經過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
?>
相關文章
相關標籤/搜索