|
@@ -58,7 +58,7 @@ public class TWechatServiceImpl extends ServiceImpl<TWechatMapper, TWechat> impl
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public void sendNoworkMessage(String openId, String clientId, String name, String ifForeign, String companyType) {
|
|
|
+ public void sendNetworkMessage(String openId, String clientId, String name, String ifForeign, String companyType) {
|
|
|
// 模板参数
|
|
|
Map<String, WeChatTemplateMsg> sendMag = new HashMap();
|
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
@@ -81,7 +81,11 @@ public class TWechatServiceImpl extends ServiceImpl<TWechatMapper, TWechat> impl
|
|
|
sendMag.put("time5", new WeChatTemplateMsg(alarmTime));
|
|
|
sendMag.put("thing6", new WeChatTemplateMsg("Power/Network loss."));
|
|
|
}
|
|
|
- sendWechatMessage(openId, sendMag, companyType);
|
|
|
+ if(StringUtils.isEmpty(companyType) || companyType.equals("0")) {
|
|
|
+ sendWechatMessage(openId, sendMag, companyType, ConfigConsts.SZ_TEMPLATE_ID);
|
|
|
+ } else {
|
|
|
+ sendWechatMessage(openId, sendMag, companyType, ConfigConsts.SC_TEMPLATE_ID);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -101,7 +105,11 @@ public class TWechatServiceImpl extends ServiceImpl<TWechatMapper, TWechat> impl
|
|
|
sendMag.put("thing4", new WeChatTemplateMsg("高"));
|
|
|
sendMag.put("time5", new WeChatTemplateMsg(alarmTime));
|
|
|
sendMag.put("thing6", new WeChatTemplateMsg(alarmContent));
|
|
|
- sendWechatMessage(openId, sendMag, companyType);
|
|
|
+ if(StringUtils.isEmpty(companyType) || companyType.equals("0")) {
|
|
|
+ sendWechatMessage(openId, sendMag, companyType, ConfigConsts.SZ_TEMPLATE_ID);
|
|
|
+ } else {
|
|
|
+ sendWechatMessage(openId, sendMag, companyType, ConfigConsts.SC_TEMPLATE_ID);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -180,6 +188,44 @@ public class TWechatServiceImpl extends ServiceImpl<TWechatMapper, TWechat> impl
|
|
|
return accessToken;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void sendOnOffMessage(String openId, String clientId, String networkTime, String companyType, String name, Integer eqeStatus) {
|
|
|
+ // 模板参数
|
|
|
+ Map<String, WeChatTemplateMsg> sendMag = new HashMap();
|
|
|
+ // 转换时间为String类型
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ Long time = Long.valueOf(networkTime);
|
|
|
+ String workTime = format.format(time);
|
|
|
+ clientId = clientId.substring(clientId.length() - 6);
|
|
|
+ // 模版参数
|
|
|
+ if(name.length() > 20) {
|
|
|
+ sendMag.put("thing2", new WeChatTemplateMsg(name.substring(0, 16) + "..."));
|
|
|
+ } else {
|
|
|
+ sendMag.put("thing2", new WeChatTemplateMsg(name));
|
|
|
+ }
|
|
|
+ if (eqeStatus == 1) {
|
|
|
+ sendMag.put("character_string9", new WeChatTemplateMsg(clientId));
|
|
|
+ } else {
|
|
|
+ sendMag.put("thing6", new WeChatTemplateMsg(clientId));
|
|
|
+ }
|
|
|
+ sendMag.put("time4", new WeChatTemplateMsg(workTime));
|
|
|
+ String templateId = "";
|
|
|
+ if(StringUtils.isEmpty(companyType) || companyType.equals("0")) {
|
|
|
+ if(eqeStatus == 1) {
|
|
|
+ templateId = ConfigConsts.SZ_ON_TEMPLATE_ID;
|
|
|
+ } else {
|
|
|
+ templateId = ConfigConsts.SZ_OFF_TEMPLATE_ID;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if(eqeStatus == 1) {
|
|
|
+ templateId = ConfigConsts.SC_ON_TEMPLATE_ID;
|
|
|
+ } else {
|
|
|
+ templateId = ConfigConsts.SC_OFF_TEMPLATE_ID;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sendWechatMessage(openId, sendMag, companyType, templateId);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取accessToken推送消息
|
|
|
* @param openId
|
|
@@ -187,7 +233,7 @@ public class TWechatServiceImpl extends ServiceImpl<TWechatMapper, TWechat> impl
|
|
|
* @param companyType
|
|
|
* @return
|
|
|
*/
|
|
|
- public void sendWechatMessage(String openId, Map<String, WeChatTemplateMsg> sendMag, String companyType) {
|
|
|
+ public void sendWechatMessage(String openId, Map<String, WeChatTemplateMsg> sendMag, String companyType, String templateId) {
|
|
|
String accessToken = "";
|
|
|
try {
|
|
|
if(StringUtils.isEmpty(companyType) || companyType.equals("0")) {
|
|
@@ -209,13 +255,11 @@ public class TWechatServiceImpl extends ServiceImpl<TWechatMapper, TWechat> impl
|
|
|
sendBody.put("touser", openId);
|
|
|
sendBody.put("topcolor", "#FF0000");
|
|
|
sendBody.put("data", sendMag);
|
|
|
+ sendBody.put("template_id", templateId);
|
|
|
if(StringUtils.isEmpty(companyType) || companyType.equals("0")) {
|
|
|
- sendBody.put("template_id", ConfigConsts.SZ_TEMPLATE_ID);
|
|
|
sendBody.put("url", "http://szwlh.sunzee.com.cn/shenze/");
|
|
|
} else {
|
|
|
- sendBody.put("template_id", ConfigConsts.SC_TEMPLATE_ID);
|
|
|
sendBody.put("url", "http://sevencloud.com.cn/sc/");
|
|
|
-
|
|
|
}
|
|
|
String sendUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken;
|
|
|
ResponseEntity<String> forEntity = restTemplate.postForEntity(sendUrl, sendBody, String.class);
|