PHP获取小程序用户openid

代码如下:

//code值,从前端获取
$code = $_GET['code'];

//注册时获取
$appid="xxxxxxxxxxxxx";
$secret = "xxxxxxxxxxxxxxxxxxxxx";

$get_code_url = 'https://api.weixin.qq.com/sns/jscode2session?appid='.$appid.'&secret='.$secret.'&js_code='.$code.'&grant_type=authorization_code';
$ret=file_get_contents($get_code_url);
$openid= json_decode($ret)->{'openid'};

 

posted @ 2020-07-28 11:25  不叫一日闲过  阅读(789)  评论(0编辑  收藏  举报