| @@ -158,14 +158,15 @@ public class WxMpServiceImpl implements WxMpService { | |||
| RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build(); | |||
| httpGet.setConfig(config); | |||
| } | |||
| CloseableHttpResponse response = getHttpclient().execute(httpGet); | |||
| String resultContent = new BasicResponseHandler().handleResponse(response); | |||
| WxError error = WxError.fromJson(resultContent); | |||
| if (error.getErrorCode() != 0) { | |||
| throw new WxErrorException(error); | |||
| try (CloseableHttpResponse response = getHttpclient().execute(httpGet)) { | |||
| String resultContent = new BasicResponseHandler().handleResponse(response); | |||
| WxError error = WxError.fromJson(resultContent); | |||
| if (error.getErrorCode() != 0) { | |||
| throw new WxErrorException(error); | |||
| } | |||
| WxAccessToken accessToken = WxAccessToken.fromJson(resultContent); | |||
| wxMpConfigStorage.updateAccessToken(accessToken.getAccessToken(), accessToken.getExpiresIn()); | |||
| } | |||
| WxAccessToken accessToken = WxAccessToken.fromJson(resultContent); | |||
| wxMpConfigStorage.updateAccessToken(accessToken.getAccessToken(), accessToken.getExpiresIn()); | |||
| } catch (ClientProtocolException e) { | |||
| throw new RuntimeException(e); | |||
| } catch (IOException e) { | |||
| @@ -851,8 +852,7 @@ public class WxMpServiceImpl implements WxMpService { | |||
| StringEntity entity = new StringEntity(request.toString(), Consts.UTF_8); | |||
| httpPost.setEntity(entity); | |||
| try { | |||
| CloseableHttpResponse response = getHttpclient().execute(httpPost); | |||
| try(CloseableHttpResponse response = getHttpclient().execute(httpPost)) { | |||
| String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); | |||
| XStream xstream = XStreamInitializer.getInstance(); | |||
| xstream.alias("xml", WxMpPrepayIdResult.class); | |||
| @@ -944,8 +944,7 @@ public class WxMpServiceImpl implements WxMpService { | |||
| StringEntity entity = new StringEntity(request.toString(), Consts.UTF_8); | |||
| httpPost.setEntity(entity); | |||
| try { | |||
| CloseableHttpResponse response = httpClient.execute(httpPost); | |||
| try(CloseableHttpResponse response = httpClient.execute(httpPost)) { | |||
| String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); | |||
| XStream xstream = XStreamInitializer.getInstance(); | |||
| xstream.alias("xml", WxMpPayResult.class); | |||
| @@ -1000,8 +999,7 @@ public class WxMpServiceImpl implements WxMpService { | |||
| StringEntity entity = new StringEntity(request.toString(), Consts.UTF_8); | |||
| httpPost.setEntity(entity); | |||
| try { | |||
| CloseableHttpResponse response = getHttpclient().execute(httpPost); | |||
| try(CloseableHttpResponse response = getHttpclient().execute(httpPost)) { | |||
| String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); | |||
| XStream xstream = XStreamInitializer.getInstance(); | |||
| xstream.processAnnotations(WxRedpackResult.class); | |||