收藏
回答

我想做一个app分享的带邀请功能的二维码,进入二维码之后授权可以直接注册,但是一次授权就可以?

/**
 * 微信网页授权登录
 *
 * @return 结果
 */
@Anonymous
@GetMapping("/webAuthorize")
public AjaxResult authorize(HttpServletResponse response, HttpSession session, @RequestParam String inviteCode, @RequestParam String uri) throws IOException {
    // 生成唯一的 state 值,加入随机数或时间戳
    String state = inviteCode + "_STATE_" + UUID.randomUUID().toString();
    String scope = "snsapi_userinfo";
    String redirectUri = wxMpConfiguration.getRedirectUri();

    // 构建授权 URL
    String authorizeUrl = wxMpConfiguration.wxMpService()
            .getOAuth2Service()
            .buildAuthorizationUrl(redirectUri, scope, state) + "&forcePopup=true";

    // 清理 session 中的授权状态
    session.removeAttribute("authState");

    // 返回成功信息并附带授权链接
    return AjaxResult.success("授权成功", authorizeUrl);

}

我想做成每次就来都需要重新授权,但是现在的情况是只要第一次授权了,有效期就是30天,能做成每次都需要授权么?

回答关注问题邀请回答
收藏
登录 后发表内容