| @@ -210,36 +210,34 @@ public class TtMaServiceImpl implements TtMaService, RequestHttp<CloseableHttpCl | |||||
| throw new RuntimeException("微信服务端异常,超出重试次数"); | throw new RuntimeException("微信服务端异常,超出重试次数"); | ||||
| } | } | ||||
| public static void main(String[] args) { | |||||
| String str = "123"; | |||||
| JSONObject jsonObject = (JSONObject) JSON.toJSON(str); | |||||
| jsonObject.put("access_token","456"); | |||||
| System.out.println(jsonObject.toJSONString()); | |||||
| } | |||||
| private <T, E> T executeInternal(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException { | private <T, E> T executeInternal(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException { | ||||
| E dataForLog = DataUtils.handleDataWithSecret(data); | E dataForLog = DataUtils.handleDataWithSecret(data); | ||||
| if (uri.contains("access_token=")) { | if (uri.contains("access_token=")) { | ||||
| throw new IllegalArgumentException("uri参数中不允许有access_token: " + uri); | throw new IllegalArgumentException("uri参数中不允许有access_token: " + uri); | ||||
| } | } | ||||
| // String accessToken = getAccessToken(false); | |||||
| // try { | |||||
| // if(!(data instanceof String)){ | |||||
| // JSONObject jsonObject = (JSONObject) JSON.toJSON(data); | |||||
| // jsonObject.put("access_token",accessToken); | |||||
| // data = (E)jsonObject; | |||||
| // } | |||||
| // } catch (Exception e){ | |||||
| // log.error("\n【请求参数+access_token】:{}\n【错误信息】:{}", dataForLog, e.getMessage()); | |||||
| // } | |||||
| String accessToken = getAccessToken(false); | |||||
| E param = null; | |||||
| try { | |||||
| if(!(data instanceof String)){ | |||||
| JSONObject jsonObject = (JSONObject) JSON.toJSON(data); | |||||
| jsonObject.put("access_token",accessToken); | |||||
| param = (E)jsonObject; | |||||
| } | |||||
| } catch (Exception e){ | |||||
| log.error("\n【请求参数+access_token】:{}\n【错误信息】:{}", dataForLog, e.getMessage()); | |||||
| } | |||||
| if(param == null){ | |||||
| param = data; | |||||
| } | |||||
| // String uriWithAccessToken = uri + (uri.contains("?") ? "&" : "?") + "access_token=" + accessToken; | // String uriWithAccessToken = uri + (uri.contains("?") ? "&" : "?") + "access_token=" + accessToken; | ||||
| String uriWithAccessToken = uri; | String uriWithAccessToken = uri; | ||||
| try { | try { | ||||
| T result = executor.execute(uriWithAccessToken, data, WxType.MiniApp); | |||||
| T result = executor.execute(uriWithAccessToken, param, WxType.MiniApp); | |||||
| log.debug("\n【请求地址】: {}\n【请求参数】:{}\n【响应数据】:{}", uriWithAccessToken, dataForLog, result); | log.debug("\n【请求地址】: {}\n【请求参数】:{}\n【响应数据】:{}", uriWithAccessToken, dataForLog, result); | ||||
| return result; | return result; | ||||
| } catch (WxErrorException e) { | } catch (WxErrorException e) { | ||||