转:【微信公众号】微信snsapi_base静默授权与snsapi_userinfo网页授权的实现(不建议使用静默,直接用主动比较方便)

版权声明:本文为CSDN博主「小璐謌」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/qq_37462176/article/details/78917339

1、snsapi_base只能获取access_token和openID,流程走完即终止

2、snsapi_userinfo可以获取更详细的用户资料,比如头像、昵称、性别等

(注:当 scope=snsapi_userinfo时; 参考微信开发文档:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140842 )

/* 用全局access_token 和openid 获取用户个人信息: */

$url ="https://api.weixin.qq.com/cgi-bin/user/info?access_token={$access_token}&openid={$openid}&lang=zh_CN"

转:【微信公众号】微信snsapi_base静默授权与snsapi_userinfo网页授权的实现(不建议使用静默,直接用主动比较方便)

转:【微信公众号】微信snsapi_base静默授权与snsapi_userinfo网页授权的实现(不建议使用静默,直接用主动比较方便)

当 scope=snsapi_base时;

1、第一步,获取code,

https://open.weixin.qq.com/connect/oauth2/authorize?appid='.APPID.'&redirect_uri='.urldecode(URL).'login.php&response_type=code&scope=snsapi_base&state=start#wechat_redirect
2、第二步,获取openID, 网页授权access_token(注意:网页授权access_token 与 普通access_token的区别)

https://api.weixin.qq.com/sns/oauth2/access_token?appid='.APPID.'&secret='.APPSECRET.'&code='.CODE.'&grant_type=authorization_code
3、第三步,获取普通access_token,有效期7200秒
https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$secret
4、第四步,结合openID普通access_token获取用户详细信息,https://api.weixin.qq.com/cgi-bin/user/info?access_token='.$access_token.'&openid='.$openId.'&lang=zh_CN