php教程

超轻量级php框架startmvc

PHP通过微信跳转的Code参数获取用户的openid(关键代码)

更新时间:2020-03-09 19:06 作者:startmvc
关键代码如下所示://获取微信登录用户信息functiongetOpenID($appid,$appsecret,$code){$url="https://api.

关键代码如下所示:


//获取微信登录用户信息
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(关键代码),希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!