微信登陆获取用户信息
Posted yangwenchao-blogs
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了微信登陆获取用户信息相关的知识,希望对你有一定的参考价值。
目前可试试这两个接口
后台需完善地方:
1.拼装微信扫一扫登录url;
2.先微信返回access_token才能进行跳转,回调https://api.weixin.qq.com/sns/userinfo?access_token=获取到的ACCESS_TOKEN&openid=获取到的OPENID;
3.返回用户信息
1.微信扫一扫获取二维码(点击登陆按钮,获取如下data数据,把此返回值解析成二维码展现给用户来微信扫码登陆)
接口:
http://192.168.2.69:8080/client/login/login_url GET
请求参数示例:
http://192.168.2.69:8080/client/login/login_url?access_page=https://open.weixin.qq.com/connect/qrconnect
返回操作成功0和失败-1
{
"state":0,
"msg":"operate success",
"data":"https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_coderedirect_uri?code=CODE&state=STATE",
"success":true
}
"state":0,
"msg":"operate success",
"data":"https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_coderedirect_uri?code=CODE&state=STATE",
"success":true
}
或
{
"state":-1,
"msg":null
"data":null,
"success":false
}
2.客户端轮询查询用户信息(目前客户端试试轮询方案,这个具体参数待定,这里是给你测试用的flag=success返回成功 其他返回失败)
接口:
http://192.168.2.69:8080/client/login/userInfo GET
请求参数示例:
http://192.168.2.69:8080/client/login/userInfo?flag=success
返回操作成功0和失败-1
{
"state":0,
"msg":"operate success",
"data":{
"image":"https://dss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/static/protocol/https/home/img/icons_0c37e9b.png",
"country":"China",
"city":"shenzhen",
"nick_name":"jack"
},
"success":true
}
"state":0,
"msg":"operate success",
"data":{
"image":"https://dss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/static/protocol/https/home/img/icons_0c37e9b.png",
"country":"China",
"city":"shenzhen",
"nick_name":"jack"
},
"success":true
}
或
{
"state":-1,
"msg":null
"data":null,
"success":false
}
以上是关于微信登陆获取用户信息的主要内容,如果未能解决你的问题,请参考以下文章
基于ThinkPHP框架小程序获取微信用户信息并将存进数据库