Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

小程序发货信息管理服务 #2772

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
144 changes: 144 additions & 0 deletions src/MiniProgram/Shipping/Client.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?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' => $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' => $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);
};
}
}
162 changes: 162 additions & 0 deletions tests/MiniProgram/Shipping/ClientTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
<?php

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);

$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', $data)->andReturn('mock-result');

$this->assertSame('mock-result', $client->uploadShippingInfo($data));

}

public function testUploadCombineShippingInfo()
{
$client = $this->mockApiClient(Client::class);

$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', $data)->andReturn('mock-result');

$this->assertSame('mock-result', $client->uploadCombineShippingInfo($data));
}

public function testGetOrder()
{
$client = $this->mockApiClient(Client::class);

$params = [
'transaction_id' => '42000020212023112332159214'
];

$client->expects()->httpPostJson('wxa/sec/order/get_order', $params)->andReturn('mock-result');
$this->assertSame('mock-result', $client->getOrder($params));
}

public function testGetOrderList()
{
$client = $this->mockApiClient(Client::class);

$data = [];

$client->expects()->httpPostJson('wxa/sec/order/get_order_list', $data)->andReturn('mock-result');

$this->assertSame('mock-result', $client->getOrderList($data));
}

public function testNotifyConfirmReceive()
{
$client = $this->mockApiClient(Client::class);

$data = [
'transaction_id' => '42000020212023112332159214xx',
'received_time' => ''
];

$client->expects()->httpPostJson('wxa/sec/order/notify_confirm_receive', $data)->andReturn('mock-result');

$this->assertSame('mock-result', $client->notifyConfirmReceive($data));
}

public function testSetMsgJumpPath()
{
$client = $this->mockApiClient(Client::class);

$data = [
'path' => 'pages/not-found',
];

$client->expects()->httpPostJson('wxa/sec/order/set_msg_jump_path', $data)->andReturn('mock-result');

$this->assertSame('mock-result', $client->setMsgJumpPath('pages/not-found'));
}

public function testIsTradeManaged()
{
$client = $this->mockApiClient(Client::class);

$data = [
'appid' => '123',
];

$client->expects()->httpPostJson('wxa/sec/order/is_trade_managed', $data)->andReturn('mock-result');

$this->assertSame('mock-result', $client->isTradeManaged('123'));
}

public function testIsTradeCompleted()
{
$client = $this->mockApiClient(Client::class);

$data = [
'appid' => '123',
];

$client->expects()->httpPostJson('wxa/sec/order/is_trade_management_confirmation_completed', $data)->andReturn('mock-result');

$this->assertSame('mock-result', $client->isTradeCompleted('123'));
}
}
Loading