微信小程序,weixin,新鸟求助,出现了40029问题

2024-11-24 06:04:48
推荐回答(2个)
回答1:

$zsappid='wx80dd3667ed6e2863';
$zssecret='18088e581ffe1d3ce8e84f368a22b6c7';

if(isset($_GET['code'])){

hq_AccessToken($_GET['code']);
}

function hq_AccessToken($codea){
$url="https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$zsappid."&secret=".$zssecret."&code=".$codea."&grant_type=authorization_code";
$res=httpRequset($url);
print_r($res);
}

function httpRequset($url,$data=false){
$ch=curl_init();
//设置超时
curl_setopt($ch,CURLOPT_TIMEOUT,60);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);
if($data){
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
}
curl_setopt($ch,CURLOPT_HEADER,FALSE);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
$res=curl_exec($ch);
curl_close($ch);
return $res;
}
?>

回答2:

code只能使用一次的,你这个应该是code使用了两次哦。附上我的代码
$url = "https://api.weixin.qq.com/sns/jscode2session?appid=" . C('wx_appid') . "&secret=" . C('wx_appsecret') . "&js_code=" . $code . "&grant_type=authorization_code";