|
@@ -108,6 +108,10 @@ public class WcChatMessageUtils {
|
|
message.setClient_msg_id(client_msg_id);
|
|
message.setClient_msg_id(client_msg_id);
|
|
message.setData(data);
|
|
message.setData(data);
|
|
|
|
|
|
|
|
+ sendWecChatMessage(userId, wechatMsgTemplateId, systemUserId, objectId, userOpenId, message,1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void sendWecChatMessage(Long userId, String wechatMsgTemplateId, Long systemUserId, Long objectId, String userOpenId, WeChatTemplateMessage message, int maxRetries) {
|
|
// 发送消息
|
|
// 发送消息
|
|
String returnMsg = HttpUtil.post(StrUtil.format("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={}", getAccessToken()), message.toString());
|
|
String returnMsg = HttpUtil.post(StrUtil.format("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={}", getAccessToken()), message.toString());
|
|
cn.hutool.json.JSONObject jsonObject2 = JSONUtil.parseObj(returnMsg);
|
|
cn.hutool.json.JSONObject jsonObject2 = JSONUtil.parseObj(returnMsg);
|
|
@@ -131,6 +135,13 @@ public class WcChatMessageUtils {
|
|
}
|
|
}
|
|
|
|
|
|
messageLogService.createMessageLog(messageLogSaveReqVO);
|
|
messageLogService.createMessageLog(messageLogSaveReqVO);
|
|
|
|
+
|
|
|
|
+ // 如果微信的accessToken失效,则重新获取,最多重试3次
|
|
|
|
+ if (jsonObject2.getStr("errcode").equals("40001") && maxRetries <= 3) {
|
|
|
|
+ maxRetries++;
|
|
|
|
+ stringRedisTemplate.delete(WX_TICK_KEY_APPID);
|
|
|
|
+ sendWecChatMessage(userId, wechatMsgTemplateId, systemUserId, objectId, userOpenId, message, maxRetries);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|