使用了php,php部分如下:
$code = $_GET["code"];
$userinfo = getUserInfo($code);
function getUserInfo($code)
{
$appid = "1111111111";
$appsecret = "1111111111111";//appid和appsecret在这里隐去,在源代码中是正确的
$access_token = "";
//Get access_token
$access_token_url = "https://api./sns/oauth2/access_token?appid=$appid&secret=$appsecret&code=$code&grant_type=authorization_code";
$access_token_json = https_request($access_token_url);
$access_token_array = json_decode($access_token_json,true);
$access_token = $access_token_array['access_token'];
$openid = $access_token_array['openid'];
//Get user info
$userinfo_url = "https://api./sns/userinfo?access_token=$access_token&openid=$openid";
$userinfo_json = https_request($access_token_url);
$userinfo_array = json_decode($userinfo_json,ture);
echo $userinfo_json;
return userinfo_array;
}
function https_request($url)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($curl);
if (curl_errno($curl)){
return 'ERROR'.curl_error($curl);
}
curl_close($curl);
return $data;
}
然后现在出现的问题就是,调userinfo_json时出现了问题,导致了最后结果无法显示。
中间过程把userinfo_json输出时,提示{"errcode":40029,"errmsg":"invalid code"}
而如果我把userinfo_url的链接复制下来在手机打开的话,还是能调用到用户的详细资料
所以问题到底出现在了哪里?有什么解决办法?求大神解答