From 5e0cb027af3232b4a8878e98b0a3e33818993146 Mon Sep 17 00:00:00 2001 From: yansongda Date: Sat, 23 Nov 2024 11:28:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E5=88=86=E8=B4=A6=E7=94=B3=E8=AF=B7=E5=88=86=E8=B4=A6=E8=B4=A6?= =?UTF-8?q?=E5=8D=95=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 +++ .../V3/Extend/ProfitSharing/GetBillPlugin.php | 47 +++++++++++++++++ .../ProfitSharing/GetBillPluginTest.php | 50 +++++++++++++++++++ web/docs/v3/wechat/all.md | 2 +- 4 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 src/Plugin/Wechat/V3/Extend/ProfitSharing/GetBillPlugin.php create mode 100644 tests/Plugin/Wechat/V3/Extend/ProfitSharing/GetBillPluginTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 34b15e9e9..e5d313da5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v3.7.11 + +### added + +- feat: 新增微信分账申请分账账单插件 (#1041) + ## v3.7.10 ### fixed diff --git a/src/Plugin/Wechat/V3/Extend/ProfitSharing/GetBillPlugin.php b/src/Plugin/Wechat/V3/Extend/ProfitSharing/GetBillPlugin.php new file mode 100644 index 000000000..09bac2d44 --- /dev/null +++ b/src/Plugin/Wechat/V3/Extend/ProfitSharing/GetBillPlugin.php @@ -0,0 +1,47 @@ + $rocket]); + + $payload = $rocket->getPayload(); + + if (is_null($payload)) { + throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 分账 申请账单,参数为空'); + } + + $query = filter_params($payload)->query(); + + $rocket->setPayload([ + '_method' => 'GET', + '_url' => 'v3/profitsharing/bills?'.$query, + '_service_url' => 'v3/profitsharing/bills?'.$query, + ]); + + Logger::info('[Wechat][V3][Extend][ProfitSharing][GetBillPlugin] 插件装载完毕', ['rocket' => $rocket]); + + return $next($rocket); + } +} diff --git a/tests/Plugin/Wechat/V3/Extend/ProfitSharing/GetBillPluginTest.php b/tests/Plugin/Wechat/V3/Extend/ProfitSharing/GetBillPluginTest.php new file mode 100644 index 000000000..e867b3b2a --- /dev/null +++ b/tests/Plugin/Wechat/V3/Extend/ProfitSharing/GetBillPluginTest.php @@ -0,0 +1,50 @@ +plugin = new GetBillPlugin(); + } + + public function testEmptyPayload() + { + $rocket = new Rocket(); + + self::expectException(InvalidParamsException::class); + self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING); + self::expectExceptionMessage('参数异常: 分账 申请账单,参数为空'); + + $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + } + + public function testNormal() + { + $rocket = new Rocket(); + $rocket->setPayload(new Collection( [ + "download_url" => "111", + '_t' => 'a', + ])); + + $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); + + self::assertEquals([ + '_method' => 'GET', + '_url' => 'v3/profitsharing/bills?download_url=111', + '_service_url' => 'v3/profitsharing/bills?download_url=111', + ], $result->getPayload()->all()); + } +} diff --git a/web/docs/v3/wechat/all.md b/web/docs/v3/wechat/all.md index fc1e7943c..c65d577b8 100644 --- a/web/docs/v3/wechat/all.md +++ b/web/docs/v3/wechat/all.md @@ -679,7 +679,7 @@ $result = Pay::wechat()->papay([ - 申请分账账单 - `暂无` + `\Yansongda\Pay\Plugin\Wechat\V3\Extend\ProfitSharing\GetBillPlugin` - 下载账单