微信登录接口调用步骤

WX开放平台申请网站应用,获得APPID和SECRET,第三方应用接入WX登录

APPID:xxxxxxxxxxxxxx
SECRET:yyyyyyyyyyyyyyy

第一步:调用微信登录接口,用户扫码登录,生成code
https://open.weixin.qq.com/connect/qrconnect?appid=xxxxxxxxxxxxxx&redirect_uri=https%3A%2F%2Fp7yrpa.natappfree.cc&response_type=code&scope=snsapi_login&state=200

结果:
http://79n8s3.natappfree.cc/?code=0610Xey313BXSQ15G6v31H6wy310Xeyv&state=200

第二步:请求以下路径通过code获取access_token 参数:appid=APPID,secret=SECRET,code=填写上一步生成的code,grant_type=“authorization_code”,生成access_token
https://api.weixin.qq.com/sns/oauth2/access_token
https://api.weixin.qq.com/sns/oauth2/access_token?appid=xxxxxxxxxxxxxx&secret=yyyyyyyyyyyyyyy&code=061OWZMX1Rl7LZ0qICMX1I9CMX1OWZMK&grant_type=authorization_code
https://api.weixin.qq.com/sns/oauth2/access_token?appid=xxxxxxxxxxxxxx&secret=SECRETyyyyyyyyyyyyyyy&code=0610Xey313BXSQ15G6v31H6wy310Xeyv&grant_type=authorization_code

结果:
{ 
"access_token":"ACCESS_TOKEN",                       	接口调用凭证
"expires_in":7200, 			          	access_token接口调用凭证超时时间,单位(秒)
"refresh_token":"REFRESH_TOKEN",		用户刷新access_token
"openid":"OPENID", 				授权用户唯一标识
"scope":"SCOPE",				用户授权的作用域,使用逗号(,)分隔
"unionid": "o6_bmasdasdsad6_2sgVt7hMZOPfL"	当且仅当该网站应用已获得该用户的userinfo授权时,才会出现该字段。
}

第三步:请求以下链接进行refresh_token 参数:appid=APPID,grant_type=‘refresh_token’,refresh_token=填写上一步获取到的refresh_token参数
https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=APPID&grant_type=refresh_token&refresh_token=23_ivXL7QsljTjYUJaifpGajw6DaWu3N-2A5-GewcFpSEK_xZ_CSBGBJ35HpXS-qa4GwbsvrEHbibwJWma3OKpYr73m3ZnAi25_V3pezwRSO10
https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=APPID&grant_type=refresh_token&refresh_token=REFRESH_TOKEN

结果:
{ 
"access_token":"ACCESS_TOKEN", 		接口调用凭证
"expires_in":7200, 				access_token接口调用凭证超时时间,单位(秒)
"refresh_token":"REFRESH_TOKEN", 		用户刷新access_token
"openid":"OPENID", 				授权用户唯一标识
"scope":"SCOPE" 				用户授权的作用域,使用逗号(,)分隔
}

第四步:请求以下连接查询用户基本信息 参数:access_token=填写上一步获取的access_token,openid=填写上一步获取的openid
https://api.weixin.qq.com/sns/userinfo

结果:
{"openid":"ooooooooooooo",
"nickname":"朝",
"sex":1,
"language":"zh_CN",
"city":"Hangzhou",
"province":"Zhejiang",
"country":"CN",
"headimgurl":"http:\/\/thirdwx.qlogo.cn\/mmopen\/vi_32\/Q0j4TwGTfTIlicQP4zdmtiaDkLEus7e8GMHZXnnD2YqLWpgEPl5QGPAKe02x4nMwZricqBOzo8gF0mm3gLyL0zh2Q\/132",
"privilege":[],
"unionid":"oniwU5vxax7qU27Xdy3Cb-MYvYeE"}

你可能感兴趣的:(笔记)