140 lines
4.8 KiB
Kotlin
140 lines
4.8 KiB
Kotlin
package com.yingmao.clash.vm
|
||
|
||
|
||
import android.text.TextUtils
|
||
import androidx.lifecycle.viewModelScope
|
||
import com.tencent.mmkv.MMKV
|
||
import com.yingmao.clash.app.MainApplication
|
||
import com.yingmao.clash.base.PublicViewMode
|
||
import com.cncat.vpn.common.log.Log
|
||
import com.yingmao.clash.BuildConfig
|
||
import com.yingmao.clash.conf.BZYConstants
|
||
import com.yingmao.clash.entity.CheckLoginRsp
|
||
import com.yingmao.clash.listener.AsyncBodyCallback
|
||
import com.yingmao.clash.listener.AsyncCallback
|
||
import com.yingmao.clash.net.http.HttpApi
|
||
import com.yingmao.clash.net.http.HttpReqType
|
||
import com.yingmao.clash.net.http.HttpStatus
|
||
import com.yingmao.clash.net.http.NetService
|
||
import com.yingmao.clash.net.http.entity.LoginRsp
|
||
import com.yingmao.clash.net.http.entity.LoginRsp2
|
||
import com.yingmao.clash.util.AESUtil
|
||
import com.yingmao.clash.util.Utils
|
||
import kotlinx.coroutines.async
|
||
import kotlinx.coroutines.launch
|
||
import retrofit2.Call
|
||
import retrofit2.Callback
|
||
import retrofit2.Response
|
||
|
||
class LoginAtyVM : PublicViewMode() {
|
||
fun login(username: String, password: String,oaid:String) {
|
||
Log.d("login.....")
|
||
var imei = ""
|
||
/* MainApplication.getApp()?.let {
|
||
imei = AESUtil.getSubscriberId(it)
|
||
}*/
|
||
|
||
// var imsi = ""
|
||
// var mac = Utils.getMacAddress()
|
||
// if (TextUtils.isEmpty(mac)){
|
||
// mac=""
|
||
// }
|
||
val params: Map<String, String> =
|
||
mutableMapOf(
|
||
"phoneNumber" to username,
|
||
"password" to password,
|
||
"osType" to "android",
|
||
// "imei" to imei,
|
||
// "imsi" to imsi,
|
||
// "mac" to mac!!,
|
||
"idfa" to "",
|
||
"oaid" to oaid
|
||
)
|
||
Log.d("login params==>${params}")
|
||
val httpApi = NetService.instances.createHttps(HttpApi::class.java)
|
||
doAsync(HttpReqType.LOGIN) { httpApi.login(params) }
|
||
|
||
// var reqType = HttpReqType.LOGIN
|
||
// httpApi.login2(params).enqueue(object : Callback<LoginRsp2> {
|
||
// override fun onResponse(p0: Call<LoginRsp2>, p1: Response<LoginRsp2>) {
|
||
//
|
||
// try {
|
||
//
|
||
// val rsp = p1.body()!!
|
||
// com.cncat.vpn.common.log.Log.i("请求结果22:$rsp")
|
||
// statusData.value = HttpStatus.Success(reqType, rsp)
|
||
// } catch (e: Exception) {
|
||
// com.cncat.vpn.common.log.Log.e("网络请求异常22", e)
|
||
// statusData.value = HttpStatus.Failure(reqType, e.toString())
|
||
// }
|
||
// }
|
||
//
|
||
// override fun onFailure(p0: Call<LoginRsp2>, p1: Throwable) {
|
||
//
|
||
// }
|
||
//
|
||
// })
|
||
|
||
}
|
||
|
||
fun checkLogin() {
|
||
Log.d("checkLogin.....")
|
||
val httpApi = NetService.instances.createHttpsEncodeStr(HttpApi::class.java)
|
||
val token = MMKV.defaultMMKV().decodeString(BZYConstants.MMKV_KEY_PH_TOKEN, "")!!
|
||
val phoneNumber =
|
||
MMKV.defaultMMKV().decodeString(BZYConstants.MMKV_KEY_REMEMBER_USERNAME, "")!!
|
||
val params = mutableMapOf(
|
||
"phToken" to token,
|
||
"phoneNumber" to phoneNumber,
|
||
// "OAID" to MainApplication.OAID,
|
||
)
|
||
Log.d("checkLogin params==>${params}")
|
||
doAsyncEncodeStr(HttpReqType.CHECK_LOGIN, CheckLoginRsp::class.java) {
|
||
httpApi.checkLogin(
|
||
params
|
||
)
|
||
}
|
||
}
|
||
|
||
fun getRegisterHost(callback: AsyncBodyCallback) {
|
||
val rt =
|
||
NetService.instances.createFreeBaseUrl("https://yingmao.oss-cn-hongkong.aliyuncs.com/")
|
||
doAsyncNoNeedReturn(HttpReqType.GET_HOST) {
|
||
try { //TODO bug 会引起崩溃
|
||
var host = rt.getYmRegister()
|
||
callback.suc(host)
|
||
} catch (e: Exception) {
|
||
e.printStackTrace()
|
||
callback.err()
|
||
}
|
||
}
|
||
}
|
||
fun getTzRegisterHost(callback: AsyncBodyCallback) {
|
||
val rt =
|
||
NetService.instances.createFreeBaseUrl("https://yingmao.oss-cn-hongkong.aliyuncs.com/")
|
||
doAsyncNoNeedReturn(HttpReqType.GET_HOST) {
|
||
try { //TODO bug 会引起崩溃
|
||
var host = rt.getTzRegister()
|
||
callback.suc(host)
|
||
} catch (e: Exception) {
|
||
e.printStackTrace()
|
||
callback.err()
|
||
}
|
||
}
|
||
}
|
||
fun getBzyRegisterHost(callback: AsyncBodyCallback) {
|
||
val rt =
|
||
NetService.instances.createFreeBaseUrl("https://yingmao.oss-cn-hongkong.aliyuncs.com/")
|
||
doAsyncNoNeedReturn(HttpReqType.GET_HOST) {
|
||
try { //TODO bug 会引起崩溃
|
||
var host = rt.getBzyRegister()
|
||
callback.suc(host)
|
||
} catch (e: Exception) {
|
||
e.printStackTrace()
|
||
callback.err()
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
} |