define("APPID", "xxxx");
define("APPSECRET", "xxx");
$code = $_GET['code'];
if(!$code){
echo '<a href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx5d7a4bb756e53b28&redirect_uri=http://www.xxx.com/index.php?m=oauth2&a=init&response_type=code&scope=snsapi_base&state=1#wechat_redirect" target="_blank">点击登陆</a>';
}else{
//使用code获取OpenID
$openid_url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=".APPID."&secret=".APPSECRET."&code=".$code."&grant_type=authorization_code";
$openid_data = file_get_contents($openid_url);
$arr_openid = (Array)json_decode($openid_data);
$openid = $arr_openid['openid'];
//获取全局Access Token
/*
$access_token_url = "https://api.weixin.qq.com/cgi-
微信通过网页获取用户头像与昵称等信息
最新推荐文章于 2024-07-05 16:55:18 发布
本文演示了如何通过微信OAuth2.0协议获取用户的openid、昵称、性别、城市、省份、国家和头像URL。首先,利用授权码获取openid,然后通过全局access_token获取用户详细信息。
摘要由CSDN通过智能技术生成