附上3段逻辑代码+报错。
一.调用第三方接口的方法
function https_request($url,$type="get",$res="json",$data = ''){
//1.初始化curl
$curl = curl_init();
//2.设置curl的参数
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,2);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
if ($type == "post"){
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
//3.采集
$output = curl_exec($curl);
//4.关闭
curl_close($curl);
if ($res == 'json') {
return json_decode($output,true);
}
}
二.获取用户的openid
function getBaseInfo(){
//1.获取到code
$appid = "我的Id";
$redirect_uri = urlencode("http://www.XXXX.com/XXXX/XXXX.php/Index/getUserOpenId");
$url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$appid."&redirect_uri=".$redirect_uri."&response_type=code&scope=snsapi_base&state=614#wechat_redirect";
header('location:'.$url);
}
三.获取用户的access_token
function getUserOpenId(){
$appid = "我的ID";
$appsecret = "我的appsecret";
$code=$_GET['code'];
//2.获取到网页授权的access_token
$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$appid."&secret=".$appsecret."&code=".$code."&grant_type=authorization_cod";
//3.拉取用户的openid
$res = $this->https_request($url,'get');
var_dump($res);
return $res;
}
报错信息
array(2) { ["errcode"]=> int(41008) ["errmsg"]=> string(47) "missing code, hints: [ req_id: TPKnBa0038s113 ]" }
找了好几天了,也没找到原因。
求帮忙,真的。