From 2e2ed06081fa94e2864b5014c0ca02663c202caf Mon Sep 17 00:00:00 2001 From: church Date: Thu, 14 Dec 2023 18:40:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E5=8F=91=E8=B4=A7?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E7=AE=A1=E7=90=86=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MiniProgram/Application.php | 2 + src/MiniProgram/Shipping/Client.php | 145 +++++++++++++++ src/MiniProgram/Shipping/ServiceProvider.php | 17 ++ tests/MiniProgram/Shipping/ClientTest.php | 186 +++++++++++++++++++ 4 files changed, 350 insertions(+) create mode 100644 src/MiniProgram/Shipping/Client.php create mode 100644 src/MiniProgram/Shipping/ServiceProvider.php create mode 100644 tests/MiniProgram/Shipping/ClientTest.php diff --git a/src/MiniProgram/Application.php b/src/MiniProgram/Application.php index d012c2b7e..d751dd7c6 100644 --- a/src/MiniProgram/Application.php +++ b/src/MiniProgram/Application.php @@ -105,6 +105,8 @@ class Application extends ServiceContainer Shop\Delivery\ServiceProvider::class, Shop\Aftersale\ServiceProvider::class, Business\ServiceProvider::class, + + Shipping\ServiceProvider::class, ]; /** diff --git a/src/MiniProgram/Shipping/Client.php b/src/MiniProgram/Shipping/Client.php new file mode 100644 index 000000000..54e37d4f4 --- /dev/null +++ b/src/MiniProgram/Shipping/Client.php @@ -0,0 +1,145 @@ +httpPostJson('/wxa/sec/order/upload_shipping_info', $params); + } + + /** + * 发货信息合单录入接口 + * + * @param array $params + * + * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string + * + * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public function uploadCombineShippingInfo(array $params) + { + return $this->httpPostJson('/wxa/sec/order/upload_combined_shipping_info', $params); + } + + + /** + * 查询订单发货状态 + * + * @param array $params + * + * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string + * + * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public function getOrder(array $params) + { + return $this->httpPostJson('/wxa/sec/order/get_order', $params); + } + + /** + * 查询订单列表 + * + * @param array $params + * + * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string + * + * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public function getOrderList(array $params = []) + { + return $this->httpPostJson('/wxa/sec/order/get_order_list', $params); + } + + /** + * 确认收货提醒接口 + * + * @param array $params + * + * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string + * + * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public function notifyConfirmReceive(array $params) + { + return $this->httpPostJson('/wxa/sec/order/notify_confirm_receive', $params); + } + + /** + * 消息跳转路径设置接口 + * + * @param string $path + * + * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string + * + * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public function setMsgJumpPath(string $path) + { + $params = [ + 'path' => $path + ]; + + return $this->httpPostJson('/wxa/sec/order/set_msg_jump_path', $params); + } + + /** + * 查询小程查询小程序是否已开通发货信息管理服务 + * + * @param string $appID + * + * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string + * + * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public function isTradeManaged(string $appID = '') + { + $config = $this->app->getConfig(); + + $params = [ + 'appid' => empty($appID) ? $config['app_id'] : $appID + ]; + + return $this->httpPostJson('/wxa/sec/order/is_trade_managed', $params); + } + + /** + * 查询小程序是否已完成交易结算管理确认 + * + * @param string $appID + * + * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string + * + * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public function isTradeCompleted(string $appID = '') + { + $config = $this->app->getConfig(); + + $params = [ + 'appid' => empty($appID) ? $config['app_id'] : $appID + ]; + + return $this->httpPostJson('/wxa/sec/order/is_trade_management_confirmation_completed', $params); + } +} \ No newline at end of file diff --git a/src/MiniProgram/Shipping/ServiceProvider.php b/src/MiniProgram/Shipping/ServiceProvider.php new file mode 100644 index 000000000..5769c6c2b --- /dev/null +++ b/src/MiniProgram/Shipping/ServiceProvider.php @@ -0,0 +1,17 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace EasyWeChat\Tests\MiniProgram\Shipping; + +use EasyWeChat\MiniProgram\Shipping\Client; +use EasyWeChat\Tests\TestCase; + +class ClientTest extends TestCase +{ + public function testUploadShippingInfo() + { + $client = $this->mockApiClient(Client::class)->makePartial(); + + $data = [ + 'order_key' => [ + 'order_number_type' => 1, + 'transaction_id' => '', + 'mchid' => '', + 'out_trade_no' => '' + ], + 'logistics_type' => 1, + 'delivery_mode' => 1, + 'is_all_delivered' => true, + 'shipping_list' => [ + 'tracking_no' => '323244567777', + 'express_company' => 'DHL', + 'item_desc' => '微信红包抱枕*1个', + 'contact' => [ + 'consignor_contact' => '189****1234, 021-****1234', + 'receiver_contact' => '189****1234' + ], + ], + 'upload_time' => '2022-12-15T13:29:35.120+08:00', + 'payer' => [ + 'openid' => 'oUpF8uMuAJO_M2pxb1Q9zNjWeS6o' + ] + ]; + + $client->expects()->httpPostJson('wxa/sec/order/upload_shipping_info', compact('data'))->andReturn('mock-result'); + + $this->assertSame('mock-result', $client->uploadShippingInfo($data)); + } + + public function uploadCombineShippingInfo() + { + $client = $this->mockApiClient(Client::class)->makePartial(); + + $data = [ + 'order_key' => [ + 'order_number_type' => 1, + 'transaction_id' => '', + 'mchid' => '', + 'out_trade_no' => '' + ], + 'sub_orders' => [ + 'order_key' => [ + 'order_number_type' => 1, + 'transaction_id' => '', + 'mchid' => '', + 'out_trade_no' => '' + ], + 'logistics_type' => 1, + 'delivery_mode' => 1, + 'is_all_delivered' => true, + 'shipping_list' => [ + 'tracking_no' => '323244567777', + 'express_company' => 'DHL', + 'item_desc' => '微信红包抱枕*1个', + 'contact' => [ + 'consignor_contact' => '189****1234, 021-****1234', + 'receiver_contact' => '189****1234' + ], + ], + ], + 'upload_time' => '2022-12-15T13:29:35.120+08:00', + 'payer' => [ + 'openid' => 'oUpF8uMuAJO_M2pxb1Q9zNjWeS6o' + ] + ]; + + $client->expects()->httpPostJson('wxa/sec/order/upload_combined_shipping_info', compact('data'))->andReturn('mock-result'); + + $this->assertSame('mock-result', $client->uploadShippingInfo($data)); + } + + public function testGetOrder() + { + $client = $this->mockApiClient(Client::class)->makePartial(); + + $data = [ + 'transaction_id' => '42000020212023112332159214xx', + 'merchant_id' => '', + 'sub_merchant_id' => '', + 'merchant_trade_no' => '', + ]; + + $client->expects()->httpPostJson('wxa/sec/order/get_order', compact('data'))->andReturn('mock-result'); + + $this->assertSame('mock-result', $client->getOrder($data)); + } + + public function testGetOrderList() + { + $client = $this->mockApiClient(Client::class)->makePartial(); + + $data = [ + 'pay_time_range' => [ + 'begin_time' => 123456789, + 'end_time' => 123456789 + ], + 'order_state' => 1, + 'openid' => '', + 'last_index' => '', + 'page_size' => 100 + ]; + + $client->expects()->httpPostJson('wxa/sec/order/get_order_list', compact('data'))->andReturn('mock-result'); + + $this->assertSame('mock-result', $client->getOrderList($data)); + } + + public function testNotifyConfirmReceive() + { + $client = $this->mockApiClient(Client::class)->makePartial(); + + $data = [ + 'transaction_id' => '42000020212023112332159214xx', + 'merchant_id' => '', + 'sub_merchant_id' => '', + 'merchant_trade_no' => '', + 'received_time' => '' + ]; + + $client->expects()->httpPostJson('wxa/sec/order/notify_confirm_receive', compact('data'))->andReturn('mock-result'); + + $this->assertSame('mock-result', $client->notifyConfirmReceive($data)); + } + + public function testSetMsgJumpPath() + { + $client = $this->mockApiClient(Client::class)->makePartial(); + + $data = [ + 'path' => 'pages/not-found', + ]; + + $client->expects()->httpPostJson('wxa/sec/order/set_msg_jump_path', compact('data'))->andReturn('mock-result'); + + $this->assertSame('mock-result', $client->setMsgJumpPath($data)); + } + + public function testIsTradeManaged() + { + $client = $this->mockApiClient(Client::class)->makePartial(); + + $data = [ + 'appid' => '', + ]; + + $client->expects()->httpPostJson('wxa/sec/order/is_trade_managed', $data)->andReturn('mock-result'); + + $this->assertSame('mock-result', $client->isTradeManaged($data)); + } + + public function testIsTradeCompleted() + { + $client = $this->mockApiClient(Client::class)->makePartial(); + + $data = [ + 'appid' => '', + ]; + + $client->expects()->httpPostJson('wxa/sec/order/is_trade_management_confirmation_completed', $data)->andReturn('mock-result'); + + $this->assertSame('mock-result', $client->isTradeCompleted($data)); + } +}