Browse Source

add
小程序

18339543638 7 months ago
parent
commit
017036e582

+ 53 - 0
tr-modules/tr-module-smartFollowUp/src/main/java/cn/tr/module/smart/wx/controller/WxAppletUserController.java

@@ -0,0 +1,53 @@
+package cn.tr.module.smart.wx.controller;
+
+import cn.binarywang.wx.miniapp.api.WxMaService;
+import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
+import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
+import cn.binarywang.wx.miniapp.util.WxMaConfigHolder;
+import cn.tr.core.exception.ServiceException;
+import cn.tr.core.exception.TRExcCode;
+import cn.tr.core.pojo.CommonResult;
+import cn.tr.module.smart.wx.dto.WxAppletEncodeInfoDTO;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * 微信小程序用户接口
+ *
+ * @author <a href="https://github.com/binarywang">Binary Wang</a>
+ */
+@RestController
+@AllArgsConstructor
+@Slf4j
+@RequestMapping("/wx/user/{appid}")
+@Api(tags = "微信小程序用户")
+public class WxAppletUserController {
+    private final WxMaService wxMaService;
+
+    /**
+     * <pre>
+     * 获取用户信息接口
+     * </pre>
+     */
+    @PostMapping("/info")
+    @ApiOperation("获取微信用户信息")
+    public CommonResult<WxMaUserInfo> info(@PathVariable String appid, @RequestBody WxAppletEncodeInfoDTO source) {
+        if (!wxMaService.switchover(appid)) {
+            throw new IllegalArgumentException(String.format("未找到对应appid=[%s]的配置,请核实!", appid));
+        }
+
+        // 用户信息校验
+        if (!wxMaService.getUserService().checkUserInfo(source.getSessionKey(), source.getRawData(), source.getSignature())) {
+            WxMaConfigHolder.remove();//清理ThreadLocal
+            throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"获取用户信息失败");
+        }
+
+        // 解密用户信息
+        WxMaUserInfo userInfo = wxMaService.getUserService().getUserInfo(source.getSessionKey(), source.getEncryptedData(), source.getIv());
+        WxMaConfigHolder.remove();//清理ThreadLocal
+        return CommonResult.success(userInfo);
+    }
+}

+ 0 - 77
tr-modules/tr-module-smartFollowUp/src/main/java/cn/tr/module/smart/wx/controller/WxMaUserController.java

@@ -1,77 +0,0 @@
-package cn.tr.module.smart.wx.controller;
-
-import cn.binarywang.wx.miniapp.api.WxMaService;
-import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
-import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
-import cn.binarywang.wx.miniapp.util.WxMaConfigHolder;
-import cn.tr.core.exception.ServiceException;
-import cn.tr.core.exception.TRExcCode;
-import cn.tr.core.pojo.CommonResult;
-import lombok.AllArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * 微信小程序用户接口
- *
- * @author <a href="https://github.com/binarywang">Binary Wang</a>
- */
-@RestController
-@AllArgsConstructor
-@Slf4j
-@RequestMapping("/wx/user/{appid}")
-public class WxMaUserController {
-    private final WxMaService wxMaService;
-
-    /**
-     * <pre>
-     * 获取用户信息接口
-     * </pre>
-     */
-    @GetMapping("/info")
-    public CommonResult<WxMaUserInfo> info(@PathVariable String appid, String sessionKey,
-                             String signature, String rawData, String encryptedData, String iv) {
-        if (!wxMaService.switchover(appid)) {
-            throw new IllegalArgumentException(String.format("未找到对应appid=[%s]的配置,请核实!", appid));
-        }
-
-        // 用户信息校验
-        if (!wxMaService.getUserService().checkUserInfo(sessionKey, rawData, signature)) {
-            WxMaConfigHolder.remove();//清理ThreadLocal
-            throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"获取用户信息失败");
-        }
-
-        // 解密用户信息
-        WxMaUserInfo userInfo = wxMaService.getUserService().getUserInfo(sessionKey, encryptedData, iv);
-        WxMaConfigHolder.remove();//清理ThreadLocal
-        return CommonResult.success(userInfo);
-    }
-
-    /**
-     * <pre>
-     * 获取用户绑定手机号信息
-     * </pre>
-     */
-    @GetMapping("/phone")
-    public CommonResult<WxMaPhoneNumberInfo> phone(@PathVariable String appid, String sessionKey, String signature,
-                        String rawData, String encryptedData, String iv) {
-        if (!wxMaService.switchover(appid)) {
-            throw new IllegalArgumentException(String.format("未找到对应appid=[%s]的配置,请核实!", appid));
-        }
-
-        // 用户信息校验
-        if (!wxMaService.getUserService().checkUserInfo(sessionKey, rawData, signature)) {
-            WxMaConfigHolder.remove();//清理ThreadLocal
-            throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"获取用户手机号失败");
-        }
-
-        // 解密
-        WxMaPhoneNumberInfo phoneNoInfo = wxMaService.getUserService().getPhoneNoInfo(sessionKey, encryptedData, iv);
-        WxMaConfigHolder.remove();//清理ThreadLocal
-        return CommonResult.success(phoneNoInfo);
-    }
-
-}

+ 2 - 0
tr-modules/tr-module-smartFollowUp/src/main/java/cn/tr/module/smart/wx/controller/WxPortalController.java

@@ -5,6 +5,7 @@ import cn.binarywang.wx.miniapp.bean.WxMaMessage;
 import cn.binarywang.wx.miniapp.constant.WxMaConstants;
 import cn.binarywang.wx.miniapp.message.WxMaMessageRouter;
 import cn.binarywang.wx.miniapp.util.WxMaConfigHolder;
+import io.swagger.annotations.Api;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
@@ -19,6 +20,7 @@ import java.util.Objects;
 @AllArgsConstructor
 @RequestMapping("/wx/portal/{appid}")
 @Slf4j
+@Api(hidden = true)
 public class WxPortalController {
     private final WxMaService wxMaService;
     private final WxMaMessageRouter wxMaMessageRouter;

+ 20 - 0
tr-modules/tr-module-smartFollowUp/src/main/java/cn/tr/module/smart/wx/dto/WxAppletEncodeInfoDTO.java

@@ -0,0 +1,20 @@
+package cn.tr.module.smart.wx.dto;
+
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+
+/**
+ * @ClassName : WxUserInfoDTO
+ * @Description :
+ * @Author : LF
+ * @Date: 2025年05月20日
+ */
+@Data
+@ApiModel("微信小程序加密")
+public class WxAppletEncodeInfoDTO {
+    private String sessionKey;
+    private String signature;
+    private String rawData;
+    private String encryptedData;
+    private String iv;
+}