這篇文章主要介紹了PHP通過微信跳轉的Code參數獲取用戶的openid(關鍵代碼)的相關資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
關鍵代碼如下所示:
//獲取微信登錄用戶信息
function getOpenID($appid,$appsecret,$code){
$url="https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$appid."&secret=".
$appsecret."&code=".$code."&grant_type=authorization_code";
$weixin=file_get_contents($url);//通過code換取網頁授權access_token
$jsondecode=json_decode($weixin); //對JSON格式的字符串進行編碼
$array = get_object_vars($jsondecode);//轉換成數組
$openid = $array['openid'];//輸出openid
return $openid;
}
以上所述是小編給大家介紹的PHP通過微信跳轉的Code參數獲取用戶的openid(關鍵代碼),希望對大家有所幫助