一、获取code:
https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx7a9d753f8dfdadf7&redirect_uri=http%3A%2F%2Fwx.minner.com&response_type=code&scope=snsapi_base&state=STATE&connect_redirect=1#wechat_redirect
会自动跳转链接,从链接的请求参数中获得code(可以通过右上角...点开复制链接,查看code)
例如:http://wx.minner.com/?code=061jI7Ga1zSMPG0hLgJa1VEUgz0jI7G6&state=STATE#/personal
二、用code获取access_token和openid
https://api.weixin.qq.com/sns/oauth2/access_token?appid={appid}&secret={secret}&code=061jI7Ga1zSMPG0hLgJa1VEUgz0jI7G6&grant_type=authorization_code
响应:
{
"access_token": "access_token",
"expires_in": 7200,
"refresh_token": "refresh_token",
"openid": "openid",
"scope": "snsapi_userinfo"
}
三、用access_token获取userinfo
https://api.weixin.qq.com/sns/userinfo?access_token={access_token}&openid={openid}&lang=zh_CN
响应:
{
"openid": "openid",
"nickname": "nickname",
"sex": 0,
"language": "",
"city": "",
"province": "",
"country": "",
"headimgurl": "https://thirdwx.qlogo.cn/mmopen/xxx",
"privilege": []
}