Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

laravel8.0 getUserByCode 不能用,报错 #95

Open
goofy-he opened this issue Dec 18, 2020 · 3 comments
Open

laravel8.0 getUserByCode 不能用,报错 #95

goofy-he opened this issue Dec 18, 2020 · 3 comments

Comments

@goofy-he
Copy link

laravel8.0 getUserByCode 不能用,报错 无效码
laravel7 正常

@mingyoung
Copy link
Owner

报错信息提供下

@zm-john
Copy link

zm-john commented Feb 2, 2021

@mingyoung

  • client middleware $request->getUri()->getQuery() 没有取到值
  • vendor/mingyoung/dingtalk/src/Kernel/Http/Client.php
public function withAccessTokenMiddleware()
    {
        if (isset($this->getMiddlewares()['access_token'])) {
            return $this;
        }

        $middleware = function (callable $handler) {
            return function (RequestInterface $request, array $options) use ($handler) {
                if ($this->app['access_token']) {
                    parse_str($request->getUri()->getQuery(), $query); // 这个地方没有拿到 code,所以报【不存在的临时授权码】
                    // 正常情况下,请求参数应该是:access_token=xx&code=xyy
                    // 现在是,access_token=xx,缺失 code 参数
                    $request = $request->withUri(
                        $request->getUri()->withQuery(http_build_query(['access_token' => $this->app['access_token']->getToken()] + $query))
                    );
                }

                return $handler($request, $options);
            };
        };

        $this->pushMiddleware($middleware, 'access_token');

        return $this;
    }
  • 下面这样改,middleware 可以去到值
  • vendor/mingyoung/dingtalk/src/User/Client.php
public function getUserByCode($code)
{
        // return $this->client->get("user/getuserinfo", compact('code')); 源码
        return $this->client->get("user/getuserinfo?code={$code}"); // 修改后
}

@zm-john
Copy link

zm-john commented Feb 2, 2021

是 guzzle/http 从 6.* 升级到 7.* 导致的 bug

可以这样解决,

  1. 将 guzzle/http 降到 6.*
composer require "guzzlehttp/guzzle:^6.3"
  1. 重新安装, 按顺序来,不然会报依赖 overtrue/http 版本的错误
composer remove mingyoung/dingtalk
composer require "mingyoung/dingtalk: ^2.0"

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants