微信网页授权接口获取不到code,报错41008 缺少oauth code

我听闻始终一个人 2016-10-28 09:49:40
附上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.shnewfeel.com/xryl/weixin.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 ]" }







找了好几天了,也没找到原因。
求帮忙,真的。
...全文
7106 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
doudoubudou 2016-12-09
  • 打赏
  • 举报
回复
$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=$appid&secret=$secret&code=$code&grant_type=authorization_code
komyluo 2016-12-02
  • 打赏
  • 举报
回复
1、grant_type=authorization_cod是正确的? 2、在getUserOpenId()中,echo $_GET['code']看看
qq_36507503 2016-12-01
  • 打赏
  • 举报
回复
appid=".$appid."&secret=".$appsecret."&code=".$code."&grant_type=authorization_cod"; code呢呢

20,397

社区成员

发帖
与我相关
我的任务
社区描述
“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法利用了C、Java和Perl,该语言的主要目标是允许web开发人员快速编写动态网页。
phpphpstorm 技术论坛(原bbs)
社区管理员
  • 开源资源社区
  • phpstory
  • xuzuning
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧