11package cn .binarywang .wx .miniapp .api .impl ;
22
3- import java .io .File ;
43import java .io .IOException ;
54import java .util .HashMap ;
65import java .util .Map ;
1211import org .apache .http .client .methods .HttpGet ;
1312import org .apache .http .impl .client .BasicResponseHandler ;
1413import org .apache .http .impl .client .CloseableHttpClient ;
15- import org .slf4j .Logger ;
16- import org .slf4j .LoggerFactory ;
1714
1815import cn .binarywang .wx .miniapp .api .WxMaAnalysisService ;
1916import cn .binarywang .wx .miniapp .api .WxMaCodeService ;
2219import cn .binarywang .wx .miniapp .api .WxMaMsgService ;
2320import cn .binarywang .wx .miniapp .api .WxMaQrcodeService ;
2421import cn .binarywang .wx .miniapp .api .WxMaRunService ;
22+ import cn .binarywang .wx .miniapp .api .WxMaSecCheckService ;
2523import cn .binarywang .wx .miniapp .api .WxMaService ;
2624import cn .binarywang .wx .miniapp .api .WxMaSettingService ;
2725import cn .binarywang .wx .miniapp .api .WxMaShareService ;
3129import cn .binarywang .wx .miniapp .config .WxMaConfig ;
3230import com .google .common .base .Joiner ;
3331import com .google .gson .Gson ;
32+ import lombok .extern .slf4j .Slf4j ;
3433import me .chanjar .weixin .common .bean .WxAccessToken ;
35- import me .chanjar .weixin .common .bean .result .WxMediaUploadResult ;
3634import me .chanjar .weixin .common .error .WxError ;
3735import me .chanjar .weixin .common .error .WxErrorException ;
3836import me .chanjar .weixin .common .util .DataUtils ;
3937import me .chanjar .weixin .common .util .crypto .SHA1 ;
4038import me .chanjar .weixin .common .util .http .HttpType ;
41- import me .chanjar .weixin .common .util .http .MediaUploadRequestExecutor ;
4239import me .chanjar .weixin .common .util .http .RequestExecutor ;
4340import me .chanjar .weixin .common .util .http .RequestHttp ;
4441import me .chanjar .weixin .common .util .http .SimpleGetRequestExecutor ;
5148/**
5249 * @author <a href="https://github.com/binarywang">Binary Wang</a>
5350 */
51+ @ Slf4j
5452public class WxMaServiceImpl implements WxMaService , RequestHttp <CloseableHttpClient , HttpHost > {
55- private final Logger log = LoggerFactory .getLogger (this .getClass ());
56-
5753 private CloseableHttpClient httpClient ;
5854 private HttpHost httpProxy ;
5955 private WxMaConfig wxMaConfig ;
@@ -69,6 +65,7 @@ public class WxMaServiceImpl implements WxMaService, RequestHttp<CloseableHttpCl
6965 private WxMaJsapiService jsapiService = new WxMaJsapiServiceImpl (this );
7066 private WxMaShareService shareService = new WxMaShareServiceImpl (this );
7167 private WxMaRunService runService = new WxMaRunServiceImpl (this );
68+ private WxMaSecCheckService secCheckService = new WxMaSecCheckServiceImpl (this );
7269
7370 private int retrySleepMillis = 1000 ;
7471 private int maxRetryTimes = 5 ;
@@ -153,13 +150,6 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
153150 return this .getWxMaConfig ().getAccessToken ();
154151 }
155152
156- @ Override
157- public boolean imgSecCheck (File file ) throws WxErrorException {
158- //这里只是借用MediaUploadRequestExecutor,并不使用其返回值WxMediaUploadResult
159- WxMediaUploadResult result = this .execute (MediaUploadRequestExecutor .create (this .getRequestHttp ()), IMG_SEC_CHECK_URL , file );
160- return result != null ;
161- }
162-
163153 @ Override
164154 public WxMaJscode2SessionResult jsCode2SessionInfo (String jsCode ) throws WxErrorException {
165155 final WxMaConfig config = getWxMaConfig ();
@@ -209,7 +199,7 @@ public <T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) thro
209199 return this .executeInternal (executor , uri , data );
210200 } catch (WxErrorException e ) {
211201 if (retryTimes + 1 > this .maxRetryTimes ) {
212- this . log .warn ("重试达到最大次数【{}】" , maxRetryTimes );
202+ log .warn ("重试达到最大次数【{}】" , maxRetryTimes );
213203 //最后一次重试失败后,直接抛出异常,不再等待
214204 throw new RuntimeException ("微信服务端异常,超出重试次数" );
215205 }
@@ -219,7 +209,7 @@ public <T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) thro
219209 if (error .getErrorCode () == -1 ) {
220210 int sleepMillis = this .retrySleepMillis * (1 << retryTimes );
221211 try {
222- this . log .warn ("微信系统繁忙,{} ms 后重试(第{}次)" , sleepMillis , retryTimes + 1 );
212+ log .warn ("微信系统繁忙,{} ms 后重试(第{}次)" , sleepMillis , retryTimes + 1 );
223213 Thread .sleep (sleepMillis );
224214 } catch (InterruptedException e1 ) {
225215 throw new RuntimeException (e1 );
@@ -230,7 +220,7 @@ public <T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) thro
230220 }
231221 } while (retryTimes ++ < this .maxRetryTimes );
232222
233- this . log .warn ("重试达到最大次数【{}】" , this .maxRetryTimes );
223+ log .warn ("重试达到最大次数【{}】" , this .maxRetryTimes );
234224 throw new RuntimeException ("微信服务端异常,超出重试次数" );
235225 }
236226
@@ -246,7 +236,7 @@ private <T, E> T executeInternal(RequestExecutor<T, E> executor, String uri, E d
246236
247237 try {
248238 T result = executor .execute (uriWithAccessToken , data );
249- this . log .debug ("\n 【请求地址】: {}\n 【请求参数】:{}\n 【响应数据】:{}" , uriWithAccessToken , dataForLog , result );
239+ log .debug ("\n 【请求地址】: {}\n 【请求参数】:{}\n 【响应数据】:{}" , uriWithAccessToken , dataForLog , result );
250240 return result ;
251241 } catch (WxErrorException e ) {
252242 WxError error = e .getError ();
@@ -264,12 +254,12 @@ private <T, E> T executeInternal(RequestExecutor<T, E> executor, String uri, E d
264254 }
265255
266256 if (error .getErrorCode () != 0 ) {
267- this . log .error ("\n 【请求地址】: {}\n 【请求参数】:{}\n 【错误信息】:{}" , uriWithAccessToken , dataForLog , error );
257+ log .error ("\n 【请求地址】: {}\n 【请求参数】:{}\n 【错误信息】:{}" , uriWithAccessToken , dataForLog , error );
268258 throw new WxErrorException (error , e );
269259 }
270260 return null ;
271261 } catch (IOException e ) {
272- this . log .error ("\n 【请求地址】: {}\n 【请求参数】:{}\n 【异常信息】:{}" , uriWithAccessToken , dataForLog , e .getMessage ());
262+ log .error ("\n 【请求地址】: {}\n 【请求参数】:{}\n 【异常信息】:{}" , uriWithAccessToken , dataForLog , e .getMessage ());
273263 throw new RuntimeException (e );
274264 }
275265 }
@@ -349,4 +339,9 @@ public WxMaShareService getShareService() {
349339 public WxMaRunService getRunService () {
350340 return this .runService ;
351341 }
342+
343+ @ Override
344+ public WxMaSecCheckService getSecCheckService () {
345+ return this .secCheckService ;
346+ }
352347}
0 commit comments