首页 > 代码库 > 微信公众号开发入门---STATE 2:获取用户信息
微信公众号开发入门---STATE 2:获取用户信息
微信以openid获取用户信息
//先获取access_token
$wxin_conf = Yii::$app->params[‘oauth_conf‘][‘oauth_wx_in‘];
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$wxin_conf[‘app_id‘]."&secret=".$wxin_conf[‘app_key‘];
$data = http://www.mamicode.com/CurlslUtil::get($url);
$data = http://www.mamicode.com/json_decode($data);
$token = @$data->access_token;
//获取userinfo
$url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=$token&openid=olKhow5AWI40PPzeeMVAjSXRFb3c&lang=zh_CN]";
$data = http://www.mamicode.com/CurlslUtil::get($url);
$data = http://www.mamicode.com/@json_decode($data);
var_dump($data);
//curl封装
public static function get($url, $asyncPost = 0, $header = array()) {
if ($asyncPost == 1)
$header [] = "Connection: close";
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_HTTPHEADER, $header );
curl_setopt ( $ch, CURLOPT_HEADER, 0 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $ch, CURLOPT_POST, false );
if (substr ( $url, 0, 5 ) == ‘https‘) {
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, FALSE );
}
$data = http://www.mamicode.com/curl_exec ( $ch );
curl_close ( $ch );
return $data;
}
微信公众号开发入门---STATE 2:获取用户信息
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。