git 1 month ago
parent
commit
6091a05704
2 changed files with 81 additions and 29 deletions
  1. 35 4
      src/main/kotlin/cn/qqck/kotlin/tools/String.kt
  2. 46 25
      src/test/kotlin/Main.kt

+ 35 - 4
src/main/kotlin/cn/qqck/kotlin/tools/String.kt

@@ -120,7 +120,13 @@ fun String.isEx(): Boolean {
     return this.all { it in '!'..'~' }
 }
 
-data class AddrPort(val addr: String, val port: Int)
+enum class AddrType {
+    Host,
+    Ipv4,
+    Ipv6,
+}
+
+data class AddrPort(val addr: String, val addr_type: AddrType, val port: Int)
 
 /**
  * 将当前字符串解析为主机地址和端口号,返回一个包含地址和端口的 AddrPort 对象。
@@ -130,19 +136,44 @@ data class AddrPort(val addr: String, val port: Int)
  *
  * @return 如果解析成功,返回包含地址和端口的 AddrPort 对象;如果解析失败或格式无效,则返回 null。
  */
-fun String.toAddrPort(): AddrPort? {
+fun String?.toAddrPort(): AddrPort? {
+    if (this == null) return null
     if (this.isBlank()) return null
     Regex("\\[([a-fA-F0-9:]+)]:(\\d+)").matchEntire(this)?.also {
         val j_port = it.groupValues[2].toIntOrNull()
-        if (j_port != null && j_port in 1..65535) return AddrPort(it.groupValues[1], j_port)
+        if (j_port != null && j_port in 1..65535 && it.groupValues[1].isIpv6()) return AddrPort(it.groupValues[1], AddrType.Ipv6, j_port)
     }
     Regex("([a-zA-Z0-9.-]+):(\\d+)").matchEntire(this)?.also {
         val j_port = it.groupValues[2].toIntOrNull()
-        if (j_port != null && j_port in 1..65535) return AddrPort(it.groupValues[1], j_port)
+        if (j_port != null && j_port in 1..65535) {
+            if (it.groupValues[1].isIpv4()) return AddrPort(it.groupValues[1], AddrType.Ipv4, j_port)
+            return AddrPort(it.groupValues[1], AddrType.Host, j_port)
+        }
     }
     return null
 }
 
+/**
+ * 判断当前字符串是否为有效的IPv4地址格式。
+ *
+ * @return 如果字符串是有效的IPv4地址格式,返回true;否则返回false。
+ */
+fun String?.isIpv4(): Boolean {
+    if (this == null) return false
+    return Regex("^((25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9][0-9]?|0)\\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9][0-9]?|0)$").matches(this)
+}
+
+/**
+ * 判断当前字符串是否为IPv6地址格式。
+ *
+ * @return 如果字符串为有效的IPv6地址格式(包含在中括号内,如`[::1]`),返回true;否则返回false。
+ */
+fun String?.isIpv6(): Boolean {
+    if (this == null) return false
+    return Regex("^(?:[\\da-fA-F]{1,4}:){7}[\\da-fA-F]{1,4}$|^(?:[\\da-fA-F]{1,4}:){1,7}:$|^:(?::[\\da-fA-F]{1,4}){1,7}$|^(?:[\\da-fA-F]{1,4}(?::[\\da-fA-F]{1,4}){0,5})?::(?:[\\da-fA-F]{1,4}(?::[\\da-fA-F]{1,4}){0,5})?$")
+        .matches(this)
+}
+
 /**
  * 隐藏字符串中间一部分字符,用于部分信息的脱敏显示。
  *

+ 46 - 25
src/test/kotlin/Main.kt

@@ -1,38 +1,59 @@
 import cn.qqck.kotlin.tools.*
+import dev.botta.json.values.JsonValue
 import okhttp3.MediaType.Companion.toMediaType
 import okhttp3.RequestBody.Companion.toRequestBody
 
 fun main() {
     println(Date.day(1))
-    println(ULID.random())
+    println("192.168.1.1".isIpv4())
+    println("2409:8c1e:75b0:1120::16".isIpv6())
+    println("fe80::1ff:fe23:4567:890a".isIpv6())
     // println(register_queue.isNet())
     // register_queue.get()
 }
 
-private object register_queue {
-    private const val host = "http://127.0.0.1"
-    private const val port = 10002
-    private const val query = "?token=pJ1cX5gC9qU8iG3sW9gL5xG9jC5mV6rJ1uL7"
+fun ggcz(): JsonValue? {
 
-    fun isNet(): Boolean {
-        return Okhttp.call("${this.host}:${this.port}") != null
-    }
-
-    fun get(): String? {
-        val j_body = Okhttp.call("${this.host}:${this.port}/api/腾讯QQ/注册/任务列表/获取待处理${this.query}") ?: return null
-        if (j_body.body == null) return null
-        val j_json = j_body.body!!.string().json()
-        if (j_json.path("code")?.asInt() != 1) return null
-        val j_id = j_json.path("data.id")?.asString() ?: return null
-        val j_area = j_json.path("data.区号")?.asString() ?: return null
-        val j_phone = j_json.path("data.手机号")?.asString() ?: return null
-        println(j_area)
-        println(j_phone)
+    val proxy = Proxy.Info("39.101.128.132", 801, "tx004", "110110")
 
-        val j_url = "${this.host}:${this.port}/api/腾讯QQ/注册/任务列表/更新状态${this.query}"
-        val j_post = "id=${j_id}&状态=${10000}"
-        while (Okhttp.call(j_url) { it.post(j_post.toRequestBody("application/x-www-form-urlencoded".toMediaType())) } == null) Thread.sleep(1000)
-
-        return "aaa"
+    val j_serverip = "1.13.162.140"
+    val j_uid = "3X6W6rkeRhS7GauNNeu5As8E7t2NORlVu4y4J58X4d16WosyvZuLU9dhcPd4xRBE98m9"
+    val j_post = "aid=2031242339&代理地址=${"${proxy.addr}:${proxy.port}"}&代理类型=${
+        when (proxy.type) {
+            Proxy.Type.Http -> 0
+            Proxy.Type.Socks5 -> 1
+            else -> 0
+        }
+    }&代理账号=${proxy.user}&代理密码=${proxy.pass}".toRequestBody("application/x-www-form-urlencoded".toMediaType())
+    for (j_i in 0..2) {
+        var j_url = "http://${j_serverip}/api/腾讯QQ/图形验证码/任务列表/创建任务?token=${j_uid}"
+        val j_data = Okhttp.call(j_url) { it.post(j_post) }?.body?.json() ?: continue
+        println("ggcz -> data:${j_data}")
+        if (j_data.path("code")?.asInt() != 1) continue
+        val j_id = j_data.path("data.id")?.asString() ?: continue
+        Thread.sleep(5000)
+        j_url = "http://${j_serverip}/api/腾讯QQ/图形验证码/任务列表/查询状态?token=${j_uid}"
+        val j_postc = "id=${j_id}".toRequestBody("application/x-www-form-urlencoded".toMediaType())
+        for (j_i in 0..180) {
+            Thread.sleep(1000)
+            val j_result = Okhttp.call(j_url) { it.post(j_postc) }?.body?.json() ?: continue
+            println("ggcz -> result:${j_result}")
+            if (j_result.path("code")?.asInt() != 1) break
+            // 等待处理= 0
+            // 开始处理= 1
+            // 提交信息= 2
+            // 未完成= 100
+            // 成功= 10000
+            // 类型不支持= 10001
+            // 识别错误= 10002
+            // 网络错误= 10003
+            // 返回错误= 10004
+            // 执行错误= 10005
+            val j_状态 = j_result.path("data.状态")?.asInt() ?: break
+            if (j_状态 < 100) continue
+            if (j_状态 == 10000) return j_result.path("data.处理结果")
+            break
+        }
     }
-}
+    return null
+}