11package io .github .kloping .qqbot ;
22
3- import io .github .kloping .judge .Judge ;
43import io .github .kloping .qqbot .entities .qqpd .Channel ;
54import io .github .kloping .qqbot .http .AuthV2Base ;
65import io .github .kloping .qqbot .http .data .Token ;
@@ -24,8 +23,9 @@ public class Start0 {
2423 ContextManager contextManager ;
2524
2625 public Map <String , String > getHeaders () {
26+ if (isExpired (token )) headers .clear ();
2727 if (headers .isEmpty ()) {
28- headers .put ("Authorization" , contextManager . getContextEntity ( String .class , Starter . AUTH_ID ));
28+ headers .put ("Authorization" , String .format ( "QQBot %s" , getV2Token () ));
2929 headers .put ("Accept-Encoding" , "application/json" );
3030 }
3131 return headers ;
@@ -34,9 +34,7 @@ public Map<String, String> getHeaders() {
3434 public Map <String , String > getV2Headers () {
3535 if (isExpired (token )) v2headers .clear ();
3636 if (v2headers .isEmpty ()) {
37- String secret = contextManager .getContextEntity (String .class , Starter .SECRET_ID );
38- if (Judge .isEmpty (secret )) return v2headers ;
39- v2headers .put ("Authorization" , String .format ("QQBot %s" , getV2Token (secret )));
37+ v2headers .put ("Authorization" , String .format ("QQBot %s" , getV2Token ()));
4038 v2headers .put ("X-Union-Appid" , contextManager .getContextEntity (String .class , Starter .APPID_ID ));
4139 }
4240 return v2headers ;
@@ -49,14 +47,20 @@ private boolean isExpired(Token token) {
4947 @ AutoStand
5048 AuthV2Base authV2Base ;
5149
50+
5251 private Token token ;
5352
54- private String getV2Token (String secret ) {
53+ private String getV2Token () {
54+ String appid = contextManager .getContextEntity (String .class , Starter .APPID_ID );
55+ String secret = contextManager .getContextEntity (String .class , Starter .SECRET_ID );
5556 token = authV2Base .auth (
56- String .format ("{\" appId\" : \" %s\" ,\" clientSecret\" : \" %s\" }\n " , contextManager .getContextEntity (String .class , Starter .APPID_ID ), secret )
57- , Channel .SEND_MESSAGE_HEADERS
58- );
57+ String .format ("{\" appId\" : \" %s\" ,\" clientSecret\" : \" %s\" }\n " , appid , secret )
58+ , Channel .SEND_MESSAGE_HEADERS );
5959 token .setT0 (System .currentTimeMillis ());
6060 return token .getAccess_token ();
6161 }
62+
63+ public String getAccessToken () {
64+ return isExpired (token ) ? getV2Token () : token .getAccess_token ();
65+ }
6266}
0 commit comments