码迷,mamicode.com
首页 > 微信 > 详细

【微信H5】 Redirect_uri参数错误解决方法

时间:2017-05-03 15:19:29      阅读:559      评论:0      收藏:0      [点我收藏+]

标签:官网   fst   string   用户   ref   index   pre   方式   appid   


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

 


【微信H5】 Redirect_uri参数错误解决方法

标签:官网   fst   string   用户   ref   index   pre   方式   appid   

原文地址:http://www.cnblogs.com/Profound/p/6801995.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!