$appid = "appid appid ";
$secret = "secret ";
$code = $_GET["code"];
$get_token_url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$appid.'&secret='.$secret.'&code='.$code.'&grant_type=authorization_code';
//header("location:$get_token_url");
echo $get_token_url."
";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$get_token_url);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1 );
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10);
$res = curl_exec($ch);
echo "echo:".json_encode($res)."
"; //显示false
echo curl_multi_getcontent($ch)."
"; //空
curl_close($ch);
$json_obj = json_decode($res,true);
//根据openid和access_token查询用户信息
$access_token = $json_obj['access_token'];
$openid = $json_obj['openid'];
var_dump($res); //显示obj(false)
echo $openid;
登录后复制
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$get_token_url);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //不验证证书
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //不验证证书
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1 );
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10);
$res = curl_exec($ch);
var_dump($res); //有返回值
登录后复制