|
@@ -7,14 +7,12 @@ import com.usky.common.core.exception.BusinessException;
|
|
import com.usky.common.redis.core.RedisHelper;
|
|
import com.usky.common.redis.core.RedisHelper;
|
|
import com.usky.system.domain.MceMbuser;
|
|
import com.usky.system.domain.MceMbuser;
|
|
import com.usky.system.mapper.MceMbuserMapper;
|
|
import com.usky.system.mapper.MceMbuserMapper;
|
|
-import com.usky.system.service.ISysDictDataService;
|
|
|
|
import com.usky.system.service.MceMbuserService;
|
|
import com.usky.system.service.MceMbuserService;
|
|
import com.usky.system.constant.constant;
|
|
import com.usky.system.constant.constant;
|
|
import com.usky.common.mybatis.core.AbstractCrudService;
|
|
import com.usky.common.mybatis.core.AbstractCrudService;
|
|
-import com.usky.system.service.vo.SendWeChatMessageRequestVO;
|
|
|
|
-import com.usky.system.service.vo.TemplateData;
|
|
|
|
-import com.usky.system.service.vo.TemplateMsgEntityVO;
|
|
|
|
|
|
+import com.usky.system.service.vo.*;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -85,10 +83,11 @@ public class MceMbuserServiceImpl extends AbstractCrudService<MceMbuserMapper, M
|
|
redisHelper.set("access_key", this.getWeChatAccessToken());
|
|
redisHelper.set("access_key", this.getWeChatAccessToken());
|
|
} else {
|
|
} else {
|
|
try {
|
|
try {
|
|
- String access_time = redisHelper.get("access_time").toString();
|
|
|
|
- String now_time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
- long i = getTimeDifference(access_time, now_time);
|
|
|
|
- if (i > 115) { // 大于115分钟
|
|
|
|
|
|
+ String accessTime = redisHelper.get("access_time").toString();
|
|
|
|
+ String nowTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
+ long i = getTimeDifference(accessTime, nowTime);
|
|
|
|
+ // 大于115分钟
|
|
|
|
+ if (i > 115) {
|
|
redisHelper.set("access_time", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
redisHelper.set("access_time", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
redisHelper.set("access_key", this.getWeChatAccessToken());
|
|
redisHelper.set("access_key", this.getWeChatAccessToken());
|
|
}
|
|
}
|
|
@@ -104,35 +103,103 @@ public class MceMbuserServiceImpl extends AbstractCrudService<MceMbuserMapper, M
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
- String token = obj.toString();
|
|
|
|
|
|
+ String tUrl;
|
|
|
|
+ String templateId = "";
|
|
|
|
|
|
- TemplateMsgEntityVO messageVo = new TemplateMsgEntityVO();
|
|
|
|
- messageVo.setTTitle(infoTitle);
|
|
|
|
- messageVo.setTKeyword1(infoContent);
|
|
|
|
- messageVo.setTKeyword3(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
|
- messageVo.setTRemark(infoContent);
|
|
|
|
|
|
+ Map<String, TemplateData> data = new HashMap<>();
|
|
|
|
+ String nowTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
+
|
|
|
|
+ switch (requestVO.getInfoType()) {
|
|
|
|
+ // 登录成功通知
|
|
|
|
+ case "0":
|
|
|
|
+ // 登录时间
|
|
|
|
+ data.put("time3", new TemplateData(nowTime, "#173177"));
|
|
|
|
+ // 登录账号 userName
|
|
|
|
+ data.put("thing6", new TemplateData(requestVO.getUserName(), "#173177"));
|
|
|
|
+ // 登录IP
|
|
|
|
+ data.put("character_string8", new TemplateData(requestVO.getLoginAddress(), "#173177"));
|
|
|
|
+ // 登录地点
|
|
|
|
+ data.put("thing9", new TemplateData(requestVO.getLoginAddress(), "#173177"));
|
|
|
|
+ // 登录方式
|
|
|
|
+ data.put("thing10", new TemplateData(requestVO.getLoginType(), "#173177"));
|
|
|
|
+ // 设置公众号模板消息ID
|
|
|
|
+ templateId = constant.WE_CHAT_LOGIN_TEMPLATE_ID;
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case "1":
|
|
|
|
+ case "5":
|
|
|
|
+ /* 通知公告&工作报告通知(工单已完成通知)
|
|
|
|
+ * 工单标题{{thing9.DATA}}
|
|
|
|
+ * 发起人{{thing8.DATA}}
|
|
|
|
+ * 完成时间{{time12.DATA}}
|
|
|
|
+ **/
|
|
|
|
+ data.put("thing9", new TemplateData(requestVO.getInfoContent(), "#173177"));
|
|
|
|
+ data.put("thing8", new TemplateData(requestVO.getUserName(), "#173177"));
|
|
|
|
+ data.put("time12", new TemplateData(nowTime, "#173177"));
|
|
|
|
+ // 设置公众号模板消息ID
|
|
|
|
+ templateId = constant.WE_CHAT_WORK_TEMPLATE_ID;
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case "3":
|
|
|
|
+ /* OA系统流程审批通知
|
|
|
|
+ * 流程名称{{thing7.DATA}}
|
|
|
|
+ * 审批节点{{thing8.DATA}}
|
|
|
|
+ * 发起人{{thing13.DATA}}
|
|
|
|
+ * 发起时间{{time10.DATA}}
|
|
|
|
+ * 审批结果{{const21.DATA}}
|
|
|
|
+ **/
|
|
|
|
+ data.put("thing7", new TemplateData(requestVO.getInfoTitle(), "#173177"));
|
|
|
|
+ data.put("thing8", new TemplateData(requestVO.getInfoContent(), "#173177"));
|
|
|
|
+ data.put("thing13", new TemplateData(requestVO.getUserName(), "#173177"));
|
|
|
|
+ data.put("time10", new TemplateData(nowTime, "#173177"));
|
|
|
|
+ data.put("const21", new TemplateData(requestVO.getApprovalResult(), "#173177"));
|
|
|
|
+
|
|
|
|
+ // 设置公众号模板消息ID
|
|
|
|
+ templateId = constant.WE_CHAT_OA_TEMPLATE_ID;
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case "2":
|
|
|
|
+ case "4":
|
|
|
|
+ TemplateMsgEntityVO messageVo = new TemplateMsgEntityVO();
|
|
|
|
+ messageVo.setTTitle(infoTitle);
|
|
|
|
+ messageVo.setTKeyword1(infoContent);
|
|
|
|
+ messageVo.setTKeyword3(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
|
+ messageVo.setTRemark(infoContent);
|
|
|
|
+ /* 设备预警信息提醒
|
|
|
|
+ * {{first.DATA}}
|
|
|
|
+ * 设备号:{{keyword1.DATA}}
|
|
|
|
+ * 报警类型:{{keyword2.DATA}}
|
|
|
|
+ * 时间:{{keyword3.DATA}}
|
|
|
|
+ * {{remark.DATA}}
|
|
|
|
+ **/
|
|
|
|
+ messageVo.setTemplateId(constant.WE_CHAT_TEMPLATE_ID);
|
|
|
|
+ data.put("first", new TemplateData(messageVo.getTTitle(), "#44b549"));
|
|
|
|
+ data.put("keyword1", new TemplateData(messageVo.getTKeyword1(), "#173177"));
|
|
|
|
+ data.put("keyword2", new TemplateData(messageVo.getTKeyword2(), "#173177"));
|
|
|
|
+ data.put("keyword3", new TemplateData(messageVo.getTKeyword3(), "#173177"));
|
|
|
|
+ data.put("remark", new TemplateData(messageVo.getTRemark(), "#173177"));
|
|
|
|
+
|
|
|
|
+ templateId = messageVo.getTemplateId();
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 回调地址
|
|
if (Objects.nonNull(requestVO.getInfoTypeName())) {
|
|
if (Objects.nonNull(requestVO.getInfoTypeName())) {
|
|
- messageVo.setTUrl(String.format(constant.WE_CHAT_CUSTOMER_CALL_URL, requestVO.getInfoType(), requestVO.getInfoTypeName(), infoId));
|
|
|
|
- messageVo.setTKeyword2(requestVO.getInfoTypeName());
|
|
|
|
|
|
+ tUrl = String.format(constant.WE_CHAT_CUSTOMER_CALL_URL, requestVO.getInfoType(), requestVO.getInfoTypeName(), infoId);
|
|
} else {
|
|
} else {
|
|
- messageVo.setTUrl(String.format(constant.WE_CHAT_CUSTOMER_CALL_URL1, requestVO.getInfoType(), infoId));
|
|
|
|
- messageVo.setTKeyword2("");
|
|
|
|
|
|
+ tUrl = String.format(constant.WE_CHAT_CUSTOMER_CALL_URL1, requestVO.getInfoType(), infoId);
|
|
}
|
|
}
|
|
|
|
|
|
- messageVo.setTemplateId(constant.WE_CHAT_TEMPLATE_ID);
|
|
|
|
-
|
|
|
|
|
|
+ String token = obj.toString();
|
|
String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + token;
|
|
String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + token;
|
|
Map<String, Object> content = new HashMap<>();
|
|
Map<String, Object> content = new HashMap<>();
|
|
- Map<String, TemplateData> data = new HashMap<>();
|
|
|
|
- data.put("first", new TemplateData(messageVo.getTTitle(), "#44b549"));
|
|
|
|
- data.put("keyword1", new TemplateData(messageVo.getTKeyword1(), "#173177"));
|
|
|
|
- data.put("keyword2", new TemplateData(messageVo.getTKeyword2(), "#173177"));
|
|
|
|
- data.put("keyword3", new TemplateData(messageVo.getTKeyword3(), "#173177"));
|
|
|
|
- data.put("remark", new TemplateData(messageVo.getTRemark(), "#173177"));
|
|
|
|
-
|
|
|
|
content.put("touser", openId);
|
|
content.put("touser", openId);
|
|
- content.put("url", messageVo.getTUrl());
|
|
|
|
- content.put("template_id", messageVo.getTemplateId());
|
|
|
|
|
|
+ if (StringUtils.isNotBlank(tUrl)) {
|
|
|
|
+ content.put("url", tUrl);
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(templateId)) {
|
|
|
|
+ content.put("template_id", templateId);
|
|
|
|
+ }
|
|
content.put("data", data);
|
|
content.put("data", data);
|
|
String resp = HttpUtil.post(requestUrl, JSONUtil.parseObj(content).toString());
|
|
String resp = HttpUtil.post(requestUrl, JSONUtil.parseObj(content).toString());
|
|
System.out.println(content.toString());
|
|
System.out.println(content.toString());
|