Skip to content

Commit 453fc68

Browse files
Merge pull request #77 from ashinnotfound/fix/loginByPassword
feat: 删除qq机器人使用密码登陆的方法
2 parents 63ee01a + ed5a5b3 commit 453fc68

File tree

5 files changed

+8
-35
lines changed

5 files changed

+8
-35
lines changed

pom.xml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,6 @@
3838
<artifactId>mirai-core-jvm</artifactId>
3939
<version>2.16.0</version>
4040
</dependency>
41-
<!-- 临时修复qq登录组件 https://github.com/cssxsh/fix-protocol-version.git -->
42-
<dependency>
43-
<groupId>mirai</groupId>
44-
<artifactId>fix-protocol</artifactId>
45-
<version>1.12.0</version>
46-
<scope>system</scope>
47-
<systemPath>${pom.basedir}/src/main/resources/fix-protocol-version-1.12.0.mirai2.jar</systemPath>
48-
</dependency>
49-
<dependency>
50-
<groupId>org.asynchttpclient</groupId>
51-
<artifactId>async-http-client</artifactId>
52-
<version>2.12.3</version>
53-
</dependency>
5441
<!-- 微信 -->
5542
<dependency>
5643
<groupId>itchat</groupId>

src/main/java/com/ashin/client/QqBotClient.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import net.mamoe.mirai.auth.BotAuthorization;
99
import net.mamoe.mirai.utils.BotConfiguration;
1010
import org.springframework.stereotype.Component;
11-
import xyz.cssxsh.mirai.tool.FixProtocolVersion;
1211

1312
import javax.annotation.PostConstruct;
1413
import 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
}

src/main/java/com/ashin/config/QqConfig.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
@ConfigurationProperties("qq")
1616
public class QqConfig {
1717
private Boolean enable;
18-
private Boolean loginByQRCode;
1918
private Long account;
20-
private String password;
2119
private Boolean acceptNewFriend;
2220
private Boolean acceptNewGroup;
2321
private Boolean returnDrawByURL;

src/main/resources/application.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,8 @@ gpt:
2626
qq:
2727
# 是否使用qq true/false
2828
enable: true
29-
# 登陆方法:true扫码登录(推荐) false密码登录
30-
loginByQRCode: true
31-
# qq账号密码
29+
# qq账号
3230
account:
33-
# (扫码登录则无需填写密码)
34-
password:
3531
# 是否自动同意好友申请
3632
acceptNewFriend: false
3733
# 是否自动同意被邀请入群
-4.86 MB
Binary file not shown.

0 commit comments

Comments
 (0)