H5页面获取微信信息授权,微信授权,微信授权“redirect_uri 参数错误

 this.wxInfo.redirect_uri = encodeURIComponent(window.location.href);
        var h =
          "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
          this.wxInfo.appid +
          "&redirect_uri=" +
          this.wxInfo.redirect_uri +
          "&response_type=code&scope=" +
          this.wxInfo.scope +
          "&state=" +
          this.wxInfo.state +
          "#wechat_redirect";

        window.location.href = h;

H5页面获取微信信息授权-主要参数说明:

redirect_uri 是微信授权后回调的地址参数建议encodeURIComponent一下地址,避免出错(微信公众号授权登录,提示“redirect_uri 参数错误”
appid 是微信公众号id
 scope  获取用户信息 "snsapi_userinfo"
 
授权成功后会回调到redirect_uri 地址并在地址后面加上code=XX&state=XX
 
如果取到了code=XX&state=XX,调用后端接口传这两个参数给后端去取openId并判断用户信息
 
 
微信授权拒绝
由于拒绝授权,微信将回调到redirect_uri,但并不在参数后面添加信息
 
 
 
 
posted @ 2020-06-30 16:56  假装学习  阅读(2108)  评论(0编辑  收藏  举报