首先微信開放平臺(tái)申請(qǐng)appID和appsecret
appID:w...f
appsecret:maw...a
回調(diào)地址:http://***.ngrok.cc/wxCallback
1. 獲取code
- 請(qǐng)求地址:https://open.weixin.qq.com/connect/qrconnect
- 請(qǐng)求方法:GET
- 請(qǐng)求參數(shù):appid redirect_uri response_type scope
- 返回結(jié)果:redirect_uri?code=CODE&state=STATE
2. 通過code獲取access_token
- 請(qǐng)求地址:https://api.weixin.qq.com/sns/oauth2/access_token
- 請(qǐng)求方法:GET
- 請(qǐng)求參數(shù):appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code
- 返回結(jié)果:access_token expires_in refresh_token openid scope
3. 通過access_token調(diào)用接口 獲取用戶個(gè)人信息
- 請(qǐng)求地址:https://api.weixin.qq.com/sns/userinfo
- 請(qǐng)求方法:GET
- 請(qǐng)求參數(shù):access_token=ACCESS_TOKEN&openid=OPENID
- 返回結(jié)果:openid nickname...
最終獲得用戶信息包括:
- openid
- nickname
- sex
- language
- city
- province
- country
- headimgurl
- privilege