Quellcode durchsuchen

Merge branch 'usky-zyj' of uskycloud/usky-modules into server-165

James vor 1 Jahr
Ursprung
Commit
7447d19749

+ 3 - 3
service-iot/service-iot-biz/src/main/java/com/usky/iot/constant/constant.java

@@ -12,15 +12,15 @@ public class constant {
     // 回调地址,获取open_id
     public static final String WE_CHAT_CALL_BACK_DOMAIN_URL = "http://localhost:9887/weChat/getWeChatOpenId";
     // 回调域名
-    public static final String call_back_domain = "aiot.usky.cn";
+    public static final String call_back_domain = "manager.usky.cn";
     // 微信公众号的token获取地址
     public static final String WE_CHAT_ACCESS_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s";
     // 微信公众号消息推送地址
     public static final String WE_CHAT_REQUEST_URL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=%s";
     // 微信公众号推送消息模板id
-    public static final String WE_CHAT_TEMPLATE_ID = "**********";
+    public static final String WE_CHAT_TEMPLATE_ID = "jbgHt8W8RNpRN2KZwvAMty40iiZU2sa9dqnFXOsCvqw";
     // 微信公众号的消息回调地址(这儿可根据业务需求自定义动作,可选)
-    public static final String WE_CHAT_CUSTOMER_CALL_URL = "https://***.***.***.***/***/***/accountInfo?keyword=%s";
+    public static final String WE_CHAT_CUSTOMER_CALL_URL = "http://manager.usky.cn/mobile/#/pages/infoDetails?id=%s";
     // 微信公众号的主题颜色
     public static final String WE_CHAT_TOP_COLOR = "#A349A4";
     // 微信公众号微信用户授权地址

+ 21 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/controller/web/MceMbuserController.java

@@ -0,0 +1,21 @@
+package com.usky.iot.controller.web;
+
+
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import org.springframework.stereotype.Controller;
+
+/**
+ * <p>
+ * 消息中心_移动端注册表 前端控制器
+ * </p>
+ *
+ * @author han
+ * @since 2024-04-26
+ */
+@Controller
+@RequestMapping("/mceMbuser")
+public class MceMbuserController {
+
+}
+

+ 86 - 9
service-iot/service-iot-biz/src/main/java/com/usky/iot/controller/web/WeChatController.java

@@ -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;
+    }
+
 }
 
 

+ 68 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/domain/MceMbuser.java

@@ -0,0 +1,68 @@
+package com.usky.iot.domain;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import java.time.LocalDateTime;
+import java.io.Serializable;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * <p>
+ * 消息中心_移动端注册表
+ * </p>
+ *
+ * @author han
+ * @since 2024-04-26
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class MceMbuser implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Long id;
+
+    /**
+     * 电话号码
+     */
+    private String phone;
+
+    /**
+     * 微信用户id
+     */
+    private String openid;
+
+    /**
+     * 用户ID
+     */
+    private Long userId;
+
+    /**
+     * 应用ID
+     */
+    private String cids;
+
+    /**
+     * 创建人
+     */
+    private String createBy;
+
+    /**
+     * 创建时间
+     */
+    private LocalDateTime createTime;
+
+    /**
+     * 更新人
+     */
+    private String updateBy;
+
+    /**
+     * 更新时间
+     */
+    private LocalDateTime updateTime;
+
+
+}

+ 16 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/mapper/MceMbuserMapper.java

@@ -0,0 +1,16 @@
+package com.usky.iot.mapper;
+
+import com.usky.iot.domain.MceMbuser;
+import com.usky.common.mybatis.core.CrudMapper;
+
+/**
+ * <p>
+ * 消息中心_移动端注册表 Mapper 接口
+ * </p>
+ *
+ * @author han
+ * @since 2024-04-26
+ */
+public interface MceMbuserMapper extends CrudMapper<MceMbuser> {
+
+}

+ 16 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/MceMbuserService.java

@@ -0,0 +1,16 @@
+package com.usky.iot.service;
+
+import com.usky.iot.domain.MceMbuser;
+import com.usky.common.mybatis.core.CrudService;
+
+/**
+ * <p>
+ * 消息中心_移动端注册表 服务类
+ * </p>
+ *
+ * @author han
+ * @since 2024-04-26
+ */
+public interface MceMbuserService extends CrudService<MceMbuser> {
+
+}

+ 3 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/DmpDeviceTypeServiceImpl.java

@@ -51,6 +51,9 @@ public class DmpDeviceTypeServiceImpl extends AbstractCrudService<DmpDeviceTypeM
     @Transactional(rollbackFor = Exception.class)
     @Override
     public void edit(DmpDeviceType dmpDeviceType) {
+        if (checkNameUnique(dmpDeviceType)) {
+            throw new BusinessException("修改设备类型'" + dmpDeviceType.getTypeName() + "'失败,该设备类型已经存在");
+        }
         dmpDeviceType.setUpdatedBy(SecurityUtils.getUsername());
         dmpDeviceType.setUpdatedTime(LocalDateTime.now());
         this.updateById(dmpDeviceType);

+ 20 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/MceMbuserServiceImpl.java

@@ -0,0 +1,20 @@
+package com.usky.iot.service.impl;
+
+import com.usky.iot.domain.MceMbuser;
+import com.usky.iot.mapper.MceMbuserMapper;
+import com.usky.iot.service.MceMbuserService;
+import com.usky.common.mybatis.core.AbstractCrudService;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ * 消息中心_移动端注册表 服务实现类
+ * </p>
+ *
+ * @author han
+ * @since 2024-04-26
+ */
+@Service
+public class MceMbuserServiceImpl extends AbstractCrudService<MceMbuserMapper, MceMbuser> implements MceMbuserService {
+
+}

+ 31 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/vo/SendWeChatMessageRequestVO.java

@@ -0,0 +1,31 @@
+package com.usky.iot.service.vo;
+
+import lombok.Data;
+
+@Data
+public class SendWeChatMessageRequestVO {
+    /**
+     * 消息类型
+     */
+    String infoType;
+
+    /**
+     * 消息标题
+     */
+    String infoTitle;
+
+    /**
+     * 消息内容
+     */
+    String infoContent;
+
+    /**
+     * 消息Id
+     */
+    Integer infoId;
+
+    /**
+     * openId
+     */
+    String openId;
+}

+ 48 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/vo/TemplateMsgEntityVO.java

@@ -0,0 +1,48 @@
+package com.usky.iot.service.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class TemplateMsgEntityVO implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 标题
+     */
+    private String tTitle;
+    /**
+     * 第一行
+     */
+    private String tKeyword1;
+    /**
+     * 第二行
+     */
+    private String tKeyword2;
+    /**
+     * 第三行
+     */
+    private String tKeyword3;
+    /**
+     * 第四行
+     */
+    private String tKeyword4;
+    /**
+     * 备注
+     */
+    private String tRemark;
+    /**
+     * 跳转连接
+     */
+    private String tUrl;
+    /**
+     * 模板Id
+     */
+    private String templateId;
+    /**
+     * 状态
+     */
+    private int tStatus;
+
+}

+ 18 - 0
service-iot/service-iot-biz/src/main/resources/mapper/iot/MceMbuserMapper.xml

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.usky.iot.mapper.MceMbuserMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.usky.iot.domain.MceMbuser">
+        <id column="id" property="id" />
+        <result column="phone" property="phone" />
+        <result column="openid" property="openid" />
+        <result column="user_id" property="userId" />
+        <result column="cids" property="cids" />
+        <result column="create_by" property="createBy" />
+        <result column="create_time" property="createTime" />
+        <result column="update_by" property="updateBy" />
+        <result column="update_time" property="updateTime" />
+    </resultMap>
+
+</mapper>