|
@@ -1,20 +1,28 @@
|
|
|
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;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.usky.common.core.bean.ApiResult;
|
|
|
import com.usky.common.core.exception.BusinessException;
|
|
|
+import com.usky.common.core.util.HttpUtils;
|
|
|
import com.usky.common.redis.core.RedisHelper;
|
|
|
import com.usky.iot.constant.constant;
|
|
|
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.*;
|
|
@@ -35,6 +43,7 @@ import java.util.Objects;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("/weChat")
|
|
|
+@Slf4j
|
|
|
public class WeChatController {
|
|
|
@Autowired
|
|
|
private WxMpService wxMpService;
|
|
@@ -59,7 +68,7 @@ public class WeChatController {
|
|
|
if(userAgent.contains("MicroMessenger")){ //wx
|
|
|
request.getSession().setAttribute("type","wx");
|
|
|
if(StringUtils.isBlank(code)){
|
|
|
- String url = URLDecoder.decode(http+constant.call_back_domain+request.getRequestURI());
|
|
|
+ String url = URLDecoder.decode(http+constant.call_back_domain+"/mobile/#/pages"+request.getRequestURI());
|
|
|
String sendUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+constant.WE_CHAT_APP_ID+"&redirect_uri="+url+"&response_type=code&scope=snsapi_base&state=abc123#wechat_redirect";
|
|
|
try{
|
|
|
System.out.println("sendUrl: "+sendUrl);
|
|
@@ -84,8 +93,8 @@ public class WeChatController {
|
|
|
if(one != null){
|
|
|
request.getSession().setAttribute("phone",one.getPhone());
|
|
|
}
|
|
|
-//
|
|
|
-// response.sendRedirect("https://qhome.usky.cn/work/index.html#/pages/login/login?flag=true");
|
|
|
+
|
|
|
+ response.sendRedirect("https://manager.usky.cn/mobile/#/pages/login?flag=true");
|
|
|
} catch (Exception e) {
|
|
|
throw new BusinessException(e.getMessage());
|
|
|
}
|
|
@@ -118,7 +127,7 @@ public class WeChatController {
|
|
|
.eq(SysWxOpuser::getType,"app");
|
|
|
SysWxOpuser one = sysWxOpuserService.getOne(queryWrapper);
|
|
|
if(one != null){
|
|
|
- String sendUrl = "https://aiot.usky.cn/work/#/pages/index?op="+one.getOpenid();
|
|
|
+ String sendUrl = "https://manager.usky.cn/mobile/#/pages/index?op="+one.getOpenid();
|
|
|
try{
|
|
|
System.out.println("sendUrl: "+sendUrl);
|
|
|
response.sendRedirect(sendUrl);
|
|
@@ -130,7 +139,7 @@ public class WeChatController {
|
|
|
}else{
|
|
|
if(!userAgent.contains("MicroMessenger")){
|
|
|
try{
|
|
|
- response.sendRedirect("https://aiot.usky.cn/work/#/pages/login");
|
|
|
+ response.sendRedirect("https://manager.usky.cn/mobile/#/pages/login");
|
|
|
}catch (IOException e){
|
|
|
throw new BusinessException(e.getMessage());
|
|
|
}
|
|
@@ -163,13 +172,13 @@ public class WeChatController {
|
|
|
if(one != null){
|
|
|
request.getSession().setAttribute("phone",one.getPhone());
|
|
|
|
|
|
- String sendUrl = "https://aiot.usky.cn/work/#/pages/index?op="+one.getOpenid();
|
|
|
+ String sendUrl = "https://manager.usky.cn/mobile/#/pages/index?op="+one.getOpenid();
|
|
|
response.sendRedirect(sendUrl);
|
|
|
}else{
|
|
|
request.getSession().removeAttribute("openid");
|
|
|
request.getSession().removeAttribute("phone");
|
|
|
|
|
|
- response.sendRedirect("https://aiot.usky.cn/work/#/pages/login");
|
|
|
+ response.sendRedirect("https://manager.usky.cn/mobile/#/pages/login");
|
|
|
}
|
|
|
|
|
|
|
|
@@ -186,13 +195,13 @@ public class WeChatController {
|
|
|
SysWxOpuser one = sysWxOpuserService.getOne(queryWrapper);
|
|
|
if(one != null){
|
|
|
request.getSession().setAttribute("phone",one.getPhone());
|
|
|
- String sendUrl = "https://aiot.usky.cn/work/#/pages/index?op="+one.getOpenid();
|
|
|
+ String sendUrl = "https://manager.usky.cn/mobile/#/pages/index?op="+one.getOpenid();
|
|
|
response.sendRedirect(sendUrl);
|
|
|
}else{
|
|
|
request.getSession().removeAttribute("openid");
|
|
|
request.getSession().removeAttribute("phone");
|
|
|
|
|
|
- response.sendRedirect("https://aiot.usky.cn/work/#/pages/login");
|
|
|
+ response.sendRedirect("https://manager.usky.cn/mobile/#/pages/login");
|
|
|
}
|
|
|
}catch (IOException e){
|
|
|
throw new BusinessException(e.getMessage());
|
|
@@ -281,6 +290,74 @@ public class WeChatController {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+// /**
|
|
|
+// * 微信消息提醒
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// @PostMapping("sendWeChatMessage")
|
|
|
+// public Map<String,Object> sendWeChatMessage(@RequestBody SendWeChatMessageRequestVO requestVO){
|
|
|
+// String infoType = requestVO.getInfoType();
|
|
|
+// String infoTitle = requestVO.getInfoTitle();
|
|
|
+// String infoContent = requestVO.getInfoContent();
|
|
|
+// Map<String,Object> map = new HashMap<>();
|
|
|
+//
|
|
|
+// String s = null;
|
|
|
+// try {
|
|
|
+// s = HttpUtils.postForm(URL, body, null);
|
|
|
+// }catch (Exception e){
|
|
|
+// log.info("发送微信推送报警出错"+e);
|
|
|
+// }
|
|
|
+// return map;
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 微信消息提醒
|
|
|
+ * @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;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|