一键连更改客服获取方式
This commit is contained in:
parent
3a44431418
commit
ea098a2a63
|
|
@ -189,34 +189,6 @@ open class PublicViewMode : BaseViewMode() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getYmKefuHost(callback: AsyncBodyCallback) {
|
|
||||||
val baseUrl=BuildConfig.service_url
|
|
||||||
val rt =
|
|
||||||
NetService.instances.createFreeBaseUrl(baseUrl)
|
|
||||||
doAsyncNoNeedReturn(HttpReqType.GET_HOST) {
|
|
||||||
try {
|
|
||||||
var host = rt.getKefuHost()
|
|
||||||
callback.suc(host)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
e.printStackTrace()
|
|
||||||
callback.err()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fun getCustomServiceHost(callback: AsyncBodyCallback) {
|
|
||||||
val rt =
|
|
||||||
NetService.instances.createFreeBaseUrl("https://pubtofile.oss-cn-hongkong.aliyuncs.com/")
|
|
||||||
doAsyncNoNeedReturn(HttpReqType.GET_HOST) {
|
|
||||||
try {
|
|
||||||
val host = rt.getYingMaoKefuHost()
|
|
||||||
callback.suc(host)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
e.printStackTrace()
|
|
||||||
callback.err()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getTzKefuHost(callback: AsyncBodyCallback) {
|
fun getTzKefuHost(callback: AsyncBodyCallback) {
|
||||||
val rt =
|
val rt =
|
||||||
NetService.instances.createFreeBaseUrl("https://yingmao.oss-cn-hongkong.aliyuncs.com/")
|
NetService.instances.createFreeBaseUrl("https://yingmao.oss-cn-hongkong.aliyuncs.com/")
|
||||||
|
|
@ -320,4 +292,45 @@ open class PublicViewMode : BaseViewMode() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fun getLocalHost(callback: AsyncBodyCallback) {
|
||||||
|
val baseUrl=BuildConfig.service_url
|
||||||
|
val rt = NetService.instances.createFreeBaseUrl(baseUrl)
|
||||||
|
doAsyncNoNeedReturn(HttpReqType.GET_HOST) {
|
||||||
|
try { //TODO bug 会引起崩溃
|
||||||
|
var host = rt.getLocalKefuHost()
|
||||||
|
callback.suc(host)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
callback.err()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fun getCustomServiceNet(callback: AsyncBodyCallback) {
|
||||||
|
val rt =
|
||||||
|
NetService.instances.createFreeBaseUrl("https://pubtofilegz.oss-rg-china-mainland.aliyuncs.com/")
|
||||||
|
doAsyncNoNeedReturn(HttpReqType.GET_HOST) {
|
||||||
|
try {
|
||||||
|
val host = rt.getKklNetHost()
|
||||||
|
android.util.Log.i("getCustomServiceHost","Kf host::"+host)
|
||||||
|
callback.suc(host)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
callback.err()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fun getCustomServiceNetS3(callback: AsyncBodyCallback) {
|
||||||
|
val rt =
|
||||||
|
NetService.instances.createFreeBaseUrl("https://wfjsq.s3.ap-east-1.amazonaws.com/")
|
||||||
|
doAsyncNoNeedReturn(HttpReqType.GET_HOST) {
|
||||||
|
try {
|
||||||
|
val host = rt.getKklNetS3()
|
||||||
|
android.util.Log.i("getCustomServiceHost","Kf host::"+host)
|
||||||
|
callback.suc(host)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
callback.err()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -240,10 +240,13 @@ interface HttpApi {
|
||||||
|
|
||||||
//客服链接
|
//客服链接
|
||||||
@GET("/oss/kf/yjl_kefu.txt")
|
@GET("/oss/kf/yjl_kefu.txt")
|
||||||
suspend fun getKefuHost(): String
|
suspend fun getLocalKefuHost(): String
|
||||||
|
@GET("kf/yjl_kefu.txt")
|
||||||
|
suspend fun getKklNetHost(): String
|
||||||
|
|
||||||
@GET("/yjl_kefu.txt")
|
@GET("/yjl_kefu.txt")
|
||||||
suspend fun getYingMaoKefuHost(): String
|
suspend fun getKklNetS3(): String
|
||||||
|
|
||||||
|
|
||||||
@GET("/taizi_kefu.txt")
|
@GET("/taizi_kefu.txt")
|
||||||
suspend fun getTaiZiKefuHost(): String
|
suspend fun getTaiZiKefuHost(): String
|
||||||
|
|
|
||||||
|
|
@ -127,11 +127,11 @@ class NetService private constructor() : INetService {
|
||||||
// .sslSocketFactory(getSSLSocketFactory(), CustomTrustManager())//信任所有证书
|
// .sslSocketFactory(getSSLSocketFactory(), CustomTrustManager())//信任所有证书
|
||||||
.sslSocketFactory(getSSLSocketFactory(), trustAllCerts[0] as X509TrustManager)
|
.sslSocketFactory(getSSLSocketFactory(), trustAllCerts[0] as X509TrustManager)
|
||||||
.hostnameVerifier(getHostnameVerifier()!!)
|
.hostnameVerifier(getHostnameVerifier()!!)
|
||||||
if (BuildConfig.DEBUG) {
|
// if (BuildConfig.DEBUG) {
|
||||||
builder.addInterceptor(loggingInterceptor)
|
|
||||||
// builder.addInterceptor(ExceptionLoggingInterceptor())
|
|
||||||
}
|
|
||||||
// builder.addInterceptor(loggingInterceptor)
|
// builder.addInterceptor(loggingInterceptor)
|
||||||
|
//// builder.addInterceptor(ExceptionLoggingInterceptor())
|
||||||
|
// }
|
||||||
|
builder.addInterceptor(loggingInterceptor)
|
||||||
return builder.build()
|
return builder.build()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ class BZYWebViewKeFu : BaseActivity() {
|
||||||
var mmkvHost = MMKV.defaultMMKV()
|
var mmkvHost = MMKV.defaultMMKV()
|
||||||
.decodeString(BZYConstants.MMKV_KEY_KEFU_HOST, "")
|
.decodeString(BZYConstants.MMKV_KEY_KEFU_HOST, "")
|
||||||
// com.cncat.vpn.common.log.Log.d("mmkvHost kf ==>${mmkvHost}")
|
// com.cncat.vpn.common.log.Log.d("mmkvHost kf ==>${mmkvHost}")
|
||||||
webViewAtyVM.getYmKefuHost(object : AsyncBodyCallback {
|
webViewAtyVM.getLocalHost(object : AsyncBodyCallback {
|
||||||
override suspend fun suc(str: String) {
|
override suspend fun suc(str: String) {
|
||||||
// com.cncat.vpn.common.log.Log.d("str==>${str}")
|
// com.cncat.vpn.common.log.Log.d("str==>${str}")
|
||||||
if (str != mmkvHost) {
|
if (str != mmkvHost) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
package com.yingmao.clash.webview
|
||||||
|
import android.util.Log
|
||||||
|
import com.yingmao.clash.base.PublicViewMode
|
||||||
|
import com.yingmao.clash.listener.AsyncBodyCallback
|
||||||
|
|
||||||
|
class CustomServiceHelper(private val splashAtyVM: PublicViewMode) {
|
||||||
|
|
||||||
|
fun getHostWithFallback(callback: (String) -> Unit) {
|
||||||
|
tryGetHost(
|
||||||
|
{ splashAtyVM.getLocalHost(it) },
|
||||||
|
{ splashAtyVM.getCustomServiceNet(it) },
|
||||||
|
{ splashAtyVM.getCustomServiceNetS3(it) },
|
||||||
|
callback
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun tryGetHost(
|
||||||
|
first: (AsyncBodyCallback) -> Unit,
|
||||||
|
second: (AsyncBodyCallback) -> Unit,
|
||||||
|
third: (AsyncBodyCallback) -> Unit,
|
||||||
|
callback: (String) -> Unit
|
||||||
|
) {
|
||||||
|
first(createCallback("getLocalHost method success", "getLocalHost method failed", callback) {
|
||||||
|
second(createCallback("getCustomServiceNet method success", "getCustomServiceNet method failed", callback) {
|
||||||
|
third(createCallback("getCustomServiceNetS3 method success", "getCustomServiceNetS3 methods failed", callback) {
|
||||||
|
callback("") // 所有方法都失败
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createCallback(
|
||||||
|
successLog: String,
|
||||||
|
errorLog: String,
|
||||||
|
callback: (String) -> Unit,
|
||||||
|
onFailure: () -> Unit
|
||||||
|
): AsyncBodyCallback {
|
||||||
|
return object : AsyncBodyCallback {
|
||||||
|
override suspend fun suc(str: String) {
|
||||||
|
Log.e("data", successLog)
|
||||||
|
callback(str) // 成功时回调
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun err() {
|
||||||
|
Log.e("data", errorLog)
|
||||||
|
onFailure() // 失败时尝试下一个方法
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -28,7 +28,10 @@ import com.yingmao.clash.R
|
||||||
import com.yingmao.clash.base.BaseActivity
|
import com.yingmao.clash.base.BaseActivity
|
||||||
import com.yingmao.clash.conf.BZYConstants
|
import com.yingmao.clash.conf.BZYConstants
|
||||||
import com.yingmao.clash.listener.AsyncBodyCallback
|
import com.yingmao.clash.listener.AsyncBodyCallback
|
||||||
|
import com.yingmao.clash.view.RxToast
|
||||||
import com.yingmao.clash.vm.WebViewAtyVM
|
import com.yingmao.clash.vm.WebViewAtyVM
|
||||||
|
import kotlinx.coroutines.MainScope
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import java.net.URLEncoder
|
import java.net.URLEncoder
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -89,46 +92,31 @@ class CustomerServiceWebView:BaseActivity() {
|
||||||
// }
|
// }
|
||||||
getCustomerServiceUrl()
|
getCustomerServiceUrl()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getCustomerServiceUrl() {
|
private fun getCustomerServiceUrl() {
|
||||||
val userName = MMKV.defaultMMKV().decodeString(BZYConstants.MMKV_KEY_REMEMBER_USERNAME, "")
|
val userName = MMKV.defaultMMKV().decodeString(BZYConstants.MMKV_KEY_REMEMBER_USERNAME, "")
|
||||||
val enName = URLEncoder.encode(userName, "UTF-8")
|
val enName = URLEncoder.encode(userName, "UTF-8")
|
||||||
Log.d("getCustomerServiceUrl enName==>${enName}")
|
Log.d("getCustomerServiceUrl enName==>${enName}")
|
||||||
|
if (TextUtils.isEmpty(customerServiceHost)) {
|
||||||
val mmkvHost = MMKV.defaultMMKV()
|
val mmkvHost = MMKV.defaultMMKV()
|
||||||
.decodeString(BZYConstants.MMKV_KEY_KEFU_HOST, "")
|
.decodeString(BZYConstants.MMKV_KEY_KEFU_HOST, "")
|
||||||
webViewVM.getYmKefuHost(object : AsyncBodyCallback {
|
|
||||||
override suspend fun suc(str: String) {
|
CustomServiceHelper(webViewVM).getHostWithFallback { str ->
|
||||||
|
if(str.isEmpty()){
|
||||||
|
RxToast.info("客服地址获取失败!")
|
||||||
|
return@getHostWithFallback
|
||||||
|
}
|
||||||
|
MainScope().launch {
|
||||||
if (str != mmkvHost) {
|
if (str != mmkvHost) {
|
||||||
MMKV.defaultMMKV()
|
MMKV.defaultMMKV()
|
||||||
.encode(BZYConstants.MMKV_KEY_KEFU_HOST, str)
|
.encode(BZYConstants.MMKV_KEY_KEFU_HOST, str)
|
||||||
}
|
}
|
||||||
customerServiceHost = str
|
customerServiceHost = str
|
||||||
csWebView.loadUrl(str+"&app_account=${enName}"+"&app_t=${resources.getString(R.string.yijianlian)}"+"&app_v=${BuildConfig.VERSION_NAME}."+BuildConfig.productId)
|
csWebView.loadUrl(str+"&app_account=${enName}"+"&app_t=${resources.getString(R.string.yijianlian)}"+"&app_v=${BuildConfig.VERSION_NAME}."+BuildConfig.productId)
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun err() {
|
|
||||||
webViewVM.getCustomServiceHost(object : AsyncBodyCallback {
|
|
||||||
override suspend fun suc(str: String) {
|
|
||||||
if (str != mmkvHost) {
|
|
||||||
MMKV.defaultMMKV()
|
|
||||||
.encode(BZYConstants.MMKV_KEY_KEFU_HOST, str)
|
|
||||||
}
|
|
||||||
csWebView.loadUrl(str+"&app_account=${enName}"+"&app_t=${resources.getString(R.string.yijianlian)}"+"&app_v=${BuildConfig.VERSION_NAME}."+BuildConfig.productId)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun err() {
|
|
||||||
if (!TextUtils.isEmpty(mmkvHost)) {
|
|
||||||
csWebView.loadUrl(mmkvHost+"&app_account=${enName}"+"&app_t=${resources.getString(R.string.yijianlian)}"+"&app_v=${BuildConfig.VERSION_NAME}."+BuildConfig.productId)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
})
|
csWebView.loadUrl(customerServiceHost + "&app_account=${enName}"+"&app_t=${resources.getString(R.string.yijianlian)}"+"&app_v=${BuildConfig.VERSION_NAME}."+BuildConfig.productId)
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
initKeyboardListener()
|
initKeyboardListener()
|
||||||
}
|
}
|
||||||
private fun initKeyboardListener() {
|
private fun initKeyboardListener() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue