1717public class Start0 {
1818
1919 public Map <String , String > headers = new HashMap ();
20- public Map <String , String > v2headers = new HashMap ();
2120
2221 @ AutoStand
2322 ContextManager contextManager ;
2423
2524 //ALL req token header
2625 public synchronized Map <String , String > getHeaders () {
27- if (isExpired (token )) headers .clear ();
28- if (headers .isEmpty ()) {
29- headers .put ("Authorization" , String .format ("QQBot %s" , getV2Token ()));
30- headers .put ("Accept-Encoding" , "application/json" );
31- headers .put ("X-Union-Appid" , contextManager .getContextEntity (String .class , Starter .APPID_ID ));
32- }
26+ if (headers .isEmpty () || isExpired (token )) updateToken ();
3327 return headers ;
3428 }
3529
3630 private boolean isExpired (Token token ) {
3731 return token == null || token .isExpired ();
3832 }
3933
40- @ AutoStand
41- AuthV2Base authV2Base ;
34+ private Token token ;
4235
36+ public String getAccessToken () {
37+ if (isExpired (token )) updateToken ();
38+ return token .getAccess_token ();
39+ }
4340
44- private Token token ;
41+ public void updateToken () {
42+ headers .clear ();
43+ String v2token = getV2Token ();
44+ headers .put ("Authorization" , String .format ("QQBot %s" , v2token ));
45+ headers .put ("Accept-Encoding" , "application/json" );
46+ headers .put ("X-Union-Appid" , contextManager .getContextEntity (String .class , Starter .APPID_ID ));
47+ }
48+
49+ @ AutoStand
50+ AuthV2Base authV2Base ;
4551
4652 private String getV2Token () {
4753 String appid = contextManager .getContextEntity (String .class , Starter .APPID_ID );
4854 String secret = contextManager .getContextEntity (String .class , Starter .SECRET_ID );
49- token = authV2Base .auth (
50- String .format ("{\" appId\" : \" %s\" ,\" clientSecret\" : \" %s\" }\n " , appid , secret )
51- , Channel .SEND_MESSAGE_HEADERS );
52- token .setT0 (System .currentTimeMillis ());
55+ token = authV2Base .auth (String .format ("{\" appId\" : \" %s\" ,\" clientSecret\" : \" %s\" }\n " , appid , secret )
56+ , Channel .SEND_MESSAGE_HEADERS ).setT0 (System .currentTimeMillis ());
5357 return token .getAccess_token ();
5458 }
55-
56- public String getAccessToken () {
57- return isExpired (token ) ? getV2Token () : token .getAccess_token ();
58- }
5959}
0 commit comments