收藏
回答

微信登录接口返回100086错误,错误提示:invalud code decode fail?

我在微信打开如下链接:

https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa9dcb46169680d66&redirect_uri=https%3A%2F%2Fpdf.fusetools.com.cn%2Fqqc.php&response_type=code&scope=snsapi_base&state=1#wechat_redirect

没有预期的弹出 获取用户信息 授权提示,而是返回了一个

code_error:

100068

code_msg :

invalid code, decode fail


这个错误码在公众号微信网页授权说明页是没有的:

https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html

在线等,有人碰到过吗

【已解决】
 回调地址弄错了 用了qq登录的回调地址导致的,改成微信公众号的就可以了, 代码如下:


<?php  
    header("Content-Type: text/html;charset=utf-8");
    
    $appid = "xxx";  
    $secret = "xxxx";  
    
    $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';  
      
    $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);  
    curl_close($ch);  
    $json_obj = json_decode($res,true);  
      
    //根据openid和access_token查询用户信息  
    $access_token = $json_obj['access_token'];  
    $openid = $json_obj['openid'];  
    $get_user_info_url = 'https://api.weixin.qq.com/sns/userinfo?access_token='.$access_token.'&openid='.$openid.'&lang=zh_CN';  
      
    $ch = curl_init();  
    curl_setopt($ch,CURLOPT_URL,$get_user_info_url);  
    curl_setopt($ch,CURLOPT_HEADER,0);  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );  
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);  
    $res = curl_exec($ch);  
    curl_close($ch);
      
    //解析json  
    $user_obj = json_decode($res,true);  
    $_SESSION['user'] = $user_obj;  
    print_r($user_obj);  
  
?>  

最后一次编辑于  2022-06-29
回答关注问题邀请回答
收藏

2 个回答

登录 后发表内容