通过access_token openid获取微信用户昵称等信息

<?php
header('Access-Control-Allow-Origin:*');
$access_token = !empty($_GET['access_token'])?$_GET['access_token']:'';
$openid       = !empty($_GET['openid'])?$_GET['openid']:'';
//该微信url不允许前端ajax直接访问,只能由本地后端访问获取数据,再通过ajax传给前端
$url          = "https://api.weixin.qq.com/sns/userinfo?access_token={$access_token}&openid={$openid}&lang=zh_CN";
//echo $url;exit;
echo file_get_contents($url);

//https://api.weixin.qq.com/sns/userinfo?access_token=8_7O0hMPhShKPeicr8DJMpAwgUklPOPJTVmXQ0X1oXeX1sjvGK1bb8kZlxz4z10LkT_PRvssrnDwEswhXtvghxmarYl3gTFrvm1DtVanZn2vlTlpZhnbBb8K7jVszfU-q17Uysrarxz6f60ooNLSUiAFACJL&openid=o5-P4snElQIi859NmTB3bZ_ryGF0&lang=zh_CN
?>

 

posted @ 2018-04-18 23:02  风吹屁股凉冰冰  阅读(2416)  评论(0编辑  收藏  举报