mirror of
https://github.com/pppscn/SmsForwarder
synced 2024-11-04 06:00:11 +00:00
优化:发送通道Telegram
代理主机名支持域名解析 #172
This commit is contained in:
parent
439877c674
commit
ea94e30347
@ -1,5 +1,6 @@
|
||||
package com.idormy.sms.forwarder.fragment.senders
|
||||
|
||||
import android.os.Looper
|
||||
import android.text.TextUtils
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
@ -164,10 +165,19 @@ class TelegramFragment : BaseFragment<FragmentSendersTelegramBinding?>(), View.O
|
||||
when (v.id) {
|
||||
R.id.btn_test -> {
|
||||
mCountDownHelper?.start()
|
||||
val settingVo = checkSetting()
|
||||
Log.d(TAG, settingVo.toString())
|
||||
val msgInfo = MsgInfo("sms", getString(R.string.test_phone_num), getString(R.string.test_sender_sms), Date(), getString(R.string.test_sim_info))
|
||||
TelegramUtils.sendMsg(settingVo, msgInfo)
|
||||
Thread {
|
||||
try {
|
||||
val settingVo = checkSetting()
|
||||
Log.d(TAG, settingVo.toString())
|
||||
val msgInfo = MsgInfo("sms", getString(R.string.test_phone_num), getString(R.string.test_sender_sms), Date(), getString(R.string.test_sim_info))
|
||||
TelegramUtils.sendMsg(settingVo, msgInfo)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
if (Looper.myLooper() == null) Looper.prepare()
|
||||
XToastUtils.error(e.message.toString())
|
||||
Looper.loop()
|
||||
}
|
||||
}.start()
|
||||
return
|
||||
}
|
||||
R.id.btn_del -> {
|
||||
|
@ -13,6 +13,7 @@ import com.xuexiang.xhttp2.XHttp
|
||||
import com.xuexiang.xhttp2.cache.model.CacheMode
|
||||
import com.xuexiang.xhttp2.callback.SimpleCallBack
|
||||
import com.xuexiang.xhttp2.exception.ApiException
|
||||
import com.xuexiang.xutil.net.NetworkUtils
|
||||
import okhttp3.Credentials
|
||||
import okhttp3.Response
|
||||
import okhttp3.Route
|
||||
@ -64,7 +65,15 @@ class TelegramUtils private constructor() {
|
||||
&& !TextUtils.isEmpty(setting.proxyHost) && !TextUtils.isEmpty(setting.proxyPort)
|
||||
) {
|
||||
//代理服务器的IP和端口号
|
||||
request.okproxy(Proxy(setting.proxyType, setting.proxyPort?.let { InetSocketAddress(setting.proxyHost, it.toInt()) }))
|
||||
Log.d(TAG, "proxyHost = ${setting.proxyHost}, proxyPort = ${setting.proxyPort}")
|
||||
val proxyHost = if (NetworkUtils.isIP(setting.proxyHost)) setting.proxyHost else NetworkUtils.getDomainAddress(setting.proxyHost)
|
||||
if (!NetworkUtils.isIP(proxyHost)) {
|
||||
throw Exception("代理服务器主机名解析失败:proxyHost=$proxyHost")
|
||||
}
|
||||
val proxyPort: Int = setting.proxyPort?.toInt() ?: 7890
|
||||
|
||||
Log.d(TAG, "proxyHost = $proxyHost, proxyPort = $proxyPort")
|
||||
request.okproxy(Proxy(setting.proxyType, InetSocketAddress(proxyHost, proxyPort)))
|
||||
|
||||
//代理的鉴权账号密码
|
||||
if (setting.proxyAuthenticator == true
|
||||
|
Loading…
Reference in New Issue
Block a user