thomaswiener/client-amsbus

amsbus 预订客户端

dev-master 2014-11-21 15:12 UTC

This package is not auto-updated.

Last update: 2024-09-24 02:49:21 UTC


README

通用

关于

此包是 AmsBus (RO) Web 服务 (SOAP) 的 PHP 客户端实现。它基于以下位置的 Web 服务描述:在此插入文档

以下列出了不同端点示例调用。

安装

通过 composer 安装。

在您的 composer.json 中添加 "thomaswiener/client-amsbus": "dev-master" 并更新 vendors。

源代码

设置

$loader = require_once __DIR__ . "/./vendor/autoload.php";

$config = array(
    'url'                   => 'https://eshopcv.amsbus.cz:8443/',
    'id'                    => 'xxxxxxxxxxxxx',
    'version'               => 'v1',
    'sslVerifcationEnabled' => false
);

$client            = new \AmsBusClient\Client($config);
$stationService    = new \AmsBusClient\Endpoint\Station($client);
$connectionService = new \AmsBusClient\Endpoint\Connection($client);
$seatService       = new \AmsBusClient\Endpoint\Seat($client);
$ticketService     = new \AmsBusClient\Endpoint\Ticket($client);

originCode       = 'Praha [*CZ]';
$destinationCode = 'Brno [*CZ]';
$pax             = ['John Doe', 'Jane Doe'];
$tripDate        = (new \DateTime())->setDate(2014, 12, 2);

站点

按字符串搜索

$searchString = "Ber";
$response = $stationService->search($searchString);

连接

搜索

$connectionData = new \AmsBusClient\Data\Connection();
$connectionData
    ->setFrom($originCode)
    ->setTo($destinationCode)
    ->setTripDate($tripDate);

$response = $connectionService->search($connectionData);
$handle = $response->getData()->handle;

获取信息

foreach ($response->getData()->connections as $index => $connection) {
    break;
}
$urlParams = [$handleId, $indexId];

$response = $connectionService->getInfo($urlParams);

座位

锁定

$response = $seatService->block(array(), $urlParams);

解锁

$response = $seatService->unblock(array(), $urlParams);

票务

创建

$urlParams = [$ticketHandle]; #from response

$additionalInfo = new \AmsBusClient\Data\AdditionalInfo();
foreach ($tickets as $index => $ticket) {
    $passenger = new \AmsBusClient\Data\Passenger();
    $passenger->setName('John Doe');
    $passenger->setTicketIdx($index);   //the ticket index in the array (probably)
    $additionalInfo->addPassenger($passenger);
}

$response = $ticketService->create($additionalInfo, $urlParams);
$ticket = $response->getData();

获取

$response = $ticketService->get($ticketHandle);

取消

$response = $ticketService->cancel($ticketHandle);

退款

foreach ($tickets as $ticket) {
    $transCode = $ticket->transCode;
    $operation = \AmsBusClient\Endpoint\Interfaces\TicketInterface::OPERATION_THERE;
    $response = $ticketService->refund($transCode, $operation);
    $refundHandles[] = $response->getData()->refundHandle;
}

退款取消

foreach ($refundHandles as $refundHandle) {
    $response = $ticketService->refundCancel($refundHandle);
}

退款确认

foreach ($refundHandles as $refundHandle) {
    $response = $ticketService->refundConfirm($refundHandle);
}