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

找不到postJson()这个方法 #98

Open
jetox opened this issue Dec 25, 2020 · 5 comments
Open

找不到postJson()这个方法 #98

jetox opened this issue Dec 25, 2020 · 5 comments

Comments

@jetox
Copy link

jetox commented Dec 25, 2020

Call to undefined method EasyDingTalk\Kernel\Http\Client::postJson()

@huchenghua
Copy link

Call to undefined method EasyDingTalk\Kernel\Http\Client::postJson()

你是laravel8吗? 你是如何解决这个问题的?

@jiangslee
Copy link

image
不知道怎么修复比较优雅。。我只能 hard code 进去。。

@huchenghua
Copy link

好的, 谢啦

@jiangslee
Copy link

image

App\Common\Dingtalk\Http\Client.php

<?php
namespace App\Common\Dingtalk\Http;

use EasyDingTalk\Kernel\Http\Client as BaseClient;

class Client extends BaseClient {

    public function version()
    {
        return ['http_client_version' => 'hello world 1.0'];
    }

    /**
     * GET request.
     *
     * @param string $url
     * @param array  $query
     *
     * @throws \GuzzleHttp\Exception\GuzzleException
     *
     * @return \Psr\Http\Message\ResponseInterface|\Overtrue\Http\Support\Collection|array|object|string
     */
    public function get(string $url, array $query = [], $async = false)
    {
        return $this->request($url, 'GET', ['query' => $query], $async);
    }

    /**
     * JSON request.
     *
     * @param string       $url
     * @param string|array $data
     * @param array        $query
     *
     * @throws \GuzzleHttp\Exception\GuzzleException
     *
     * @return \Psr\Http\Message\ResponseInterface|\Overtrue\Http\Support\Collection|array|object|string
     */
    public function postJson(string $url, array $data = [], array $query = [])
    {
        return $this->request($url, 'POST', ['query' => $query, 'json' => $data]);
    }

}

App\Common\Dingtalk\Http\ServiceProvider.php

namespace App\Common\Dingtalk\Http;

use Pimple\Container;
use Pimple\ServiceProviderInterface;

class ServiceProvider implements ServiceProviderInterface
{
    /**
     * Registers services on the given container.
     * This method should only be used to configure services and parameters.
     * It should not get services.
     *
     * @param \Pimple\Container $pimple A container instance
     */
    public function register(Container $pimple)
    {
        // isset($pimple['client']) || 
        $pimple['client'] = function ($app) {
            return new Client($app);
        };
    }
}

找到了比较合适的解决方案了,这样就不用hard code进vendor了

@huchenghua
Copy link

image

App\Common\Dingtalk\Http\Client.php

<?php
namespace App\Common\Dingtalk\Http;

use EasyDingTalk\Kernel\Http\Client as BaseClient;

class Client extends BaseClient {

    public function version()
    {
        return ['http_client_version' => 'hello world 1.0'];
    }

    /**
     * GET request.
     *
     * @param string $url
     * @param array  $query
     *
     * @throws \GuzzleHttp\Exception\GuzzleException
     *
     * @return \Psr\Http\Message\ResponseInterface|\Overtrue\Http\Support\Collection|array|object|string
     */
    public function get(string $url, array $query = [], $async = false)
    {
        return $this->request($url, 'GET', ['query' => $query], $async);
    }

    /**
     * JSON request.
     *
     * @param string       $url
     * @param string|array $data
     * @param array        $query
     *
     * @throws \GuzzleHttp\Exception\GuzzleException
     *
     * @return \Psr\Http\Message\ResponseInterface|\Overtrue\Http\Support\Collection|array|object|string
     */
    public function postJson(string $url, array $data = [], array $query = [])
    {
        return $this->request($url, 'POST', ['query' => $query, 'json' => $data]);
    }

}

App\Common\Dingtalk\Http\ServiceProvider.php

namespace App\Common\Dingtalk\Http;

use Pimple\Container;
use Pimple\ServiceProviderInterface;

class ServiceProvider implements ServiceProviderInterface
{
    /**
     * Registers services on the given container.
     * This method should only be used to configure services and parameters.
     * It should not get services.
     *
     * @param \Pimple\Container $pimple A container instance
     */
    public function register(Container $pimple)
    {
        // isset($pimple['client']) || 
        $pimple['client'] = function ($app) {
            return new Client($app);
        };
    }
}

找到了比较合适的解决方案了,这样就不用hard code进vendor了

👍👍👍

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