66import com .getui .push .v2 .sdk .common .ApiException ;
77import com .getui .push .v2 .sdk .common .ApiResult ;
88import com .getui .push .v2 .sdk .common .Assert ;
9+ import com .getui .push .v2 .sdk .common .Config ;
910import com .getui .push .v2 .sdk .common .http .HttpManager ;
11+ import com .getui .push .v2 .sdk .common .type .TypeReference ;
1012import com .getui .push .v2 .sdk .common .util .Utils ;
1113import com .getui .push .v2 .sdk .core .Configs ;
1214import com .getui .push .v2 .sdk .core .domain .RasDomainBO ;
2426import java .security .InvalidParameterException ;
2527import java .util .*;
2628import java .util .concurrent .*;
29+ import java .util .regex .Pattern ;
2730
2831/**
2932 * 1. 管理token
@@ -107,6 +110,8 @@ public static DefaultApiClient build(GtApiConfiguration apiConfiguration, IJson
107110 while (iterator .hasNext ()) {
108111 Map .Entry <String , DefaultApiClient > entry = iterator .next ();
109112 if (entry .getKey ().startsWith (prefixOfKey )) {
113+ // 缓存更新之前校验应用信息是否正确
114+ checkAppInfo (apiConfiguration , json );
110115 defaultApiClient = entry .getValue ();
111116 defaultApiClient .apiConfiguration = apiConfiguration ;
112117 iterator .remove ();
@@ -121,6 +126,42 @@ public static DefaultApiClient build(GtApiConfiguration apiConfiguration, IJson
121126 return defaultApiClient ;
122127 }
123128
129+ final static Pattern HIDE_MASTER_SECRET_PATTERN = Pattern .compile ("(.{3}).+(.{3})" );
130+
131+ static void checkAppInfo (GtApiConfiguration configuration , IJson json ) {
132+ DefaultApiClient client = null ;
133+ try {
134+ GtApiConfiguration apiConfiguration = new GtApiConfiguration ();
135+ apiConfiguration .setAppId (configuration .getAppId ());
136+ apiConfiguration .setAppKey (configuration .getAppKey ());
137+ apiConfiguration .setMasterSecret (configuration .getMasterSecret ());
138+ apiConfiguration .setDomain (configuration .getDomain ());
139+ apiConfiguration .setOpenCheckHealthDataSwitch (false );
140+ apiConfiguration .setOpenAnalyseStableDomainSwitch (false );
141+ apiConfiguration .setTrustSSL (configuration .isTrustSSL ());
142+ apiConfiguration .setProxyConfig (configuration .getProxyConfig ());
143+
144+ client = new DefaultApiClient (apiConfiguration , json );
145+ final String fullUrl = client .genFullUrl (Config .AUTH_URI , null , null );
146+ AuthDTO authDTO = AuthDTO .build (apiConfiguration .getAppKey (), apiConfiguration .getMasterSecret ());
147+ String result = client .httpManager .syncHttps (fullUrl , "POST" , null , json .toJson (authDTO ), client .CONTENT_TYPE );
148+ ApiResult <TokenDTO > apiResult = json .fromJson (result , new TypeReference <ApiResult <TokenDTO >>() {
149+ }.getType ());
150+ if (!apiResult .isSuccess ()) {
151+ String hideSecret = HIDE_MASTER_SECRET_PATTERN .matcher (apiConfiguration .getMasterSecret ()).replaceAll ("$1********************$2" );
152+ log .error ("check app info failed. appId: {}, appKey: {}, masterSecret: {}, result: {}" ,
153+ apiConfiguration .getAppId (), apiConfiguration .getAppKey (), hideSecret , apiResult );
154+ throw new RuntimeException ("check app info failed. please check app info. appId: "
155+ + apiConfiguration .getAppId () + ", appKey: " + apiConfiguration .getAppKey ()
156+ + ", masterSecret: " + hideSecret );
157+ }
158+ } finally {
159+ if (client != null ) {
160+ client .close ();
161+ }
162+ }
163+ }
164+
124165 private DefaultApiClient (GtApiConfiguration apiConfiguration , IJson json ) {
125166 if (apiConfiguration == null ) {
126167 throw new ApiException ("apiConfiguration cannot be null." , true );
0 commit comments