Heim > Artikel > Backend-Entwicklung > 微信网页授权接口代码示例
OAuth2.0网页授权演示 <a href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx3b83200000000000&redirect_uri=http://www.domain.com/oauth2.php&resp/a>%0A
%E5%9B%9E%E8%B0%83%E9%A1%B5%E9%9D%A2
<?php if (isset($_GET['code'])){ // echo $_GET['code']; //通过code换取token $code = $_GET['code']; $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx3b0000000&secret=575e05512121xxxxxxxxxxx&code=$code&grant_type=authorization_code"; $json = file_get_contents($url); $arr = json_decode($json,true); $token = $arr['access_token']; $openid = $arr['openid']; //拿到token后就可以获取用户基本信息了 $url = "https://api.weixin.qq.com/sns/userinfo?access_token=$token&openid=$openid "; $json = file_get_contents($url);//获取微信用户基本信息 $arr = json_decode($json,true); $name = $arr['nickname'];//昵称 $imgURL = $arr['headimgurl'];//头像地址 $sex = $arr['sex'];//性别 $province = $arr['province'];//用户个人资料填写的省份 $city= $arr['city'];//普通用户个人资料填写的城市 $country= $arr['country'];//国家,如中国为CN echo "OpenID:".$openid."<br/>"; echo "昵称:".$name."<br>"."头像地址:".$imgURL."<br>"."性别:".$sex."<br>"."省份:".$province."<br>"."城市:".$city."<br>"; echo "<img src="'%22.%24imgURL.%22'" alt="微信网页授权接口代码示例" >"; }else{ echo "NO CODE"; } ?></a>
以上就介绍了 微信网页授权接口代码示例,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。