93 lines
3.8 KiB
Kotlin
93 lines
3.8 KiB
Kotlin
package com.yingmao.clash.act
|
|
|
|
import com.google.gson.Gson
|
|
import com.google.gson.JsonArray
|
|
import com.yingmao.clash.base.PublicViewMode
|
|
import com.cncat.vpn.common.log.Log
|
|
import com.yingmao.clash.entity.ClashNodebBean
|
|
import com.yingmao.clash.listener.AsyncCallBackListener
|
|
import com.yingmao.clash.net.http.HttpApi
|
|
import com.yingmao.clash.net.http.HttpReqType
|
|
import com.yingmao.clash.net.http.NetService
|
|
import com.cncat.vpn.service.data.Imported
|
|
import com.cncat.vpn.service.data.ImportedDao
|
|
import com.cncat.vpn.service.data.PendingDao
|
|
import com.cncat.vpn.service.util.sendBroadcastNodeInfo
|
|
import com.cncat.vpn.service.util.sendProfileChanged
|
|
import okhttp3.OkHttpClient
|
|
import okhttp3.Request
|
|
import org.yaml.snakeyaml.Yaml
|
|
import java.math.BigDecimal
|
|
|
|
|
|
class ProxyModeAtyVM : PublicViewMode() {
|
|
|
|
fun get_Node_Other(url: String, listener: AsyncCallBackListener) {
|
|
Log.d("get_Node_Other start")
|
|
val client = OkHttpClient()
|
|
try {
|
|
val request = Request.Builder()
|
|
.url(url)
|
|
.header("User-Agent", "ClashforWindows/0.19.23")
|
|
.build()
|
|
|
|
client.newCall(request).execute().use { response ->
|
|
if (!response.isSuccessful || response.headers["subscription-userinfo"] == null) return
|
|
|
|
var upload: Long = 0
|
|
var download: Long = 0
|
|
var total: Long = 0
|
|
var expire: Long = 0
|
|
|
|
val userinfo = response.headers["subscription-userinfo"]
|
|
// Log.d("updateFlow userinfo==>" + Gson().toJson(userinfo))
|
|
if (response.isSuccessful && userinfo != null) {
|
|
|
|
val flags = userinfo.split(";")
|
|
for (flag in flags) {
|
|
val info = flag.split("=")
|
|
when {
|
|
info[0].contains("upload") && info[1].isNotEmpty() -> upload =
|
|
BigDecimal(info[1]).longValueExact()
|
|
|
|
info[0].contains("download") && info[1].isNotEmpty() -> download =
|
|
BigDecimal(info[1]).longValueExact()
|
|
|
|
info[0].contains("total") && info[1].isNotEmpty() -> total =
|
|
BigDecimal(info[1]).longValueExact()
|
|
|
|
info[0].contains("expire") && info[1].isNotEmpty() -> {
|
|
if (info[1].isNotEmpty()) {
|
|
expire = (info[1].toDouble() * 1000).toLong()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Log.d("upload==>${upload}, download==>${download}, total==>${total}, expire==>${expire}")
|
|
response.body?.let {
|
|
var respStr = it.string()
|
|
val conf = Yaml().loadAs(respStr, HashMap::class.java)
|
|
var proxies = conf.get("proxies");
|
|
proxies?.let { pro ->
|
|
|
|
var proList = pro as ArrayList<Map<String, Any>>
|
|
var gson = Gson()
|
|
var dataList = mutableListOf<ClashNodebBean>()
|
|
proList.forEach { item ->
|
|
var jo = gson.toJson(item)
|
|
var bean = gson.fromJson(jo.toString(), ClashNodebBean::class.java)
|
|
dataList.add(bean)
|
|
}
|
|
listener.suc(dataList)
|
|
}
|
|
}
|
|
} else {
|
|
listener.faild(response)
|
|
}
|
|
}
|
|
} catch (e: Exception) {
|
|
System.out.println(e)
|
|
Log.d("e==>" + e.localizedMessage)
|
|
}
|
|
}
|
|
} |