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