微信通过网页获取用户头像与昵称等信息

本文演示了如何通过微信OAuth2.0协议获取用户的openid、昵称、性别、城市、省份、国家和头像URL。首先,利用授权码获取openid,然后通过全局access_token获取用户详细信息。
摘要由CSDN通过智能技术生成
		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-
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值