微信开发获取openid中遇到的坑

来源:互联网 发布:同一首歌停播知乎 编辑:程序博客网 时间:2024/06/16 20:16

1:微信后台设置授权回调页面域名 注意不要加http://
微信后台设置授权回调页面域名
2:去微信授权回调的url

列如:https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=http://test.ceshi.com&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect
  1. redirect_uri=http://test.ceshi.com
    一定要加http://
    不要写成redirect_uri=test.ceshi.com
    【这个在电脑端的微信客户端可以, 在手机端就不行,害我周六来改】
  2. 如果你在微信端分享出去的链接像这样 http://test.ceshi.com?id=55
    那么你还这么去跳转转的话id=55会丢失的
https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=http://test.ceshi.com?id=55&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect

我是这么解决的:
0、session中有openid的话就不用走下面了
1、把分享出去的http://test.ceshi.com?id=55放入session中
2、redirect_uri=http://test.ceshi.com
3、微信回调回来之后再进行获取openid的操作,
4、把openid存入session中。
5、在从session中取出http://test.ceshi.com?id=55,这个url,再回调回去

0 0