有时网站需要获取用户微信头像用以显示
但是微信头像等信息的获取需要用户的同意,也就不像qq头像那么容易获取
首先获取授权
index.php (授权页面)
注意:将appid
以及redirect_uri
改为自己的
oauth_response.php 文件
{'access_token'})){
//保存access_token
$access_token = $rs->{'access_token'};
$openid = $rs->{'openid'};
//请求成功返回errcode
}else if (isset($rs->{'errcode'})) {
//# code...
}
//拉取用户信息(需scope为 snsapi_userinfo)
$user = json_decode(curlget("https://api.weixin.qq.com/sns/userinfo?access_token=".$access_token."&openid=".$openid."&lang=zh_cn"));
echo '
';
echo '5555';
echo $user->{'nickname'}."
";
echo $user->{'sex'}."
";
echo $user->{'province'}."
";
echo $user->{'city'}."
";
echo $user->{'country'}."
";
echo $user->{'headimgurl'}."
";
echo $user->{'privilege'}."
";
echo $user->{'unionid'}."
";
echo $user->{'headimgurl'}."
";
?>
注意:将appid
及secret
改为自己的
之后将微信公众号端的授权回调页面域名修改
做好之后,在微信中打开网页即可
目前评论:0