【微信H5】 Redirect_uri參數錯誤解決方法



1
https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx14127af0bc9fd367&redirect_uri=http%3A%2F%2Ffbh5.wx.pre.qsepay.com%2Fbzinsh5%2Fpersonal%2Ffbwap.htm%3Fsource%3Dwage%26debug%3D1&response_type=code&scope=snsapi_base&state=&connect_redirect=1#wechat_redirect

1.0 引子

如上所示,就是我們報錯的url,下面就捋一捋我項目中的使用吧

redirect_uri 在我的項目中一般是取當前項目的url,用於獲取授權auth_code

 
         
<!--微信 授權都是通過code換取openid   分為 隱式授權(snsapi_base) / 顯式授權(snsapi_userinfo)-->
/**
 * 隱式授權(snsapi_base) 不彈窗 (顯示授權同意后,可以使用此方式獲取用戶信息)
 */
function toAuthorize(){
      var URIString=encodeURIComponent(window.location.href);
      window.location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appid+"&redirect_uri="+URIString+"&response_type=code&scope=snsapi_base&state=#wechat_redirect";
}
/**
 * 顯式授權(snsapi_userinfo) 彈出 "是否允許該網站獲取頭像,昵稱信息" 確認窗口
 */
function toAuthorizeX(){
      var hrefstr=window.location.href;
      if(hrefstr.indexOf("code=")!=-1){
         hrefstr= hrefstr.substr(0,hrefstr.indexOf("code="));
      }
      var URIString=encodeURIComponent(hrefstr);
       window.location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appid+"&redirect_uri="+URIString+"&response_type=code&scope=snsapi_userinfo&state=#wechat_redirect";

}
 
         

2.0 分析錯誤

2.1 有問題找官網 http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html

2.2 友情提示:

網頁授權的域名跟 Redirect_uri 所指向的頁面的域名不一致 
比如:你授權的 域名是 http://m.qsepay.com
你網頁跳轉的 url 是 http://m.qsepay.com/bzinsh5

這兩個很明顯不是在同一個域名下,你需要把 Redirect_uri 設置為:http://m.qsepay.com/bzinsh5

 

 
        


免責聲明!

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



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