Skip to content

Commit

Permalink
[bot] AutoMerging: merge all upstream's changes:
Browse files Browse the repository at this point in the history
* 'main' of https://github.com/pppscn/SmsForwarder:
  新增:`/config/query`接口返回`version_code`和`version_name`字段 pppscn#184
  优化:Android 4.4 兼容性(410棒子) pppscn#180
  v3.0.6
  优化:发送通道`企业微信应用`支持http/socks5代理(应对IP白名单限制)
  修复:v3.0.5在部分机型解析/config/query返回sim_info_list节点时报错
  v3.0.5
  • Loading branch information
github-actions[bot] committed Jul 8, 2022
2 parents ab2da5a + 72d2b1d commit e3521c6
Show file tree
Hide file tree
Showing 14 changed files with 361 additions and 32 deletions.
8 changes: 4 additions & 4 deletions app/src/main/java/com/idormy/sms/forwarder/entity/SimInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import java.io.Serializable
data class SimInfo(
//运营商信息:中国移动 中国联通 中国电信
@SerializedName("carrier_name")
var mCarrierName: CharSequence? = null,
var mCarrierName: String? = null,
//集成电路卡识别码即SIM卡卡号
@SerializedName("icc_id")
var mIccId: CharSequence? = null,
var mIccId: String? = null,
//卡槽id:-1=没插入、 0=卡槽1 、1=卡槽2
@SerializedName("sim_slot_index")
var mSimSlotIndex: Int = 0,
//号码
@SerializedName("number")
var mNumber: CharSequence? = null,
var mNumber: String? = null,
//国家代码
@SerializedName("country_iso")
var mCountryIso: CharSequence? = null,
var mCountryIso: String? = null,
//SIM的 Subscription Id (SIM插入顺序)
@SerializedName("subscription_id")
var mSubscriptionId: Int = 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
package com.idormy.sms.forwarder.entity.setting

import com.idormy.sms.forwarder.R
import java.io.Serializable
import java.net.Proxy

data class WeworkAgentSetting(
var corpID: String = "",
val agentID: String = "",
val secret: String = "",
val atAll: Boolean? = false,
val toUser: String? = "@all",
) : Serializable
val proxyType: Proxy.Type = Proxy.Type.DIRECT,
val proxyHost: String? = "",
val proxyPort: String? = "",
val proxyAuthenticator: Boolean? = false,
val proxyUsername: String? = "",
val proxyPassword: String? = "",
) : Serializable {

fun getProxyTypeCheckId(): Int {
return when (proxyType) {
Proxy.Type.HTTP -> R.id.rb_proxyHttp
Proxy.Type.SOCKS -> R.id.rb_proxySocks
else -> R.id.rb_proxyNone
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.CompoundButton
import android.widget.RadioGroup
import androidx.fragment.app.viewModels
import com.google.gson.Gson
import com.idormy.sms.forwarder.R
Expand All @@ -33,6 +34,7 @@ import io.reactivex.SingleObserver
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import java.net.Proxy
import java.util.*

@Page(name = "企业微信应用")
Expand Down Expand Up @@ -126,6 +128,12 @@ class WeworkAgentFragment : BaseFragment<FragmentSendersWeworkAgentBinding?>(),
binding!!.etSecret.setText(settingVo.secret)
binding!!.sbAtAll.isChecked = settingVo.atAll == true
binding!!.etToUser.setText(settingVo.toUser)
binding!!.rgProxyType.check(settingVo.getProxyTypeCheckId())
binding!!.etProxyHost.setText(settingVo.proxyHost)
binding!!.etProxyPort.setText(settingVo.proxyPort)
binding!!.sbProxyAuthenticator.isChecked = settingVo.proxyAuthenticator == true
binding!!.etProxyUsername.setText(settingVo.proxyUsername)
binding!!.etProxyPassword.setText(settingVo.proxyPassword)
}
}
})
Expand All @@ -136,17 +144,36 @@ class WeworkAgentFragment : BaseFragment<FragmentSendersWeworkAgentBinding?>(),
binding!!.btnDel.setOnClickListener(this)
binding!!.btnSave.setOnClickListener(this)
binding!!.sbAtAll.setOnCheckedChangeListener(this)
binding!!.sbProxyAuthenticator.setOnCheckedChangeListener(this)
binding!!.rgProxyType.setOnCheckedChangeListener { _: RadioGroup?, checkedId: Int ->
if (checkedId == R.id.rb_proxyHttp || checkedId == R.id.rb_proxySocks) {
binding!!.layoutProxyHost.visibility = View.VISIBLE
binding!!.layoutProxyPort.visibility = View.VISIBLE
binding!!.layoutProxyAuthenticator.visibility = if (binding!!.sbProxyAuthenticator.isChecked) View.VISIBLE else View.GONE
} else {
binding!!.layoutProxyHost.visibility = View.GONE
binding!!.layoutProxyPort.visibility = View.GONE
binding!!.layoutProxyAuthenticator.visibility = View.GONE
}
}
}

@SuppressLint("SetTextI18n")
override fun onCheckedChanged(buttonView: CompoundButton?, isChecked: Boolean) {
//注意:因为只有一个监听,暂不需要判断id
if (isChecked) {
binding!!.etToUser.setText("@all")
binding!!.layoutToUser.visibility = View.GONE
} else {
binding!!.etToUser.setText("")
binding!!.layoutToUser.visibility = View.VISIBLE
override fun onCheckedChanged(buttonView: CompoundButton, isChecked: Boolean) {
when (buttonView.id) {
R.id.sb_at_all -> {
if (isChecked) {
binding!!.etToUser.setText("@all")
binding!!.layoutToUser.visibility = View.GONE
} else {
binding!!.etToUser.setText("")
binding!!.layoutToUser.visibility = View.VISIBLE
}
}
R.id.sb_proxyAuthenticator -> {
binding!!.layoutProxyAuthenticator.visibility = if (isChecked) View.VISIBLE else View.GONE
}
else -> {}
}
}

Expand Down Expand Up @@ -225,7 +252,26 @@ class WeworkAgentFragment : BaseFragment<FragmentSendersWeworkAgentBinding?>(),
val atAll = binding!!.sbAtAll.isChecked
val toUser = binding!!.etToUser.text.toString().trim()

return WeworkAgentSetting(corpID, agentID, secret, atAll, toUser)
val proxyType: Proxy.Type = when (binding!!.rgProxyType.checkedRadioButtonId) {
R.id.rb_proxyHttp -> Proxy.Type.HTTP
R.id.rb_proxySocks -> Proxy.Type.SOCKS
else -> Proxy.Type.DIRECT
}
val proxyHost = binding!!.etProxyHost.text.toString().trim()
val proxyPort = binding!!.etProxyPort.text.toString().trim()

if (proxyType != Proxy.Type.DIRECT && (TextUtils.isEmpty(proxyHost) || TextUtils.isEmpty(proxyPort))) {
throw Exception(getString(R.string.invalid_host_or_port))
}

val proxyAuthenticator = binding!!.sbProxyAuthenticator.isChecked
val proxyUsername = binding!!.etProxyUsername.text.toString().trim()
val proxyPassword = binding!!.etProxyPassword.text.toString().trim()
if (proxyAuthenticator && TextUtils.isEmpty(proxyUsername) && TextUtils.isEmpty(proxyPassword)) {
throw Exception(getString(R.string.invalid_username_or_password))
}

return WeworkAgentSetting(corpID, agentID, secret, atAll, toUser, proxyType, proxyHost, proxyPort, proxyAuthenticator, proxyUsername, proxyPassword)
}

override fun onDestroyView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.idormy.sms.forwarder.server.model.ConfigData
import com.idormy.sms.forwarder.utils.HttpServerUtils
import com.idormy.sms.forwarder.utils.PhoneUtils
import com.idormy.sms.forwarder.utils.SettingUtils
import com.xuexiang.xutil.app.AppUtils
import com.yanzhenjie.andserver.annotation.*

@Suppress("PrivatePropertyName")
Expand Down Expand Up @@ -38,7 +39,9 @@ class ConfigController {
SettingUtils.extraDeviceMark.toString(),
SettingUtils.extraSim1.toString(),
SettingUtils.extraSim2.toString(),
App.SimInfoList
App.SimInfoList,
AppUtils.getAppVersionCode(),
AppUtils.getAppVersionName(),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ data class ConfigData(
var extraSim2: String = "",
@SerializedName("sim_info_list")
var simInfoList: MutableMap<Int, SimInfo> = mutableMapOf(),
@SerializedName("version_code")
var versionCode: Int = 0,
@SerializedName("version_name")
var versionName: String = "",
) : Serializable
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ class PhoneUtils private constructor() {
//1.1.1 有使用的卡,就遍历所有卡
for (subscriptionInfo in activeSubscriptionInfoList) {
val simInfo = SimInfo()
simInfo.mCarrierName = subscriptionInfo.carrierName
simInfo.mIccId = subscriptionInfo.iccId
simInfo.mCarrierName = subscriptionInfo.carrierName.toString()
simInfo.mIccId = subscriptionInfo.iccId.toString()
simInfo.mSimSlotIndex = subscriptionInfo.simSlotIndex
simInfo.mNumber = subscriptionInfo.number
simInfo.mCountryIso = subscriptionInfo.countryIso
simInfo.mNumber = subscriptionInfo.number.toString()
simInfo.mCountryIso = subscriptionInfo.countryIso.toString()
simInfo.mSubscriptionId = subscriptionInfo.subscriptionId
println(simInfo.toString())
infoList[simInfo.mSimSlotIndex] = simInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ import com.xuexiang.xhttp2.cache.model.CacheMode
import com.xuexiang.xhttp2.callback.SimpleCallBack
import com.xuexiang.xhttp2.exception.ApiException
import com.xuexiang.xui.utils.ResUtils.getString
import com.xuexiang.xutil.net.NetworkUtils
import okhttp3.Credentials
import okhttp3.Response
import okhttp3.Route
import java.net.Authenticator
import java.net.InetSocketAddress
import java.net.PasswordAuthentication
import java.net.Proxy

@Suppress("PrivatePropertyName", "UNUSED_PARAMETER")
class WeworkAgentUtils private constructor() {
Expand All @@ -42,8 +50,49 @@ class WeworkAgentUtils private constructor() {
getTokenUrl += "&corpsecret=" + setting.secret
Log.d(TAG, "getTokenUrl:$getTokenUrl")

XHttp.get(getTokenUrl)
.keepJson(true)
val request = XHttp.get(getTokenUrl)

//设置代理
if ((setting.proxyType == Proxy.Type.HTTP || setting.proxyType == Proxy.Type.SOCKS)
&& !TextUtils.isEmpty(setting.proxyHost) && !TextUtils.isEmpty(setting.proxyPort)
) {
//代理服务器的IP和端口号
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
&& (!TextUtils.isEmpty(setting.proxyUsername) || !TextUtils.isEmpty(setting.proxyPassword))
) {
Log.i(TAG, "proxyUsername = ${setting.proxyUsername}, proxyPassword = ${setting.proxyPassword}")

if (setting.proxyType == Proxy.Type.HTTP) {
request.okproxyAuthenticator { _: Route?, response: Response ->
//设置代理服务器账号密码
val credential = Credentials.basic(setting.proxyUsername.toString(), setting.proxyPassword.toString())
response.request().newBuilder()
.header("Proxy-Authorization", credential)
.build()
}
} else {
Authenticator.setDefault(object : Authenticator() {
override fun getPasswordAuthentication(): PasswordAuthentication {
return PasswordAuthentication(setting.proxyUsername.toString(), setting.proxyPassword?.toCharArray())
}
})
}
}
}

request.keepJson(true)
.ignoreHttpsCert()
.timeOut((SettingUtils.requestTimeout * 1000).toLong()) //超时时间10s
.cacheMode(CacheMode.NO_CACHE)
.timeStamp(true)
Expand Down Expand Up @@ -96,9 +145,50 @@ class WeworkAgentUtils private constructor() {
val requestMsg: String = Gson().toJson(textMsgMap)
Log.i(TAG, "requestMsg:$requestMsg")

XHttp.post(requestUrl)
.upJson(requestMsg)
val request = XHttp.post(requestUrl)

//设置代理
if ((setting.proxyType == Proxy.Type.HTTP || setting.proxyType == Proxy.Type.SOCKS)
&& !TextUtils.isEmpty(setting.proxyHost) && !TextUtils.isEmpty(setting.proxyPort)
) {
//代理服务器的IP和端口号
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
&& (!TextUtils.isEmpty(setting.proxyUsername) || !TextUtils.isEmpty(setting.proxyPassword))
) {
Log.i(TAG, "proxyUsername = ${setting.proxyUsername}, proxyPassword = ${setting.proxyPassword}")

if (setting.proxyType == Proxy.Type.HTTP) {
request.okproxyAuthenticator { _: Route?, response: Response ->
//设置代理服务器账号密码
val credential = Credentials.basic(setting.proxyUsername.toString(), setting.proxyPassword.toString())
response.request().newBuilder()
.header("Proxy-Authorization", credential)
.build()
}
} else {
Authenticator.setDefault(object : Authenticator() {
override fun getPasswordAuthentication(): PasswordAuthentication {
return PasswordAuthentication(setting.proxyUsername.toString(), setting.proxyPassword?.toCharArray())
}
})
}
}
}

request.upJson(requestMsg)
.keepJson(true)
.ignoreHttpsCert()
.timeOut((SettingUtils.requestTimeout * 1000).toLong()) //超时时间10s
.cacheMode(CacheMode.NO_CACHE)
.retryCount(SettingUtils.requestRetryTimes) //超时重试的次数
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/res/drawable/ic_copy.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
android:tint="#FFFFFF"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FFFFFFFF"
android:fillColor="@android:color/white"
android:pathData="M18,2H9C7.9,2 7,2.9 7,4v12c0,1.1 0.9,2 2,2h9c1.1,0 2,-0.9 2,-2V4C20,2.9 19.1,2 18,2zM18,16H9V4h9V16zM3,15v-2h2v2H3zM3,9.5h2v2H3V9.5zM10,20h2v2h-2V20zM3,18.5v-2h2v2H3zM5,22c-1.1,0 -2,-0.9 -2,-2h2V22zM8.5,22h-2v-2h2V22zM13.5,22L13.5,22l0,-2h2v0C15.5,21.1 14.6,22 13.5,22zM5,6L5,6l0,2H3v0C3,6.9 3.9,6 5,6z" />
</vector>
Loading

0 comments on commit e3521c6

Please sign in to comment.