|
@@ -106,13 +106,23 @@ public class WxApi {
|
|
|
map.put("url",detailUrl);
|
|
|
String result = HttpUtils.sendPost(url, JSONObject.toJSONString(map), null);
|
|
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
- if (!"0".equals(jsonObject.get("errcode").toString())){
|
|
|
- throw new CustomException(String.format("发送异常:code:%s,message:%s",jsonObject.get("errcode"),jsonObject.get("errmsg")));
|
|
|
- }
|
|
|
return jsonObject.toJSONString();
|
|
|
|
|
|
}
|
|
|
|
|
|
+ public String againSendMessage(String result,String openId, Object data, String templateId,String detailUrl,String appId,String appSecret) {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+ if (!"0".equals(jsonObject.get("errcode").toString())){
|
|
|
+ if ("40001".equals(jsonObject.get("errcode").toString())){
|
|
|
+ String token = reloadToken(appId, appSecret);
|
|
|
+ result = sendMessageApi(openId,data,token,templateId,detailUrl);
|
|
|
+ }else {
|
|
|
+ throw new CustomException(String.format("发送异常:code:%s,message:%s",jsonObject.get("errcode"),jsonObject.get("errmsg")));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取token
|
|
|
* @param appId
|
|
@@ -139,6 +149,14 @@ public class WxApi {
|
|
|
return s;
|
|
|
}
|
|
|
|
|
|
+ public String reloadToken(String appId,String appSecret){
|
|
|
+ boolean b = redisCache.deleteObject(appId + ACCESS_TOKEN);
|
|
|
+ if (!b){
|
|
|
+ throw new CustomException("删除缓存失败请联系管理员");
|
|
|
+ }
|
|
|
+ return getToken(appId,appSecret);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取ticket
|
|
|
* @param token
|