mirror of
https://github.com/mamoe/mirai.git
synced 2025-04-17 09:09:23 +08:00
Enhance Captcha flow
This commit is contained in:
parent
77e25ec863
commit
3e024dd487
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network
@ -14,7 +14,6 @@ import net.mamoe.mirai.qqandroid.event.PacketReceivedEvent
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.KnownPacketFactories
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.OutgoingPacket
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.login.LoginPacket
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.login.LoginPacket.LoginPacketResponse.*
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.login.StatSvc
|
||||
import net.mamoe.mirai.utils.*
|
||||
import net.mamoe.mirai.utils.io.*
|
||||
@ -33,28 +32,36 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
|
||||
launch(CoroutineName("Incoming Packet Receiver")) { processReceive() }
|
||||
|
||||
bot.logger.info("Trying login")
|
||||
when (val response: LoginPacket.LoginPacketResponse = LoginPacket.SubCommand9(bot.client).sendAndExpect()) {
|
||||
is Captcha -> when (response) {
|
||||
is Captcha.Picture -> {
|
||||
bot.logger.info("需要图片验证码")
|
||||
var result = bot.configuration.captchaSolver.invoke(bot, response.data)
|
||||
if (result === null || result.length != 4) {
|
||||
//refresh captcha
|
||||
result = "ABCD"
|
||||
|
||||
var response: LoginPacket.LoginPacketResponse = LoginPacket.SubCommand9(bot.client).sendAndExpect()
|
||||
captcha@ while (true) {
|
||||
when (response) {
|
||||
is LoginPacket.LoginPacketResponse.Captcha -> when (response) {
|
||||
is LoginPacket.LoginPacketResponse.Captcha.Picture -> {
|
||||
bot.logger.info("需要图片验证码")
|
||||
var result = bot.configuration.captchaSolver.invoke(bot, response.data)
|
||||
if (result === null || result.length != 4) {
|
||||
//refresh captcha
|
||||
@Suppress("SpellCheckingInspection")
|
||||
result = "ABCD"
|
||||
}
|
||||
bot.logger.info("提交验证码")
|
||||
|
||||
response = LoginPacket.SubCommand2(bot.client, response.sign, result).sendAndExpect()
|
||||
// goto outer when
|
||||
}
|
||||
bot.logger.info("提交验证码")
|
||||
val captchaResponse: LoginPacket.LoginPacketResponse =
|
||||
LoginPacket.SubCommand2(bot.client, response.sign, result).sendAndExpect()
|
||||
}
|
||||
is Captcha.Slider -> {
|
||||
bot.logger.info("需要滑动验证码")
|
||||
}
|
||||
}
|
||||
|
||||
is Error -> error(response.toString())
|
||||
is LoginPacket.LoginPacketResponse.Captcha.Slider -> {
|
||||
error("需要滑动验证码")
|
||||
}
|
||||
}
|
||||
|
||||
is Success -> {
|
||||
bot.logger.info("Login successful")
|
||||
is LoginPacket.LoginPacketResponse.Error -> error(response.toString())
|
||||
|
||||
is LoginPacket.LoginPacketResponse.Success -> {
|
||||
bot.logger.info("Login successful")
|
||||
break@captcha
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,6 @@ import net.mamoe.mirai.utils.MiraiInternalAPI
|
||||
import net.mamoe.mirai.utils.cryptor.ECDH
|
||||
import net.mamoe.mirai.utils.cryptor.contentToString
|
||||
import net.mamoe.mirai.utils.cryptor.decryptBy
|
||||
import net.mamoe.mirai.utils.cryptor.initialPublicKey
|
||||
import net.mamoe.mirai.utils.getValue
|
||||
import net.mamoe.mirai.utils.io.*
|
||||
import net.mamoe.mirai.utils.unsafeWeakRef
|
||||
@ -54,7 +53,7 @@ internal open class QQAndroidClient(
|
||||
"tgtgtKey" to tgtgtKey,
|
||||
"tgtKey" to wLoginSigInfo.tgtKey,
|
||||
"deviceToken" to wLoginSigInfo.deviceToken,
|
||||
"shareKeyCalculatedByConstPubKey" to ecdh.calculateShareKeyByPeerPublicKey(initialPublicKey)
|
||||
"shareKeyCalculatedByConstPubKey" to ecdh.keyPair.shareKey
|
||||
//"t108" to wLoginSigInfo.t1,
|
||||
//"t10c" to t10c,
|
||||
//"t163" to t163
|
||||
@ -287,8 +286,8 @@ internal fun parsePSKeyMapAndPt4TokenMap(data: ByteArray, creationTime: Long, ex
|
||||
val pt4token = readUShortLVByteArray()
|
||||
|
||||
when {
|
||||
psKey.size > 0 -> outPSKeyMap[domain] = PSKey(psKey, creationTime, expireTime)
|
||||
pt4token.size > 0 -> outPt4TokenMap[domain] = Pt4Token(pt4token, creationTime, expireTime)
|
||||
psKey.isNotEmpty() -> outPSKeyMap[domain] = PSKey(psKey, creationTime, expireTime)
|
||||
pt4token.isNotEmpty() -> outPt4TokenMap[domain] = Pt4Token(pt4token, creationTime, expireTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -203,17 +203,24 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
|
||||
) : LoginPacketResponse()
|
||||
|
||||
sealed class Captcha : LoginPacketResponse() {
|
||||
lateinit var answer: String
|
||||
|
||||
class Slider(
|
||||
val data: IoBuffer,
|
||||
val sign: ByteArray
|
||||
) : Captcha()
|
||||
) : Captcha(){
|
||||
override fun toString(): String {
|
||||
return "LoginPacketResponse.Captcha.Slider"
|
||||
}
|
||||
}
|
||||
|
||||
class Picture(
|
||||
val data: IoBuffer,
|
||||
val sign: ByteArray
|
||||
) : Captcha()
|
||||
) : Captcha(){
|
||||
override fun toString(): String {
|
||||
return "LoginPacketResponse.Captcha.Picture"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -258,7 +265,7 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
|
||||
|
||||
@InternalAPI
|
||||
@UseExperimental(MiraiDebugAPI::class)
|
||||
private suspend fun onSolveLoginCaptcha(tlvMap: Map<Int, ByteArray>, bot: QQAndroidBot): LoginPacketResponse.Captcha {
|
||||
private suspend fun onSolveLoginCaptcha(tlvMap: Map<Int, ByteArray>, bot: QQAndroidBot): LoginPacketResponse. Captcha {
|
||||
val client = bot.client
|
||||
// val ret = tlvMap[0x104]?.let { println(it.toUHexString()) }
|
||||
println()
|
||||
|
Loading…
Reference in New Issue
Block a user