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