微信公众号中通过菜单事件获得当前用户信息
2016-11-25 16:40
302 查看
首先、配置好网页授权:
自定义菜单的格式:
其中需要替换的2个参数:#{appid}和#{register-url},除去这两个参数外其它的部分为微信要求的格式!
当用户点击“注册账户”菜单后,系统会调用上边替换的register—url地址,并且会在这个地址添加一个code参数,通过这个code可以从微信平台拿到用户的openid,拿到openid后通过我们系统记录的绑定关系,就可以拿到userid了。
代码如下:
自定义菜单的格式:
{ "type": "view", "name": "注册账号", "url": "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{appid}&redirect_uri=#{register-url}&response_type=code&scope=snsapi_base#wechat_redirect" },
其中需要替换的2个参数:#{appid}和#{register-url},除去这两个参数外其它的部分为微信要求的格式!
当用户点击“注册账户”菜单后,系统会调用上边替换的register—url地址,并且会在这个地址添加一个code参数,通过这个code可以从微信平台拿到用户的openid,拿到openid后通过我们系统记录的绑定关系,就可以拿到userid了。
代码如下:
String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + Const.appid + "&secret=" + Const.secret + "&code=" + code + "&grant_type=authorization_code"; String content = NetworkUtils.doGetByHttps(url);
相关文章推荐
- iOS 开发 如何获得用户当前位置(通过经纬度获得城市、省份等信息)
- infopath表单预览正常,发布后无法通过Web Service获取当前用户信息的解决方案
- 如何通过ADO获得Access数据库中的所有用户表和表信息
- 通过IP地址获得用户所在城市的额天气信息的整理
- ASP.NET中如何获得当前已登录用户的Email信息呢?
- 微信公众号开发--自定义菜单跳转页面并获取用户信息(续)
- 公众号批量获取用户信息,php通过openid批量获得微信用户信息
- Java微信公众号开发之通过微信公众号获取用户信息
- 【转】通过CreateToolhelp32Snapshot函数获得系统中当前运行的进程信息
- 通过OAuth2.0方式弹出授权页面获得用户基本信息
- 通过新浪IP服务器获得的当前客户端IP地址对应的国家、省份或直辖市、城市信息
- PHP获得微信用户的OpenID,然后再通过OpenID和access_token查询用户信息
- 微信公众号开发 自定义菜单跳转页面并获取用户信息实例详解
- 怎样获得当前登录页面的用户的信息(域帐户)
- 通过CreateToolhelp32Snapshot函数获得系统中当前运行的进程信息
- 微信公众号,菜单扫码重定向获取用户信息
- 基于Springboot的微信公众号接入、通过网页授权机制获取用户信息
- PHP获得微信用户的OpenID,然后再通过OpenID和access_token查询用户信息
- 微信公众号开发--自定义菜单跳转页面并获取用户信息
- 从api获得当前用户信息