在做网页授权url的时候,师兄的代码是这样子写的:
1 2 3 4 5 6 7 8 9 | @GetMapping ( "/authorize" ) public String authorize( @RequestParam ( "returnUrl" ) String returnUrl) { //1. 配置 //2. 调用方法 //url:http://sell.natapp4.cc/sell/wechat/userInfo String url = projectUrlConfig.getWechatMpAuthorize() + "/sell/wechat/userInfo" ; String redirectUrl = wxMpService.oauth2buildAuthorizationUrl(url, WxConsts.OAUTH2_SCOPE_BASE, URLEncoder.encode(returnUrl)); return "redirect:" + redirectUrl; } |
但是我进入
1 | wxMpService.oauth2buildAuthorizationUrl |
的实现方法中看到下面的代码:
1 2 3 | public String oauth2buildAuthorizationUrl(String redirectURI, String scope, String state) { return String.format( "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=%s#wechat_redirect" , this .getWxMpConfigStorage().getAppId(), URIUtil.encodeURIComponent(redirectURI), scope, StringUtils.trimToEmpty(state)); } |
这个实现的方法最后不是把这段地址都return回去了么?我感觉redirectUrl最后的值应该是:
1 | https: //open.weixin.qq.com/connect/qrconnect?appid=wxd898fcb01713c658&redirect_uri=www.imooc.com&response_type=code&scope=snsapi_base&state=#wechat_redirect |
但是仔细想想这个肯定是错的,因为这样子的话就无法调用接收code的方法了,很烦呀,是我sdk没有读懂么?