123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- package com.hssx.cloudmodel.util;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONObject;
- import com.hssx.cloudmodel.constant.Constant;
- import com.hssx.cloudmodel.entity.vo.MouldEquipmentVO;
- import org.apache.commons.lang3.StringEscapeUtils;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.Map;
- /**
- * Author: 吴涛涛 cuiyi@itany.com
- * Date : 2019 - 08 - 29 14:46
- * Description:<描述>
- * Version: 1.0
- */
- public class WechatTemplateUtil {
- /**
- * 云模盒告警模板
- * touserOpenId 被推送者的openId
- * firstData 推送标题
- * equipmentName 设备名称,emergencyType 告警类型,emergencyContent 内容,newAccessToken token
- */
- public static void sendEmergencyTemplateMessage(String touserOpenId,String equipmentName,String emergencyType,String emergencyContent,String newAccessToken) throws Exception {
- HttpRespMsg msg = new HttpRespMsg();
- String url1 = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="
- + newAccessToken;
- WechatTemplateMessage wechat = new WechatTemplateMessage();
- wechat.setTemplate_id(Constant.WARNING_NOTICE_TEMPLATE_ID);
- wechat.setTouser(touserOpenId);
- wechat.setAppid(Constant.WECHAT_APPID);
- Map<String, Map<String, String>> data = new HashMap<>();
- Map<String, String> first = new HashMap<>();
- Map<String, String> value1 = new HashMap<>();
- Map<String, String> value2 = new HashMap<>();
- Map<String, String> value3 = new HashMap<>();
- Map<String, String> value4 = new HashMap<>();
- Map<String, String> remark = new HashMap<>();
- // 推送信息主体
- first.put("value", "告警通知");//firstData推送标题
- data.put("first", first);
- value1.put("value", equipmentName);
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- data.put("keyword1", value1);
- value2.put("value", emergencyType);
- data.put("keyword2", value2);
- value3.put("value", sdf.format(new Date()));
- data.put("keyword3", value3);
- value4.put("value", emergencyContent);
- data.put("keyword4", value4);
- remark.put("value", "请尽快检查该设备");
- data.put("remark", remark);
- wechat.setData(data);
- String jsonString = JSONObject.toJSONString(wechat);
- // System.out.println("jsonString"+jsonString);
- String resp = HttpKit.post(url1, jsonString);
- // System.out.println("resp0"+resp);
- resp = StringEscapeUtils.unescapeJava(resp);
- // System.out.println("resp"+resp);
- JSONObject json = (JSONObject) JSON.parse(resp);
- }
- /**
- * 模具保养
- * templateId 模板id,touserOpenId 被推送者的openId,appId微信公众号的appId
- * firstData 推送标题
- * mouldName 模具名称,maintain 方式(保养),maintainCause 保养原因,newAccessToken token
- */
- public static void sendMaintainTemplateMessage( String touserOpenId,String mouldName,String maintain,String maintainCause,String newAccessToken) throws Exception {
- // 获取值赋值给全局变量
- String url1 = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="
- + newAccessToken;
- WechatTemplateMessage wechat = new WechatTemplateMessage();
- wechat.setTemplate_id(Constant.MAINTAIN_NOTICE_TEMPLATE_ID);
- wechat.setTouser(touserOpenId);
- wechat.setAppid(Constant.WECHAT_APPID );
- Map<String, Map<String, String>> data = new HashMap<>();
- Map<String, String> first = new HashMap<>();
- Map<String, String> value1 = new HashMap<>();
- Map<String, String> value2 = new HashMap<>();
- Map<String, String> value3 = new HashMap<>();
- Map<String, String> value4 = new HashMap<>();
- Map<String, String> remark = new HashMap<>();
- // 推送信息主体
- first.put("value", "你好,你有新的保养通知");//firstData推送标题
- data.put("first", first);
- value1.put("value", mouldName);
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
- data.put("keyword1", value1);
- value2.put("value","暂无");
- data.put("keyword2", value2);
- value3.put("value", sdf.format(new Date()));
- data.put("keyword3", value3);
- value4.put("value", maintain);
- data.put("keyword4", value4);
- remark.put("value", maintainCause);
- data.put("remark", remark);
- wechat.setData(data);
- String jsonString = JSONObject.toJSONString(wechat);
- // System.out.println("jsonString"+jsonString);
- String resp = HttpKit.post(url1, jsonString);
- // System.out.println("resp0"+resp);
- resp = StringEscapeUtils.unescapeJava(resp);
- // System.out.println("resp"+resp);
- JSONObject json = (JSONObject) JSON.parse(resp);
- }
- }
|