|
@@ -1,5 +1,8 @@
|
|
|
package com.usky.iot.controller.web;
|
|
|
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
@@ -13,11 +16,13 @@ import com.usky.iot.domain.SysWxOpuser;
|
|
|
import com.usky.iot.service.SysWxOpuserService;
|
|
|
import com.usky.iot.service.vo.SendWeChatMessageRequestVO;
|
|
|
import com.usky.iot.service.vo.SignUpRequestVO;
|
|
|
+import com.usky.iot.service.vo.TemplateMsgEntityVO;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import ma.glasnost.orika.impl.util.StringUtil;
|
|
|
import me.chanjar.weixin.common.api.WxConsts;
|
|
|
import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
|
|
|
import me.chanjar.weixin.mp.api.WxMpService;
|
|
|
+import me.chanjar.weixin.mp.enums.WxMpApiUrl;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.boot.ExitCodeEvent;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
@@ -307,6 +312,52 @@ public class WeChatController {
|
|
|
//
|
|
|
// }
|
|
|
|
|
|
+ /**
|
|
|
+ * 微信消息提醒
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PostMapping("sendWeChatMessage")
|
|
|
+ public JSONObject sendWeChatMessage(@RequestBody SendWeChatMessageRequestVO requestVO){
|
|
|
+
|
|
|
+ String infoType = requestVO.getInfoType();
|
|
|
+ String infoTitle = requestVO.getInfoTitle();
|
|
|
+ String infoContent = requestVO.getInfoContent();
|
|
|
+ Integer infoId = requestVO.getInfoId();
|
|
|
+ String openId = requestVO.getOpenId();
|
|
|
+ String token = this.getWeChatAccessToken();
|
|
|
+
|
|
|
+ TemplateMsgEntityVO messageVo=new TemplateMsgEntityVO();
|
|
|
+ messageVo.setTTitle(infoTitle);
|
|
|
+ messageVo.setTKeyword1("测试1");
|
|
|
+ messageVo.setTKeyword2("测试2");
|
|
|
+ messageVo.setTKeyword3("测试3");
|
|
|
+ messageVo.setTKeyword4("测试4");
|
|
|
+ messageVo.setTRemark(infoContent);
|
|
|
+ messageVo.setTUrl(String.format(constant.WE_CHAT_CUSTOMER_CALL_URL,infoId));
|
|
|
+ messageVo.setTemplateId(constant.WE_CHAT_TEMPLATE_ID);
|
|
|
+
|
|
|
+ String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + token;
|
|
|
+ Map<String,Object> content=new HashMap<>();
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+ data.put("first",new JSONObject().put("value",messageVo.getTTitle()));
|
|
|
+ data.put("keyword1",new JSONObject().put("value",messageVo.getTKeyword1()));
|
|
|
+ data.put("keyword2",new JSONObject().put("value",messageVo.getTKeyword2()));
|
|
|
+ data.put("keyword3",new JSONObject().put("value",messageVo.getTKeyword3()));
|
|
|
+ data.put("keyword4",new JSONObject().put("value",messageVo.getTKeyword4()));
|
|
|
+ data.put("remark",new JSONObject().put("value",messageVo.getTRemark()));
|
|
|
+
|
|
|
+ content.put("touser",openId);
|
|
|
+ content.put("url",messageVo.getTUrl());
|
|
|
+ content.put("template_id",messageVo.getTemplateId());
|
|
|
+ content.put("data",data);
|
|
|
+ String resp = HttpUtil.post(requestUrl, JSONUtil.parseObj(content).toString());
|
|
|
+ System.out.println(content.toString());
|
|
|
+ System.out.println(JSONUtil.parseObj(content));
|
|
|
+ JSONObject result = JSONObject.parseObject(resp);
|
|
|
+ System.out.println("发送消息:" + resp);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|