88import net .mamoe .mirai .auth .BotAuthorization ;
99import net .mamoe .mirai .utils .BotConfiguration ;
1010import org .springframework .stereotype .Component ;
11- import xyz .cssxsh .mirai .tool .FixProtocolVersion ;
1211
1312import javax .annotation .PostConstruct ;
1413import javax .annotation .Resource ;
@@ -29,27 +28,20 @@ public class QqBotClient {
2928 @ PostConstruct
3029 public void init () {
3130 if (qqConfig .getEnable ()) {
32- //登录 登陆协议有ANDROID_PHONE, ANDROID_PAD, ANDROID_WATCH, IPAD, MACOS
31+ //登陆协议有ANDROID_PHONE, ANDROID_PAD, ANDROID_WATCH, IPAD, MACOS
32+ //若登陆失败可尝试更换协议
33+ BotConfiguration .MiraiProtocol miraiProtocol = BotConfiguration .MiraiProtocol .ANDROID_WATCH ;
3334 try {
3435 log .info ("正在登录qq,请按提示操作:" );
35- if (qqConfig .getLoginByQRCode ()) {
36- //扫码登陆
37- qqBot = BotFactory .INSTANCE .newBot (qqConfig .getAccount (), BotAuthorization .byQRCode (), configuration -> configuration .setProtocol (BotConfiguration .MiraiProtocol .ANDROID_WATCH ));
38- } else {
39- //密码登录
40- qqBot = BotFactory .INSTANCE .newBot (qqConfig .getAccount (), qqConfig .getPassword ().trim (), new BotConfiguration () {{
41- setProtocol (BotConfiguration .MiraiProtocol .ANDROID_PAD );
42- }});
43- //使用临时修复插件
44- FixProtocolVersion .update ();
45- }
36+ //扫码登陆
37+ qqBot = BotFactory .INSTANCE .newBot (qqConfig .getAccount (), BotAuthorization .byQRCode (), configuration -> configuration .setProtocol (miraiProtocol ));
4638
4739 qqBot .login ();
48- log .info ("成功登录账号为 {} 的qq, 登陆方式为 {}" , qqConfig .getAccount (), qqConfig . getLoginByQRCode () ? "扫码登陆" : "密码登录" );
40+ log .info ("成功登录账号为 {} 的qq, 登陆协议为 {}" , qqConfig .getAccount (), miraiProtocol );
4941 //订阅监听事件
5042 qqBot .getEventChannel ().registerListenerHost (qqMessageHandler );
5143 } catch (Exception e ) {
52- log .error ("登陆失败, qq账号为 {}, 登陆方式为 {} ,原因: {}" , qqConfig .getAccount (), qqConfig . getLoginByQRCode () ? "扫码登陆" : "密码登录" , e .getMessage ());
44+ log .error ("登陆失败, qq账号为 {}, 登陆协议为 {}, 可尝试更换登陆协议, 具体原因: {}" , qqConfig .getAccount (), miraiProtocol , e .getMessage ());
5345 }
5446 }
5547 }
0 commit comments