首先微信开放平台申请appID和appsecret
appID:w...f
appsecret:maw...a
回调地址:http://***.ngrok.cc/wxCallback
1. 获取code
- 请求地址:https://open.weixin.qq.com/connect/qrconnect
- 请求方法:GET
- 请求参数:appid redirect_uri response_type scope
- 返回结果:redirect_uri?code=CODE&state=STATE
2. 通过code获取access_token
- 请求地址:https://api.weixin.qq.com/sns/oauth2/access_token
- 请求方法:GET
- 请求参数:appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code
- 返回结果:access_token expires_in refresh_token openid scope
3. 通过access_token调用接口 获取用户个人信息
- 请求地址:https://api.weixin.qq.com/sns/userinfo
- 请求方法:GET
- 请求参数:access_token=ACCESS_TOKEN&openid=OPENID
- 返回结果:openid nickname...
最终获得用户信息包括:
- openid
- nickname
- sex
- language
- city
- province
- country
- headimgurl
- privilege