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;
      }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM