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,但並不在參數后面添加信息
 
 
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM