今天配置fastadmin的第三方登录,发现微博配置好后,能正常跳转,就是返回后一直提示操作失败,具体调试后发现是获取授权报错:

'{"error":"invalid_request","error_code":21323,"request":"/2/oauth2/access_token","error_uri":"/2/oauth2/access_token","error_description":"miss client id or secret"}'

Google了一下解决办法,具体修改如下:

找到文件addons\third\library\Weibo.php,然后把函数

public function getAccessToken($code = '')
    {
        if (!$code) {
            return '';
        }
        $queryarr = array(
            "grant_type"    => "authorization_code",
            "client_id"     => $this->config['app_id'],
            "client_secret" => $this->config['app_secret'],
            "redirect_uri"  => $this->config['callback'],
            "code"          => $code,
        );
        $response = Http::post(self::GET_ACCESS_TOKEN_URL, $queryarr);
        $ret = (array)json_decode($response, true);
        return $ret ? $ret : [];
    }


修改为:

public function getAccessToken($code = '')
    {
        if (!$code) {
            return '';
        }
        $queryarr = array(
            "grant_type"    => "authorization_code",
            "client_id"     => $this->config['app_id'],
            "client_secret" => $this->config['app_secret'],
            "redirect_uri"  => $this->config['callback'],
            "code"          => $code,
        );
        $url=self::GET_ACCESS_TOKEN_URL.'?';
        foreach ($queryarr as $k=>$v){
            $url.="{$k}={$v}&";
        }
        $response = Http::post($url);
        $ret = (array)json_decode($response, true);
        return $ret ? $ret : [];
    }