Merge remote-tracking branch 'origin/cc_20230520_partner'

This commit is contained in:
zhangchenbiao
2023-07-07 12:49:41 +08:00
3 changed files with 34 additions and 16 deletions

View File

@@ -368,4 +368,24 @@ public class ISVHttpRequest {
throw new ApiException(e.getMessage());
}
}
public String getWechatAccessToken(String appId, String appSecret)throws ApiException{
String url = "https://isv-partner.hsay.com/isv/wechat/getWechatAccessToken";
//String url = "https://abstore-isv.coolstore.cn/isv/wechat/getWechatAccessToken";
HashMap requestMap = new HashMap();
requestMap.put("appId", appId);
requestMap.put("appSecret", appSecret);
ResultDTO responseEntity = null;
try {
responseEntity = httpRestTemplateService.getForObject(url, ResultDTO.class, requestMap);
log.info("url:{}, response:{}", url, JSONObject.toJSONString(responseEntity));
if(Objects.nonNull(responseEntity.getData()) && responseEntity.isSuccess()){
return (String) responseEntity.getData();
}
} catch (Exception e) {
log.info("调用isv出错{}", e);
throw new ApiException(e.getMessage());
}
return null;
}
}

View File

@@ -29,6 +29,8 @@ public class WechatRest {
@Resource
private HttpRestTemplateService httpRestTemplateService;
@Resource
private ISVHttpRequest isvHttpRequest;
/**
* 小程序Token 地址
@@ -62,26 +64,12 @@ public class WechatRest {
}
public String getAccessToken(String appId, String secret) {
/*String cacheAccessToken = "mini_" + appId;
String accessToken = redisUtilPool.getString(cacheAccessToken);
if (StringUtils.isNotBlank(accessToken)) {
return accessToken;
}*/
String reqUrl = String.format(ACCESS_TOKEN, appId, secret);
try {
JSONObject jsonObject = httpRestTemplateService.getForObject(reqUrl, JSONObject.class, new HashMap());
log.info("WechatRest#getAccessToken, reqUrl:{}, response:{}", reqUrl, JSONObject.toJSONString(jsonObject));
String token = jsonObject.getString("access_token");
if (StringUtils.isBlank(token)) {
throw new ServiceException(ErrorCodeEnum.GET_ACCESSTOKEN_ERROR);
}
// redisUtilPool.setString(cacheAccessToken, token, 7000);
// accessToken = token;
return token;
return isvHttpRequest.getWechatAccessToken(appId, secret);
} catch (Exception e) {
log.error("获取微信小程序token异常", e);
throw new ServiceException(ErrorCodeEnum.GET_ACCESSTOKEN_ERROR);
}
return null;
}

View File

@@ -256,4 +256,14 @@ public class TestController {
hyPhoneLocationService.handleHyPhoneAddress(phone);
return ResponseResult.success(Boolean.TRUE);
}
@GetMapping("/getWechatAccessToken")
public ResponseResult getWechatAccessToken(@RequestParam(value = "appId")String appId, @RequestParam("appSecret")String appSecret){
try {
return ResponseResult.success(isvHttpRequest.getWechatAccessToken(appId, appSecret));
} catch (ApiException e) {
e.printStackTrace();
}
return null;
}
}