网页扫描登陆

https://open.weixin.qq.com/cgi-bin/frame?t=home/web_tmpl&lang=zh_CN

申请在微信开放平台

https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&lang=zh_CN

@GetMapping("/qrAuthorize")
public String qrAuthorize(@RequestParam("returnUrl") String returnUrl) {
    String url =  "http://d7bkz5.natappfree.cc/sell/wechat/sell/wechat/qrUserInfo";
    String redirectUrl = wxOpenService.buildQrConnectUrl(url, WxConsts.QRCONNECT_SCOPE_SNSAPI_LOGIN, URLEncoder.encode(returnUrl));
    return "redirect:" + redirectUrl;
}

@GetMapping("/qrUserInfo")
public String qrUserInfo(@RequestParam("code") String code,
                         @RequestParam("state") String returnUrl) {
    WxMpOAuth2AccessToken wxMpOAuth2AccessToken = new WxMpOAuth2AccessToken();
    try {
        wxMpOAuth2AccessToken = wxOpenService.oauth2getAccessToken(code);
    } catch (WxErrorException e) {
        log.error("【微信网页授权】{}", e);
        throw new SellException(ResultEnum.WECHAT_MP_ERROR.getCode(), e.getError().getErrorMsg());
    }
    log.info("wxMpOAuth2AccessToken={}", wxMpOAuth2AccessToken);
    String openId = wxMpOAuth2AccessToken.getOpenId();

    return "redirect:" + returnUrl + "?openid=" + openId;
}


你可能感兴趣的:(微信)