LoginSolver.kt 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright 2019-2020 Mamoe Technologies and contributors.
  3. *
  4. * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
  5. * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
  6. *
  7. * https://github.com/mamoe/mirai/blob/master/LICENSE
  8. */
  9. package net.mamoe.mirai.utils
  10. import net.mamoe.mirai.Bot
  11. import net.mamoe.mirai.network.LoginFailedException
  12. /**
  13. * 验证码, 设备锁解决器
  14. */
  15. public expect abstract class LoginSolver {
  16. /**
  17. * 处理图片验证码.
  18. * 返回 null 以表示无法处理验证码, 将会刷新验证码或重试登录.
  19. * 抛出一个 [LoginFailedException] 以正常地终止登录, 抛出任意其他 [Exception] 将视为异常终止
  20. *
  21. * @throws LoginFailedException
  22. */
  23. public abstract suspend fun onSolvePicCaptcha(bot: Bot, data: ByteArray): String?
  24. /**
  25. * 处理滑动验证码.
  26. * 返回 null 以表示无法处理验证码, 将会刷新验证码或重试登录.
  27. * 抛出一个 [LoginFailedException] 以正常地终止登录, 抛出任意其他 [Exception] 将视为异常终止
  28. *
  29. * @throws LoginFailedException
  30. * @return 验证码解决成功后获得的 ticket.
  31. */
  32. public abstract suspend fun onSolveSliderCaptcha(bot: Bot, url: String): String?
  33. /**
  34. * 处理不安全设备验证.
  35. * 在处理完成后返回任意内容 (包含 `null`) 均视为处理成功.
  36. * 抛出一个 [LoginFailedException] 以正常地终止登录, 抛出任意其他 [Exception] 将视为异常终止.
  37. *
  38. * @return 任意内容. 返回值保留以供未来更新.
  39. * @throws LoginFailedException
  40. */
  41. public abstract suspend fun onSolveUnsafeDeviceLoginVerify(bot: Bot, url: String): String?
  42. public companion object {
  43. public val Default: LoginSolver
  44. }
  45. }