From d49cfce08cbe60417bf182c611c3d86560688aaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=80=99=E5=AD=A6=E6=9D=B0?= Date: Tue, 29 Jan 2019 16:00:05 +0800 Subject: [PATCH] add miniprogram --- .../ServerProvider/WechatServiceProvider.php | 31 +++++++++++-------- src/Wechat/Work/Base.php | 8 ++++- src/Wechat/Work/Miniprogram.php | 18 +++++++++++ 3 files changed, 43 insertions(+), 14 deletions(-) create mode 100644 src/Wechat/Work/Miniprogram.php diff --git a/src/Wechat/ServerProvider/WechatServiceProvider.php b/src/Wechat/ServerProvider/WechatServiceProvider.php index 6e50a7d..c482469 100644 --- a/src/Wechat/ServerProvider/WechatServiceProvider.php +++ b/src/Wechat/ServerProvider/WechatServiceProvider.php @@ -3,37 +3,42 @@ namespace Wechat\ServiceProvider; use Illuminate\Support\ServiceProvider; +use Wechat\Work\Miniprogram; class WechatServiceProvider extends ServiceProvider { - public function setupConfig() + public function boot() { - $source = realpath(__DIR__ . '/../../config/wx.php'); + } - if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) { - $this->publishes([$source => config_path('wx.php')], 'wx'); - } elseif ($this->app instanceof LumenApplication) { - $this->app->configure('wx'); - } + protected function setupConfig() + { + $source = realpath(dirname(__DIR__) . '/../../config/wx.php'); - $this->mergeConfigFrom($source, 'rpc'); +// if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) { +// $this->publishes([$source => config_path('wx.php')], 'wx'); +// } elseif ($this->app instanceof LumenApplication) { + $this->app->configure('wx'); +// } +// + $this->mergeConfigFrom($source, 'wx'); } public function register() { - $config = config['wx']; - + $this->setupConfig(); + $config = config('wx'); if (isset($config['work'])) { foreach ($config['work']['secrets'] as $key => $item) { - $this->app->singleton('wx.work.' . $key, function () { - return new ucwords($key); + $this->app->singleton('wx.work.' . $key, function () use ($key) { + $class = ucwords($key); + return new $class ; }); } } - } } \ No newline at end of file diff --git a/src/Wechat/Work/Base.php b/src/Wechat/Work/Base.php index 238e0bb..f8dd6a4 100644 --- a/src/Wechat/Work/Base.php +++ b/src/Wechat/Work/Base.php @@ -24,7 +24,13 @@ class Base { $uri = new Uri($uri); $uri = Uri::withQueryValue($uri, 'access_token', $this->getAccessToken()); - $request = new Request($method, $uri, [], \GuzzleHttp\json_encode($params)); + if (!empty($params)) { + $body = \GuzzleHttp\json_encode($params); + } else { + $body = null; + } + + $request = new Request($method, $uri, [], $body); return $request; } diff --git a/src/Wechat/Work/Miniprogram.php b/src/Wechat/Work/Miniprogram.php new file mode 100644 index 0000000..40d0c73 --- /dev/null +++ b/src/Wechat/Work/Miniprogram.php @@ -0,0 +1,18 @@ +client->transformForJsonRequest($url); + $resp = $this->client->send($request); + return json_decode($resp->getBody(), true); + } + +} \ No newline at end of file