Commit efb32133 authored by Him188's avatar Him188

Fix solveCaptcha on Jvm

parent f78c4734
...@@ -20,21 +20,19 @@ import kotlin.math.min ...@@ -20,21 +20,19 @@ import kotlin.math.min
* @return 用户输入得到的验证码 * @return 用户输入得到的验证码
*/ */
internal actual suspend fun solveCaptcha(captchaBuffer: IoBuffer): String? = captchaLock.withLock { internal actual suspend fun solveCaptcha(captchaBuffer: IoBuffer): String? = captchaLock.withLock {
val tempFile = File(System.getProperty("user.dir") + "/temp/Captcha.png").also { val tempFile: File = createTempFile(suffix = ".png").apply { deleteOnExit() }
withContext(Dispatchers.IO) {
it.createNewFile(); @Suppress("EXPERIMENTAL_API_USAGE")
it.writeChannel().writeFully(captchaBuffer)
}
}
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
MiraiLogger.info(ImageIO.read(tempFile.inputStream()).createCharImg()) tempFile.createNewFile()
} @Suppress("EXPERIMENTAL_API_USAGE")
MiraiLogger.info("需要验证码登录, 验证码为 4 字母") try {
try { tempFile.writeChannel().writeFully(captchaBuffer)
MiraiLogger.info("需要验证码登录, 验证码为 4 字母")
MiraiLogger.info("若看不清字符图片, 请查看 ${tempFile.absolutePath}")
} catch (e: Exception) {
MiraiLogger.info("无法写出验证码文件(${e.message}), 请尝试查看以上字符图片")
}
MiraiLogger.info("若看不清字符图片, 请查看 Mirai 目录下 /temp/Captcha.png") MiraiLogger.info(ImageIO.read(tempFile.inputStream()).createCharImg())
} catch (e: Exception) {
MiraiLogger.info("无法写出验证码文件(${e.message}), 请尝试查看以上字符图片")
} }
MiraiLogger.info("若要更换验证码, 请直接回车") MiraiLogger.info("若要更换验证码, 请直接回车")
readLine()?.takeUnless { it.isEmpty() || it.length != 4 } readLine()?.takeUnless { it.isEmpty() || it.length != 4 }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment