首页 > Web开发 > 详细

网页授权获取用户基本信息

时间:2014-11-21 20:24:27      阅读:306      评论:0      收藏:0      [点我收藏+]

微信授权登录。

基本情况:认证的服务号;

主要测试代码:

 public function openOAuth(){
        //获取回调连接中带有的code
        $code = $_GET[code];
        //获取access_token openid
        $json = file_get_contents("https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx7a5423a6f023716c5&secret=6bb7bstddekxrsa3bdcd296979bfb66967f41&code=$code&grant_type=authorization_code");
        $json = json_decode($json);

        $refresh_token =  $json->refresh_token;
      //通过refresh_token 获取需要的access_token $json_ref
= file_get_contents("https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=wx3a542a6f094310c5&grant_type=refresh_token&refresh_token=$refresh_token"); $json_ref = json_decode($json_ref); $access_token = $json_ref->access_token; $openId = $json_ref->openid; $json_userinfo = file_get_contents("https://api.weixin.qq.com/sns/userinfo?access_token=$access_token&openid=$openId&lang=zh_CN"); $json_userinfo = json_decode($json_userinfo); $nikename = $json_userinfo->nickname; $sex = $json_userinfo->sex; $area = $json_userinfo->province.-.$json_userinfo->city.-.$json_userinfo->country; $headimgurl = $json_userinfo->headimgurl; //echo $headimgurl; $privilege = $json_userinfo->privilege; $unionid = $json_userinfo->unionid; echo "<h1>展示身份信息</h1>"; echo"<h2>昵称:$nikename</h2>"; echo"<h2>性别:$sex</h2>"; echo"<h2>地址:$area</h2>"; echo<h2>头像</h2><img src=".$headimgurl.">; echo"<h2>privilege:$privilege </h2>"; echo"<h2>unionid:$unionid</h2>"; }

个人完整文档;http://files.cnblogs.com/bin-pureLife/%E5%B0%8F%E5%9B%BE%E6%A0%87.zip

APPID 等隐私处以替换。

网页授权获取用户基本信息

原文:http://www.cnblogs.com/bin-pureLife/p/4113543.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!