发布网友 发布时间:2022-04-20 04:05
共6个回答
热心网友 时间:2022-05-19 01:23
一、通过全局Access Token获取用户基本信息热心网友 时间:2022-05-19 02:58
http://wifiapi03.51y5.net/wifiapi/rd.do?f=link_pv&b=cplk&rurl=http%3A%2F%2Ftzzuozy.iwangshop.com%2FHome%2FPull%3FOrderId%3DUo94ONHX8ZeYUrmYGs5oP4vlN28wN28sCZ4qEJ8nCZ0tDp4pC3asN28iN292OMvhGMDZRtLkT5mYEbmYwOAJw8AovxglN28iN29DRsvbULmYEZ4vBZSuB5mYGMrlTMvqN28wCJakDpWiN292OMvhJM5oQrmYEbmYGqL2N28iN292OMvhJc5jPLmYEbmYvOM9vQIdwPEswA6CN28iN292OMvhIMvaPNXS8ZfS8Z4vC3GoEJ4mDpCqE3CmDJCrD39S8dqYB29FScHbSaba8ZeYDZamCZ0nEJ0qCp0nCJ0nC3anDpOoDo8i8b1XUKrbT6XlP28wCJ4i8arlRcLv8ZenEIutE7D热心网友 时间:2022-05-19 04:49
一、通过全局Access Token获取用户基本信息
1. 用户关注以及回复消息的时候,均可以获得用户的OpenID
<xml>
<ToUserName><![CDATA[gh_b629c48b653e]]></ToUserName>
<FromUserName><![CDATA[ollB4jv7LA3tydjviJp5V9qTU_kA]]></FromUserName>
<CreateTime>1372307736</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[subscribe]]></Event>
<EventKey><![CDATA[]]></EventKey>
</xml>
其中的FromUserName就是OpenID
2. 然后使用access_token接口,请求获得全局Access Token
https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
返回结果:
{
"access_token": "NU7Kr6v9L9TQaqm5NE3OTPctTZx797Wxw4Snd2WL2HHBqLCiXlDVOw2l-Se0I-WmOLLniAYLAwzhbYhXNjbLc_KAA092cxkmpj5FpuqNO0IL7bB0Exz5s5qC9Umypy-rz2y441W9qgfnmNtIZWSjSQ",
"expires_in": 7200
}
3. 再使用全局ACCESS_TOKEN获取OpenID的详细信息
https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid=OPENID
返回如下:
{
"subscribe": 1,
"openid": "oLVPpjqs2BhvzwPj5A-vTYAX4GLc",
"nickname": "方倍",
"sex": 1,
"language": "zh_CN",
"city": "深圳",
"province": "广东",
"country": "中国",
"headimgurl": "http://wx.qlogo.cn/mmopen/JcDicrZBlREhnNXZRudod9PmibRkIs5K2f1tUQ7lFjC63pYHaXGxNDgMzjGDEuvzYZbFOqtUXaxSdoZG6iane5ko9H30krIbzGv/0",
"subscribe_time": 1386160805
}
至此,获得用户的基本信息。
二、通过OAuth2.0方式弹出授权页面获得用户基本信息
1. 首先配置回调域名
2. 构造请求url如下:
https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8888888888888888&redirect_uri=http://mascot.app.com/oauth2.php&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect
页面URL中的
scope=snsapi_userinfo 表示应用授权作用域为请求用户信息
★ 如果使用别人的AppID和AppSecret,那么获得的OpenID是那个有高级接口权限的服务号的,这里可以通过消息回复,获取本公众账号下的OpenID,带入回调中,与另一个OpenID进行关联
https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8888888888888888&redirect_uri=http://mascot.app.com/oauth2.php?userid=oc7tbuPA9BgUCLADib5nB3k2KWWg&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect
将该链接回复给关注用户,用户点击后,弹出应用授权界面
3. 回调页面得到链接如下,回调url中将包含参数code
http://mascot.app.com/oauth2.php?code=00b788e3b42043c8459a57a8d8ab5d9f&state=1
或者 http://mascot.app.com/oauth2.php?userid=oc7tbuPA9BgUCLADib5nB3k2KWWg&code=00b788e3b42043c8459a57a8d8ab5d9f&state=1
4. 再使用code换取oauth2的授权access_token
url如下:
https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx8888888888888888&secret=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&code=00b788e3b42043c8459a57a8d8ab5d9f&grant_type=authorization_code
获得授权Access Token:
{
"access_token": "OezXcEiiBSKSxW0eoylIeAsR0GmYd1awCffdHgb4fhS_KKf2CotGj2cBNUKQQvj-G0ZWEE5-uBjBz941EOPqDQy5sS_GCs2z40dnvU99Y5AI1bw2uqN--2jXoBLIM5d6L9RImvm8Vg8cBAiLpWA8Vw",
"expires_in": 7200,
"refresh_token": "OezXcEiiBSKSxW0eoylIeAsR0GmYd1awCffdHgb4fhS_KKf2CotGj2cBNUKQQvj-G0ZWEE5-uBjBz941EOPqDQy5sS_GCs2z40dnvU99Y5CZPAwZksiuz_6x_TfkLoXLU7kdKM2232WDXB3Msuzq1A",
"openid": "oLVPpjqs9BhvzwPj5A-vTYAX3GLc",
"scope": "snsapi_userinfo,"
}
5. 再使用授权Access Token获取用户信息
url如下:
https://api.weixin.qq.com/sns/userinfo?access_token=OezXcEiiBSKSxW0eoylIeAsR0GmYd1awCffdHgb4fhS_KKf2CotGj2cBNUKQQvj-G0ZWEE5-uBjBz941EOPqDQy5sS_GCs2z40dnvU99Y5AI1bw2uqN--2jXoBLIM5d6L9RImvm8Vg8cBAiLpWA8Vw&openid=oLVPpjqs9BhvzwPj5A-vTYAX3GLc
返回如下
{
"openid": "oLVPpjqs9BhvzwPj5A-vTYAX3GLc",
"nickname": "方倍",
"sex": 1,
"language": "zh_CN",
"city": "Shenzhen",
"province": "Guangdong",
"country": "CN",
"headimgurl": "http://wx.qlogo.cn/mmopen/utpKYf69VAbCRDRlbUsPsdQN38DoibCkrU6SAMCSNx558eTaLVM8PyM6jlEGzOrH67hyZibIZPXu4BK1XNWzSXB3Cs4qpBBg18/0",
"privilege": []
热心网友 时间:2022-05-19 06:57
自定义菜单---跳转到网页编辑方法:热心网友 时间:2022-05-19 09:22
其实我还真不知道,热心网友 时间:2022-05-19 12:03
http: //m. gmzl.cn