废话不多说,直接上解决方案。
首先打开微信公众平台页面,左边列表找设置->公众号设置, 选择功能设置选项卡,确认一下是否正确设置了回调域名(图中网页授权域名)

搜索这个问题的人绝大部分应该都已经设置好了,
如果这里设置了域名,并且你的redirect_uri 给的也是 域名/xxx这种形式, 但是还是访问不到,首先看一下代码:
var redirect_uri = "wwww.aaa.com"
var oauth2Url = "https://open.weixin.qq.com/connect/oauth2/authorize"
+"?appid=" + appid
+"&redirect_uri=" + redirect_uri
+"&response_type=code&scope="+ scope
+"&state=STATE#wechat_redirect"
这里有个惊天大坑, 在设置回调域名的时候,微信明确指出不要添加http://前缀,所以我们就可能先入为主的认为redirect_uri也不需要填写http://, 如果不填的话是访问不到的。
解决方法
redirect_uri 带上“http://”前缀
var redirect_uri = "wwww.aaa.com"
var oauth2Url = "https://open.weixin.qq.com/connect/oauth2/authorize"
+"?appid=" + appid
+"&redirect_uri=http://" + redirect_uri //注意这里加上了http://前缀
+"&response_type=code&scope="+ scope
+"&state=STATE#wechat_redirect"
本文解决了一个常见的微信OAuth2.0回调域名配置问题。主要介绍如何正确设置redirect_uri来确保从微信跳转回应用时不会发生错误。
1万+

被折叠的 条评论
为什么被折叠?



