11package me .chanjar .weixin .mp .api .impl ;
22
3- import java .io .IOException ;
4- import java .util .concurrent .locks .Lock ;
5-
6- import org .slf4j .Logger ;
7- import org .slf4j .LoggerFactory ;
8-
93import com .google .gson .JsonArray ;
104import com .google .gson .JsonElement ;
115import com .google .gson .JsonObject ;
126import com .google .gson .JsonParser ;
13-
147import me .chanjar .weixin .common .bean .WxJsapiSignature ;
158import me .chanjar .weixin .common .bean .result .WxError ;
169import me .chanjar .weixin .common .exception .WxErrorException ;
2215import me .chanjar .weixin .mp .api .*;
2316import me .chanjar .weixin .mp .bean .*;
2417import me .chanjar .weixin .mp .bean .result .*;
18+ import org .slf4j .Logger ;
19+ import org .slf4j .LoggerFactory ;
20+
21+ import java .io .IOException ;
22+ import java .util .concurrent .locks .Lock ;
2523
26- public abstract class AbstractWxMpService <H ,P > implements WxMpService ,RequestHttp <H ,P > {
24+ public abstract class AbstractWxMpServiceImpl <H , P > implements WxMpService , RequestHttp <H , P > {
2725
2826 private static final JsonParser JSON_PARSER = new JsonParser ();
2927
@@ -46,7 +44,6 @@ public abstract class AbstractWxMpService<H,P> implements WxMpService,RequestHtt
4644 private int retrySleepMillis = 1000 ;
4745 private int maxRetryTimes = 5 ;
4846
49-
5047 @ Override
5148 public boolean checkSignature (String timestamp , String nonce , String signature ) {
5249 try {
@@ -296,7 +293,6 @@ public <T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) thro
296293 do {
297294 try {
298295 T result = executeInternal (executor , uri , data );
299- this .log .debug ("\n [URL]: {}\n [PARAMS]: {}\n [RESPONSE]: {}" , uri , data , result );
300296 return result ;
301297 } catch (WxErrorException e ) {
302298 if (retryTimes + 1 > this .maxRetryTimes ) {
@@ -326,16 +322,22 @@ public <T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) thro
326322 }
327323
328324 public synchronized <T , E > T executeInternal (RequestExecutor <T , E > executor , String uri , E data ) throws WxErrorException {
329- if (uri .indexOf ("access_token=" ) != - 1 ) {
325+ if (uri .contains ("access_token=" )) {
330326 throw new IllegalArgumentException ("uri参数中不允许有access_token: " + uri );
331327 }
332328 String accessToken = getAccessToken (false );
333329
334- String uriWithAccessToken = uri ;
335- uriWithAccessToken += uri .indexOf ('?' ) == -1 ? "?access_token=" + accessToken : "&access_token=" + accessToken ;
330+ String uriWithAccessToken ;
331+ if (uri .contains ("?" )) {
332+ uriWithAccessToken = uri + "&access_token=" + accessToken ;
333+ } else {
334+ uriWithAccessToken = uri + "?access_token=" + accessToken ;
335+ }
336336
337337 try {
338- return executor .execute (this , uriWithAccessToken , data );
338+ T result = executor .execute (this , uriWithAccessToken , data );
339+ this .log .debug ("\n [URL]: {}\n [PARAMS]: {}\n [RESPONSE]: {}" , uriWithAccessToken , data , result );
340+ return result ;
339341 } catch (WxErrorException e ) {
340342 WxError error = e .getError ();
341343 /*
@@ -352,12 +354,12 @@ public synchronized <T, E> T executeInternal(RequestExecutor<T, E> executor, Str
352354 }
353355
354356 if (error .getErrorCode () != 0 ) {
355- this .log .error ("\n [URL]: {}\n [PARAMS]: {}\n [RESPONSE]: {}" , uri , data , error );
357+ this .log .error ("\n [URL]: {}\n [PARAMS]: {}\n [RESPONSE]: {}" , uriWithAccessToken , data , error );
356358 throw new WxErrorException (error );
357359 }
358360 return null ;
359361 } catch (IOException e ) {
360- this .log .error ("\n [URL]: {}\n [PARAMS]: {}\n [EXCEPTION]: {}" , uri , data , e .getMessage ());
362+ this .log .error ("\n [URL]: {}\n [PARAMS]: {}\n [EXCEPTION]: {}" , uriWithAccessToken , data , e .getMessage ());
361363 throw new RuntimeException (e );
362364 }
363365 }
0 commit comments