soukicz /
zbozicz
Zboží.cz 转换跟踪
1.3.1
2023-09-11 12:01 UTC
Requires
- php: >=5.6.0
- ext-curl: *
- ext-json: *
- guzzlehttp/psr7: ^1.3|^2.0
Requires (Dev)
- phpstan/phpstan: ~0.9|~0.10|~0.11
- phpunit/phpunit: ~9.5
Suggests
- composer/ca-bundle: Https certificates bundle
README
Zboží.cz 高级转换跟踪
基于 https://github.com/seznam/zbozi-konverze,但增加了更好的集成到大型系统中的功能。命名空间,异步发送订单等。
订单发送
<?php use Soukicz\Zbozicz\Client; use Soukicz\Zbozicz\Order; use Soukicz\Zbozicz\CartItem; $client = new Client(1234567890, "fedcba9876543210123456789abcdef", true); $order = new Order('OBJ21101'); $order ->setEmail('info@example.org') ->setDeliveryType('PPL') ->addCartItem((new CartItem) ->setId('ABC1') ->setName('NAZEV PRODUKTU') ->setUnitPrice(1000) ->setQuantity(2) ) ->addCartItem((new CartItem) ->setId('ABC2') ->setName('NAZEV PRODUKTU') ->setUnitPrice(2000) ); $client->sendOrder($order);
并行发送订单
可以只创建 PSR-7 请求,然后通过 Guzzle 等工具发送数据。这样可以简单地并行批量发送订单。
<?php use Soukicz\Zbozicz\Client; use Soukicz\Zbozicz\Order; use Soukicz\Zbozicz\CartItem; use GuzzleHttp\Psr7\Response; use GuzzleHttp\Client\Pool; $client = new Client(1234567890, "fedcba9876543210123456789abcdef", true); $requests = []; foreach($orders as $order){ $requests[$order->geId()] = $client->createRequest($order); } $httpClient = new \GuzzleHttp\Client(); $pool = new Pool($httpClient, $requests, [ 'concurrency' => 5, 'fulfilled' => function (Response $response, $index) { echo "Order '$index' accepted\n"; }, 'rejected' => function ($reason, $index) { echo "Order '$index' not accepted: " . $reason . "\n"; }, ]);