@@ -305,18 +305,25 @@ public String get(String url, String queryParam) throws WxErrorException {
305
305
306
306
@ Override
307
307
public String post (String url , String postData ) throws WxErrorException {
308
- return execute (SimplePostRequestExecutor .create (this ), url , postData );
308
+ return execute (SimplePostRequestExecutor .create (this ), url , postData ,false );
309
+ }
310
+
311
+ public String post (String url , String postData ,boolean withoutSuiteAccessToken ) throws WxErrorException {
312
+ return execute (SimplePostRequestExecutor .create (this ), url , postData ,withoutSuiteAccessToken );
309
313
}
310
314
311
315
/**
312
316
* 向微信端发送请求,在这里执行的策略是当发生access_token过期时才去刷新,然后重新执行请求,而不是全局定时请求.
313
317
*/
314
318
@ Override
315
319
public <T , E > T execute (RequestExecutor <T , E > executor , String uri , E data ) throws WxErrorException {
320
+ return execute (executor , uri , data ,false );
321
+ }
322
+ public <T , E > T execute (RequestExecutor <T , E > executor , String uri , E data ,boolean withoutSuiteAccessToken ) throws WxErrorException {
316
323
int retryTimes = 0 ;
317
324
do {
318
325
try {
319
- return this .executeInternal (executor , uri , data );
326
+ return this .executeInternal (executor , uri , data , withoutSuiteAccessToken );
320
327
} catch (WxErrorException e ) {
321
328
if (retryTimes + 1 > this .maxRetryTimes ) {
322
329
log .warn ("重试达到最大次数【{}】" , this .maxRetryTimes );
@@ -347,14 +354,22 @@ public <T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) thro
347
354
}
348
355
349
356
protected <T , E > T executeInternal (RequestExecutor <T , E > executor , String uri , E data ) throws WxErrorException {
357
+ return executeInternal ( executor , uri ,data ,false );
358
+ }
359
+ protected <T , E > T executeInternal (RequestExecutor <T , E > executor , String uri , E data ,boolean withoutSuiteAccessToken ) throws WxErrorException {
350
360
E dataForLog = DataUtils .handleDataWithSecret (data );
351
361
352
362
if (uri .contains ("suite_access_token=" )) {
353
363
throw new IllegalArgumentException ("uri参数中不允许有suite_access_token: " + uri );
354
364
}
355
- String suiteAccessToken = getSuiteAccessToken (false );
365
+ String uriWithAccessToken ;
366
+ if (!withoutSuiteAccessToken ){
367
+ String suiteAccessToken = getSuiteAccessToken (false );
368
+ uriWithAccessToken = uri + (uri .contains ("?" ) ? "&" : "?" ) + "suite_access_token=" + suiteAccessToken ;
369
+ }else {
370
+ uriWithAccessToken = uri ;
371
+ }
356
372
357
- String uriWithAccessToken = uri + (uri .contains ("?" ) ? "&" : "?" ) + "suite_access_token=" + suiteAccessToken ;
358
373
359
374
try {
360
375
T result = executor .execute (uriWithAccessToken , data , WxType .CP );
@@ -452,9 +467,10 @@ public String getWxCpProviderToken() throws WxErrorException {
452
467
JsonObject jsonObject = new JsonObject ();
453
468
jsonObject .addProperty ("corpid" , configStorage .getCorpId ());
454
469
jsonObject .addProperty ("provider_secret" , configStorage .getProviderSecret ());
470
+ //providerAccessToken 的获取不需要suiteAccessToken ,一不必要,二可以提高效率
455
471
WxCpProviderToken wxCpProviderToken =
456
472
WxCpProviderToken .fromJson (this .post (this .configStorage .getApiUrl (GET_PROVIDER_TOKEN )
457
- , jsonObject .toString ()));
473
+ , jsonObject .toString (), true ));
458
474
String providerAccessToken = wxCpProviderToken .getProviderAccessToken ();
459
475
Integer expiresIn = wxCpProviderToken .getExpiresIn ();
460
476
0 commit comments