Pu Zhibing
2025-05-08 afdd96be3f266ee04e7c4a427eb010708e1cace3
ruoyi-auth/src/main/java/com/ruoyi/auth/controller/QwH5Controller.java
@@ -37,8 +37,11 @@
    @Autowired
    private TokenService tokenService;
    @Value("${h5.redirectUriBase}")
    private String redirectUriBase;
    @Value("${h5.redirectMerchantUriBase}")
    private String redirectMerchantUriBase;
    @Value("${h5.redirectEmployeeUriBase}")
    private String redirectEmployeeUriBase;
    /**
@@ -51,7 +54,17 @@
    @ApiOperation("构造网页授权链接")
    public R<OauthUrlVo> oauthUrl(@ApiParam(value = "授权重定向地址", required = true) @RequestParam("redirectUri") String redirectUri) throws UnsupportedEncodingException {
        // 普通应用
        redirectUri = redirectUriBase + redirectUri;
        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));
@@ -62,10 +75,10 @@
    @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");
        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("企业微信未授权手机号,无法登录");
        }