代码改变世界

获取微信openid

2016-07-05 14:25  弹簧歌  阅读(272)  评论(0编辑  收藏  举报

通过这篇文章,成功获取到了Openid:

http://www.cnblogs.com/txw1958/p/weixin76-user-info.html

官方参考:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1455784140&token=&lang=zh_CN

但也遇到几个问题:

1,redirect_uri 参数错误

https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8888888888888888&redirect_uri=http://mascot.duapp.com/oauth2.php&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirec

用正确的appid和redirect_uri替换后,在微信web开发工具中输入链接,出现此错误

原因:授权回调页面域名未设置
设置地址位置:
登录公众平台:
开发——>接口权限——>网页账号——>修改

2,Scope 参数错误或没有 Scope 权限
通过对授权回调页面的设置,本来已经正常了,出现这个问题的原因是,在复制链接地址的过程中,不小心在地址中加入了回车键,如下:
https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8888888888888888&redirect_uri=http://mascot.duapp.com/oauth2.php&response_type=code&scope=snsapi_userinfo
&state=1#wechat_redirec