Explorar o código

feat:“优化MQTT重连机制,添加汇付获取微信openid接口"

soobin hai 8 meses
pai
achega
674e3fb2ac

+ 1 - 0
src/main/java/com/szwl/config/MqttConfig.java

@@ -111,6 +111,7 @@ public class MqttConfig {
             options.setCleanSession(false);
             options.setKeepAliveInterval(60);
             options.setAutomaticReconnect(true);
+            options.setConnectionTimeout(15);
             // 建立连接
             mqttClient.connect(options);
             // 订阅主题

+ 7 - 2
src/main/java/com/szwl/constant/HuifuConstant.java

@@ -53,9 +53,14 @@ public class HuifuConstant {
     public static final String SC_WX_SUB_APP_ID = "wxd9c7c138a055ee66";
 
     /**
-     * 申泽商户公众账号ID
+     * 申泽商户公众账号密钥
+     */
+    public static final String SZ_WX_APP_SECRET = "e2854aa99f8279f33b4f065b2ffb75b1";
+
+    /**
+     * 七云商户公众账号密钥
      */
-    public static final String WX_APP_SECRET = "e2854aa99f8279f33b4f065b2ffb75b1";
+    public static final String SC_WX_APP_SECRET = "f131c85c06a80e466bd7e366cd477b93";
 
     /**
      * 申泽分账商户号

+ 2 - 2
src/main/java/com/szwl/controller/ScheduledService.java

@@ -120,7 +120,7 @@ public class ScheduledService {
             Calendar calendar = Calendar.getInstance();
             int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
             // 如果不是周日 1,周六 7
-            if (dayOfWeek != Calendar.SATURDAY && dayOfWeek != Calendar.SUNDAY) {
+            if (dayOfWeek != Calendar.SUNDAY) {
                 tDepartmentService.onTime();
             }
         }
@@ -134,7 +134,7 @@ public class ScheduledService {
             Calendar calendar = Calendar.getInstance();
             int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
             // 如果不是周日 1,周六 7
-            if (dayOfWeek != Calendar.SATURDAY && dayOfWeek != Calendar.SUNDAY) {
+            if (dayOfWeek != Calendar.SUNDAY) {
                 tDepartmentService.onTime2();
             }
         }

+ 32 - 13
src/main/java/com/szwl/controller/TAdminController.java

@@ -71,10 +71,10 @@ public class TAdminController {
 
     @Autowired
     TWechatService wechatService;
-    
+
     @Autowired
     TAreaService areaService;
-    
+
     @Autowired
     CitiesService citiesService;
 
@@ -146,14 +146,9 @@ public class TAdminController {
     @Transactional
     @Audit(type = AuditEnum.INSERT, content = "#loginUser.name + '添加账号'")
     public ResponseModel<?> addLoginUser(@RequestBody @Valid AddLoginUserParam param) {
-        if (StringUtils.isEmpty(param.getEquipmentIds())) {
-            return R.fail(ResponseCodesEnum.A0001, "机器不能为空");
-        }
         if (param.getRoleList().size() < 1) {
             return R.fail(ResponseCodesEnum.A0001, "角色不能为空");
         }
-        //获取当前操作人员
-//        UserDetailBO loginUser = tokenManager.getLoginUserDetails();
         // 保存用户实体
         Date now = new Date();
         Long parentId = param.getAdminId();
@@ -195,8 +190,8 @@ public class TAdminController {
         }
 
         // 管理的机器 需要再建立一个关系表 type区分全部还是部分
-        String equipmentIds = param.getEquipmentIds();
-        if (StringUtils.isNotEmpty(equipmentIds)) {
+        if (StringUtils.isNotEmpty(param.getEquipmentIds())) {
+            String equipmentIds = param.getEquipmentIds();
             if (equipmentIds.equals("all")) {
                 //管理全部机器
                 TAdminEquipment tAdminEquipment = new TAdminEquipment();
@@ -444,7 +439,7 @@ public class TAdminController {
             return R.fail(ResponseCodesEnum.A0001, "是否国内外为空!");
         }
         String relationAdminId = "";
-        if(StringUtils.isNotEmpty(registerParam.getInviteCode())) {
+        if (StringUtils.isNotEmpty(registerParam.getInviteCode())) {
             // 验证邀请码
             relationAdminId = String.valueOf(AdminUtils.decrypt(false, registerParam.getInviteCode()));
             TAdmin admin = tAdminService.getById(relationAdminId);
@@ -475,7 +470,7 @@ public class TAdminController {
                 return R.fail(ResponseCodesEnum.R0003);
             }
         }
-        
+
         // 增加地区
         Long areaId = null;
         if (StringUtils.isNotEmpty(registerParam.getCities())) {
@@ -568,7 +563,7 @@ public class TAdminController {
                 admin.setPromoCodeOpen("0");
             }
             // 邀请码,即上级账号
-            if(StringUtils.isNotEmpty(relationAdminId)) {
+            if (StringUtils.isNotEmpty(relationAdminId)) {
                 admin.setRelationAdminId(relationAdminId);
             }
             admin.setCompanyType(registerParam.getCompanyType());
@@ -1267,9 +1262,33 @@ public class TAdminController {
             String cityCode = cities.getCode();
             Countries countries = countriesService.getById(countryId);
             String countryCode = countries.getCode();
-            areaName = cityCode + "/"+ countryCode;
+            areaName = cityCode + "/" + countryCode;
         }
         return R.ok(areaName);
     }
+
+    @ApiOperation("获取用户信息")
+    @GetMapping("/changeArea")
+    public ResponseModel<?> changeArea() {
+        LambdaQueryWrapper<TAdmin> query = Wrappers.lambdaQuery();
+        query.eq(TAdmin::getIfForeign, "0");
+        List<TAdmin> list = tAdminService.list(query);
+        for (TAdmin admin : list) {
+            Long areaId = admin.getAreaId();
+            if (areaId != null) {
+                TArea area = areaService.getById(areaId);
+                if (area != null) {
+                    String treePath = area.getTreePath();
+                    String[] split = treePath.split(",");
+                    if (split.length > 2) {
+                        admin.setAreaId(Long.valueOf(split[2]));
+//                        System.out.println(split[2]);
+                        tAdminService.updateById(admin);
+                    }
+                }
+            }
+        }
+        return R.ok();
+    }
 }
 

+ 40 - 4
src/main/java/com/szwl/controller/TWechatController.java

@@ -2,9 +2,10 @@ package com.szwl.controller;
 
 
 import cn.com.crbank.ommo.exception.MyException;
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
 import com.szwl.constant.ConfigConsts;
+import com.szwl.constant.HuifuConstant;
 import com.szwl.constant.ResponseCodesEnum;
 import com.szwl.model.bo.R;
 import com.szwl.model.bo.ResponseModel;
@@ -18,17 +19,14 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
-
 import org.json.JSONObject;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
-
 import java.net.URLEncoder;
 import java.util.*;
 
@@ -314,5 +312,43 @@ public class TWechatController {
         return R.ok();
     }
 
+    @ApiOperation(value = "汇付微信获取openid")
+    @GetMapping("/getWeChatOpenid")
+    public ResponseModel<?> getWeChatOpenid(String authCode, String companyType) {
+        String openid = null;
+        if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
+            // 七云获取openid
+            try {
+                String openUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?" +
+                        "appid=" + HuifuConstant.SC_WX_SUB_APP_ID +
+                        "&secret=" + HuifuConstant.SC_WX_APP_SECRET +
+                        "&code=" + authCode +
+                        "&grant_type=authorization_code";
+                log.info("获取openID:{}", openUrl);
+                org.json.JSONObject jsonObject = HttpClientUtils.get(openUrl);
+                log.info("获取openID结果:{}", jsonObject);
+                openid = jsonObject.getString("openid");
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        } else {
+            // 申泽获取openid
+            try {
+                String openUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?" +
+                        "appid=" + HuifuConstant.SZ_WX_SUB_APP_ID +
+                        "&secret=" + HuifuConstant.SZ_WX_APP_SECRET +
+                        "&code=" + authCode +
+                        "&grant_type=authorization_code";
+                log.info("获取openID:{}", openUrl);
+                org.json.JSONObject jsonObject = HttpClientUtils.get(openUrl);
+                log.info("获取openID结果:{}", jsonObject);
+                openid = jsonObject.getString("openid");
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+        return R.ok(openid);
+    }
+
 }
 

+ 0 - 10
src/main/java/com/szwl/handle/HeartMessageHandler.java

@@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.szwl.model.entity.TEquipment;
 import com.szwl.model.entity.TEquipmentDesc;
 import com.szwl.model.jsonParm.HeartParam;
-import com.szwl.service.MqttMsgService;
 import com.szwl.service.TEquipmentDescService;
 import com.szwl.service.TEquipmentService;
 import lombok.extern.slf4j.Slf4j;
@@ -21,9 +20,6 @@ import org.springframework.stereotype.Component;
 public class HeartMessageHandler implements MqttMessageHandler{
 
     @Autowired
-    private MqttMsgService mqttMsgService;
-
-    @Autowired
     private TEquipmentService equipmentService;
 
     @Autowired
@@ -33,12 +29,6 @@ public class HeartMessageHandler implements MqttMessageHandler{
     public void handle(String topic, String payload) {
         HeartParam heartParam = JSON.parseObject(payload, HeartParam.class);
         String clientId = heartParam.getClientId();
-//        MqttMsg mqttMsg = new MqttMsg();
-//        mqttMsg.setCreateDate(new Date());
-//        mqttMsg.setClientId(clientId);
-//        mqttMsg.setTopic(topic);
-//        mqttMsg.setMessage(payload);
-//        mqttMsgService.save(mqttMsg);
 
         // 查询设备
         LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();