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

相关文章

文章浏览阅读8.4k次,点赞8次,收藏7次。SourceCodester Onl...
文章浏览阅读3.4k次,点赞46次,收藏51次。本文为大家介绍在...
文章浏览阅读1.1k次。- php是最优秀, 最原生的模板语言, 替代...
文章浏览阅读1.1k次,点赞18次,收藏15次。整理K8s网络相关笔...
文章浏览阅读1.2k次,点赞22次,收藏19次。此网络模型提供了...
文章浏览阅读1.1k次,点赞14次,收藏19次。当我们谈论网络安...