onlinetravelgroup / ean-client
此包已被弃用,不再维护。未建议替代包。
基于Guzzle的EAN酒店API客户端
0.7.6
2018-03-09 05:49 UTC
Requires
- php: >=5.4
- guzzlehttp/guzzle-services: 0.5.*
Requires (Dev)
- friendsofphp/php-cs-fixer: ^1.11
- guzzlehttp/cache-subscriber: ~0.2@dev
- guzzlehttp/log-subscriber: ~1.0
- phpunit/phpunit: ^5.7||^4.8
README
EAN酒店API的PHP实现。
支持所有API请求和IP及签名认证。内部使用XML请求和响应类型。
使用
每个API服务都由HotelClient
对象上的一个方法表示。每个API方法接受单个数组参数作为参数,并将结果作为数组返回。参数名称和结构符合API规范。
使用HotelClient::factory()
方法实例化HotelClient对象
<?php require 'vendor/autoload.php'; use Otg\Ean\HotelClient; $client = HotelClient::factory([ 'auth' => [ 'cid' => YOUR_CID, 'apiKey' => YOUR_API_KEY, 'secret' => YOUR_API_SECRET, // optional, omit if using IP authentication ], 'defaults' => [ 'bookingEndpoint' => 'http://dev.api.ean.com', 'generalEndpoint' => 'http://dev.api.ean.com', 'customerIpAddress' => getenv('REMOTE_ADDR'), 'customerUserAgent' => getenv('HTTP_USER_AGENT'), ] ]);
示例
酒店列表
http://developer.ean.com/docs/hotel-list
$hotels = $client->getHotelList([ 'destinationString' => 'Montpellier France', 'arrivalDate' => '2016-06-13', 'departureDate' => '2016-06-27', 'RoomGroup' => [ ['numberOfAdults' => 2] ] ]);
房间可用性
http://developer.ean.com/docs/room-avail
$rooms = $client->getRoomAvailability([ 'hotelId' => $hotels['HotelList'][0]['hotelId'], 'arrivalDate' => '2016-06-13', 'departureDate' => '2016-06-27', 'RoomGroup' => [ ['numberOfAdults' => 2] ] ]);
预订房间
http://developer.ean.com/docs/book-reservation
$bedTypes = $rooms['Rooms'][0]['BedTypes']; $smokingPreferences = explode(',', $rooms['Rooms'][0]['smokingPreferences']); $reservation = $client->postReservation([ 'RoomGroup' => [[ 'numberOfAdults' => 2, 'firstName' => 'Test', 'lastName' => 'Test', 'bedTypeId' => key($bedTypes), 'smokingPreference' => $smokingPreferences[0], ]], 'ReservationInfo' => [ 'email' => 'user@example.org', 'firstName' => 'Test', 'lastName' => 'Test', 'homePhone' => '0312345678', 'creditCardType' => 'CA', 'creditCardNumber' => '5401999999999999', 'creditCardIdentifier' => '123', 'creditCardExpirationMonth' => '12', 'creditCardExpirationYear' => '2099' ], 'AddressInfo' => [ 'address1' => 'travelnow', 'city' => 'travelnow', 'stateProvinceCode' => 'VC', 'countryCode' => 'AU', 'postalCode' => '3000' ], 'hotelId' => $rooms['hotelId'], 'arrivalDate' => $rooms['arrivalDate'], 'departureDate' => $rooms['departureDate'], 'supplierType' => $rooms['Rooms'][0]['supplierType'], 'rateKey' => $rooms['Rooms'][0]['RateInfos'][0]['RoomGroup'][0]['rateKey'], 'roomTypeCode' => isset($rooms['Rooms'][0]['roomTypeCode']) ? $rooms['Rooms'][0]['roomTypeCode'] : $rooms['Rooms'][0]['RoomType']['roomCode'], 'rateCode' => $rooms['Rooms'][0]['rateCode'], 'chargeableRate' => $rooms['Rooms'][0]['RateInfos'][0]['ChargeableRateInfo']['total'], 'currencyCode' => $rooms['Rooms'][0]['RateInfos'][0]['ChargeableRateInfo']['currencyCode'] ]);
取消预订
http://developer.ean.com/docs/cancel-reservation
$result = $client->getRoomCancellation([ 'itineraryId' => $reservation['itineraryId'], 'email' => 'user@example.org', 'confirmationNumber' => $reservation['confirmationNumbers'][0] ]); if (isset($result['cancellationNumber'])) { printf("Room cancelled: %s", $result['cancellationNumber']); }
安装
$ composer require onlinetravelgroup/ean-client
要求
- PHP 5.4
- php5-curl (建议,除非您想使用自定义适配器)
贡献
欢迎提交拉取请求。只需确保遵循PSR-1/2编码标准和不要造成混乱。
提交信息应遵循http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html的建议
混乱的提交应被压缩,直到它看起来像是第一次编程时就做得完美。这不一定意味着单个提交。
差异应该是干净的。这意味着只有与提交信息相关的行应该发生变化。
运行测试
$ phpunit
鸣谢
Guzzle做了大部分繁重的工作。这个项目实际上只是一个复杂的Guzzle服务配置。
许可证
MIT