From afa0dbb4f54e7244835dd67ec33c3e545f122f71 Mon Sep 17 00:00:00 2001
From: mitao <2763622819@qq.com>
Date: 星期五, 17 一月 2025 16:40:43 +0800
Subject: [PATCH] bug修改

---
 ruoyi-auth/src/main/java/com/ruoyi/auth/controller/QwH5Controller.java |   61 +++++++++++++++++++++++++++---
 1 files changed, 54 insertions(+), 7 deletions(-)

diff --git a/ruoyi-auth/src/main/java/com/ruoyi/auth/controller/QwH5Controller.java b/ruoyi-auth/src/main/java/com/ruoyi/auth/controller/QwH5Controller.java
index 9f6ce3e..dcd1562 100644
--- a/ruoyi-auth/src/main/java/com/ruoyi/auth/controller/QwH5Controller.java
+++ b/ruoyi-auth/src/main/java/com/ruoyi/auth/controller/QwH5Controller.java
@@ -4,17 +4,16 @@
 import com.ruoyi.auth.service.QywxInnerService;
 import com.ruoyi.auth.service.SysLoginService;
 import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.core.exception.ServiceException;
+import com.ruoyi.common.core.utils.StringUtils;
 import com.ruoyi.common.security.service.TokenService;
-import com.ruoyi.system.api.model.OauthUrlVo;
-import com.ruoyi.system.api.model.OauthUserVo;
-import com.ruoyi.system.api.model.QwH5LoginVo;
-import com.ruoyi.system.api.model.QwUserDetailDto;
+import com.ruoyi.system.api.model.*;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
@@ -38,6 +37,12 @@
     @Autowired
     private TokenService tokenService;
 
+    @Value("${h5.redirectMerchantUriBase}")
+    private String redirectMerchantUriBase;
+
+    @Value("${h5.redirectEmployeeUriBase}")
+    private String redirectEmployeeUriBase;
+
 
     /**
      * 构造网页授权链接
@@ -49,21 +54,63 @@
     @ApiOperation("构造网页授权链接")
     public R<OauthUrlVo> oauthUrl(@ApiParam(value = "授权重定向地址", required = true) @RequestParam("redirectUri") String redirectUri) throws UnsupportedEncodingException {
         // 普通应用
+        redirectUri = redirectMerchantUriBase + redirectUri;
+        String oauthRedirectUrl =  URLEncoder.encode(redirectUri,"utf-8");
+        String oauthUrl = qywxInnerService.getOauthUrl(oauthRedirectUrl);
+        return R.ok(new OauthUrlVo(oauthUrl));
+    }
+
+    @GetMapping({"/h5/oauthStaffUrl"})
+    @ApiOperation("构造网页授权链接")
+    public R<OauthUrlVo> oauthStaffUrl(@ApiParam(value = "授权重定向地址", required = true) @RequestParam("redirectUri") String redirectUri) throws UnsupportedEncodingException {
+        // 普通应用
+        redirectUri = redirectEmployeeUriBase + redirectUri;
         String oauthRedirectUrl =  URLEncoder.encode(redirectUri,"utf-8");
         String oauthUrl = qywxInnerService.getOauthUrl(oauthRedirectUrl);
         return R.ok(new OauthUrlVo(oauthUrl));
     }
 
 
+    @GetMapping("/h5/oauthStaff")
+    @ApiOperation("通过code获取员工端用户登录")
+    public R<OauthUserVo> oauthStaff(@ApiParam(value = "成员授权获取到的code", required = true) @RequestParam("code") String code) throws IOException {
+        // 通过code获取访问用户敏感信息
+        JSONObject result = qywxInnerService.getOauthUser(code);
+        QwUserDetailDto qwUserDetail = JSONObject.parseObject(result.toJSONString(), QwUserDetailDto.class);
+        //QwUserDetailDto qwUserDetail = new QwUserDetailDto();
+        //qwUserDetail.setMobile("17780704874");
+        if(StringUtils.isBlank(qwUserDetail.getMobile())){
+            throw new ServiceException("企业微信未授权手机号,无法登录");
+        }
+        // 1、查数据库获取人员
+        QwH5LoginVo qwH5LoginVo = sysLoginService.qwH5StaffLogin(qwUserDetail);
+        // 2、生成Token
+       return R.ok(tokenService.createQwH5Token(qwH5LoginVo));
+    }
+
     @GetMapping("/h5/oauthUser")
-    @ApiOperation("通过code获取访问用户登录")
+    @ApiOperation("通过code获取商户端用户登录")
     public R<OauthUserVo> oauthUser(@ApiParam(value = "成员授权获取到的code", required = true) @RequestParam("code") String code) throws IOException {
         // 通过code获取访问用户敏感信息
         JSONObject result = qywxInnerService.getOauthUser(code);
         QwUserDetailDto qwUserDetail = JSONObject.parseObject(result.toJSONString(), QwUserDetailDto.class);
+        if(StringUtils.isBlank(qwUserDetail.getMobile())){
+            throw new ServiceException("企业微信未授权手机号,无法登录");
+        }
+        //QwUserDetailDto qwUserDetail = new QwUserDetailDto();
+        //qwUserDetail.setMobile("13882237106");
         // 1、查数据库获取人员
         QwH5LoginVo qwH5LoginVo = sysLoginService.qwH5Login(qwUserDetail);
         // 2、生成Token
-       return R.ok(tokenService.createQwH5Token(qwH5LoginVo));
+        return R.ok(tokenService.createQwH5Token(qwH5LoginVo));
     }
+
+    @GetMapping("/h5/getAgentConfig")
+    @ApiOperation("通过code获取访问用户登录")
+    public R<AgentConfigVo> getAgentConfig(@ApiParam(value = "url", required = true) String url, @ApiParam(value = "type", required = false) String type) throws IOException {
+        AgentConfigVo agentConfigVo = qywxInnerService.getAgentConfig(url, type);
+        return R.ok(agentConfigVo);
+    }
+
+
 }

--
Gitblit v1.7.1