代码如下:
//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'};