Skip to content

Commit 8b09222

Browse files
committed
feat close code: v1.5.3-R1
- 4004 Authentication fail #about #40 - -1 CloseFrame.NEVER_CONNECTED > 测试版本不确定有效
1 parent 21d573a commit 8b09222

6 files changed

Lines changed: 27 additions & 18 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>io.github.kloping</groupId>
88
<artifactId>bot-qqpd-java</artifactId>
9-
<version>1.5.3-L1</version>
9+
<version>1.5.3-R1</version>
1010

1111
<packaging>jar</packaging>
1212
<name>bot-qqpd-java</name>

src/main/java/io/github/kloping/qqbot/Start0.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import io.github.kloping.qqbot.entities.qqpd.Channel;
44
import io.github.kloping.qqbot.http.AuthV2Base;
5-
import io.github.kloping.qqbot.http.data.Token;
5+
import io.github.kloping.qqbot.http.data.AccessToken;
66
import io.github.kloping.spt.annotations.AutoStand;
77
import io.github.kloping.spt.annotations.ComponentScan;
88
import io.github.kloping.spt.interfaces.component.ContextManager;
@@ -24,19 +24,19 @@ public class Start0 {
2424

2525
//ALL req token header
2626
public synchronized Map<String, String> getHeaders() {
27-
if (headers.isEmpty() || isExpired(token)) updateToken();
27+
if (headers.isEmpty() || isExpired(accessToken)) updateToken();
2828
return headers;
2929
}
3030

31-
private boolean isExpired(Token token) {
32-
return token == null || token.isExpired();
31+
private boolean isExpired(AccessToken accessToken) {
32+
return accessToken == null || accessToken.isExpired();
3333
}
3434

35-
private Token token;
35+
private AccessToken accessToken;
3636

3737
public String getAccessToken() {
38-
if (isExpired(token)) updateToken();
39-
return token.getAccess_token();
38+
if (isExpired(accessToken)) updateToken();
39+
return accessToken.getAccess_token();
4040
}
4141

4242
public void updateToken() {
@@ -53,9 +53,9 @@ public void updateToken() {
5353
private String getV2Token() {
5454
String appid = contextManager.getContextEntity(String.class, Starter.APPID_ID);
5555
String secret = contextManager.getContextEntity(String.class, Starter.SECRET_ID);
56-
token = authV2Base.auth(new AppidAndSecret(appid, secret),
56+
accessToken = authV2Base.auth(new AppidAndSecret(appid, secret),
5757
Channel.SEND_MESSAGE_HEADERS).setT0(System.currentTimeMillis());
58-
return token.getAccess_token();
58+
return accessToken.getAccess_token();
5959
}
6060

6161
@Data

src/main/java/io/github/kloping/qqbot/http/AuthV2Base.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.github.kloping.qqbot.http;
22

33
import io.github.kloping.qqbot.Start0;
4-
import io.github.kloping.qqbot.http.data.Token;
4+
import io.github.kloping.qqbot.http.data.AccessToken;
55
import io.github.kloping.spt.annotations.http.Headers;
66
import io.github.kloping.spt.annotations.http.HttpClient;
77
import io.github.kloping.spt.annotations.http.PostPath;
@@ -21,5 +21,5 @@ public interface AuthV2Base {
2121
* @return
2222
*/
2323
@PostPath("/app/getAppAccessToken")
24-
Token auth(@RequestBody(type = io.github.kloping.spt.annotations.http.RequestBody.type.json) Start0.AppidAndSecret aa, @Headers Map<String, String> headers);
24+
AccessToken auth(@RequestBody(type = io.github.kloping.spt.annotations.http.RequestBody.type.json) Start0.AppidAndSecret aa, @Headers Map<String, String> headers);
2525
}

src/main/java/io/github/kloping/qqbot/http/data/Token.java renamed to src/main/java/io/github/kloping/qqbot/http/data/AccessToken.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
@Data
1717
@Accessors(chain = true)
18-
public class Token {
18+
public class AccessToken {
1919
private String access_token;
2020
private String expires_in;
2121

src/main/java/io/github/kloping/qqbot/impl/BaseConnectedEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public String getId() {
5050
return getMetadata().get("id").toString();
5151
}
5252

53-
public static final String VERSION = "1.5.3-L1";
53+
public static final String VERSION = "1.5.3-R1";
5454
public static final String PROJECT_NAME = "qqpd-bot-java";
5555
public static final String AUTHOR = "kloping";
5656
public static final String FORMAT = "Bot(%s) connected! By " + AUTHOR + " of " + PROJECT_NAME + " v" + VERSION;

src/main/java/io/github/kloping/qqbot/network/AuthAndHeartbeat.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.github.kloping.spt.interfaces.Logger;
2020
import io.github.kloping.spt.interfaces.component.ContextManager;
2121
import org.java_websocket.client.WebSocketClient;
22+
import org.java_websocket.framing.CloseFrame;
2223

2324
import java.util.concurrent.Future;
2425
import java.util.concurrent.ScheduledFuture;
@@ -33,6 +34,8 @@
3334
public class AuthAndHeartbeat implements OnPackReceive, OnCloseListener, Events.EventRegister {
3435

3536
public static final int CODE_ERROR = -10001;
37+
//Authentication fail
38+
public static final int CODE_4004 = 4004;
3639
public static final int CODE_4006 = 4006;
3740
public static final int CODE_4007 = 4007;
3841
public static final int CODE_4008 = 4008;
@@ -71,17 +74,22 @@ public void onClose(int code, WebSocketClient wss) {
7174
code == CODE_4008 || code == CODE_4009 || (code >= CODE_4900 && code <= CODE_4913)) {
7275
identifyConnect(code, wss);
7376
} else switch (code) {
77+
case CloseFrame.NEVER_CONNECTED:
78+
case CODE_1011:
79+
case 1001:
80+
delayIdentifyConnect(code, wss);
81+
break;
82+
case CODE_4004:
83+
start0.updateToken();
84+
identifyConnect(code, wss);
85+
break;
7486
case 4013:
7587
case 4014:
7688
logger.error("无权限订阅事件");
7789
break;
7890
case 1006:
7991
identifyConnect(code, wss);
8092
break;
81-
case CODE_1011:
82-
case 1001:
83-
delayIdentifyConnect(code, wss);
84-
break;
8593
default:
8694
logger.error(String.format("暂未处理的异常code(%s)", code));
8795
if (config.getAnyCloseReconnect()) delayIdentifyConnect(code, wss);
@@ -117,6 +125,7 @@ public void identifyConnect(int code, WebSocketClient wss) {
117125
}
118126
wssWorker.msgr = 0;
119127
wssWorker.msgs = 0;
128+
wssWorker.webSocket.close();
120129
future = Public.EXECUTOR_SERVICE1.submit(wssWorker);
121130
contextManager.append(future, Starter.MAIN_FUTURE_ID);
122131
}

0 commit comments

Comments
 (0)