码迷,mamicode.com
首页 > 微信 > 详细

微信公众平台获取微信用户信息

时间:2015-05-28 19:53:46      阅读:451      评论:0      收藏:0      [点我收藏+]

标签:

1: 进入开发者管理中心 ---网页服务-----网页账号------网页授权获取用户基本信息  修改  改成自己网站的根域名 格式 如下图

                              技术分享

2:建立一个连接

 

技术分享

3: 具体获取数据的代码

//获取用户信息的函数 $accesstoken $openud
function usertoken($accesstoken,$openid){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.weixin.qq.com/sns/userinfo?access_token=".$accesstoken."&openid=".$openid );
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, ‘Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)‘);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
// curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$tmpInfo = curl_exec($ch);
if (curl_errno($ch)) {
echo ‘Errno‘.curl_error($ch);
}
curl_close($ch);
$arr= json_decode($tmpInfo,true);
return $arr;
}


//curltest("wx53cfe3a3e22780e8","28510dc852912a604bdd3ce8a6aaa9a5",$code);获取到的凭证
function getUserinfo($appid,$secret,$code){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$appid."&secret=".$secret."&code=".$code."&grant_type=authorization_code");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, ‘Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)‘);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$tmpInfo = curl_exec($ch);
if (curl_errno($ch)) {
//echo ‘Errno‘.curl_error($ch);
}
curl_close($ch);
$arr= json_decode($tmpInfo,true);
return usertoken($arr[‘access_token‘], $arr[‘openid‘]);
}

微信公众平台获取微信用户信息

标签:

原文地址:http://www.cnblogs.com/QQ42246692/p/4536603.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!