Skip to content

Commit

Permalink
小程序发货信息管理服务
Browse files Browse the repository at this point in the history
  • Loading branch information
fireqong committed Dec 14, 2023
1 parent 1c31e82 commit 2e2ed06
Show file tree
Hide file tree
Showing 4 changed files with 350 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/MiniProgram/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ class Application extends ServiceContainer
Shop\Delivery\ServiceProvider::class,
Shop\Aftersale\ServiceProvider::class,
Business\ServiceProvider::class,

Shipping\ServiceProvider::class,
];

/**
Expand Down
145 changes: 145 additions & 0 deletions src/MiniProgram/Shipping/Client.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<?php

namespace EasyWeChat\MiniProgram\Shipping;

use EasyWeChat\Kernel\BaseClient;

class Client extends BaseClient
{
/**
* 发货信息录入接口
*
* @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 uploadShippingInfo(array $params)
{
return $this->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);
}
}
17 changes: 17 additions & 0 deletions src/MiniProgram/Shipping/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace EasyWeChat\MiniProgram\Shipping;

use Pimple\Container;
use Pimple\ServiceProviderInterface;

class ServiceProvider implements ServiceProviderInterface
{

public function register(Container $app)
{
$app['shipping'] = function ($app) {
return new Client($app);
};
}
}
186 changes: 186 additions & 0 deletions tests/MiniProgram/Shipping/ClientTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
<?php

/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <i@overtrue.me>
*
* 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));
}
}

0 comments on commit 2e2ed06

Please sign in to comment.