myallocator / myallocator-php-sdk-ota
PHP SDK 用于轻松集成 MyAllocator OTA BuildToUs API
Requires
- php: >=5.3.2
Requires (Dev)
- phpunit/phpunit: 4.0.*
This package is not auto-updated.
Last update: 2024-09-20 22:01:14 UTC
README
MyAllocator BuildToUs API PHP SDK (JSON)。在线旅游代理(OTA)可以使用此 SDK 快速可靠地集成 MyAllocator BuildToUs API,以便将其系统进行分销。
MyAllocator BuildToUs API 支持许多 OTA 入站 API,但只支持一个 OTA 出站 API(NotifyBooking)。因此,此 SDK 当前仅实现了 MyAllocator BuildToUs API 文档中定义的 OTA 入站 API。您可以直接在代码库中实现简单的 HTTP GET NotifyBooking API。
注意,这不是 PMS PHP SDK。PMS PHP SDK 可以在 https://github.com/MyAllocator/myallocator-pms-php 找到
MyAllocator BuildToUs API 版本:201503
MyAllocator BuildToUs API 文档 & 集成指南 [待办事项]
MyAllocator BuildToUs API PHP SDK 文档 [http://myallocator.github.io/myallocator-ota-php-docs/]
MyAllocator [https://www.myallocator.com/]
MyAllocator 开发支持 [devhelp@myallocator.com]
需求
PHP 5.3.2 及以上版本。
文档
请参阅 http://myallocator.github.io/myallocator-ota-php-docs/ 以获取完整和最新的 SDK 文档。
Composer 安装
您可以通过 composer 安装。将以下内容添加到项目中的 composer.json
。
{
"require": {
"myallocator/myallocator-php-sdk-ota": "1.*"
}
}
然后通过以下方式安装
composer.phar install
要使用绑定,请使用 Composer 的自动加载 [https://getcomposer.org.cn/doc/00-intro.md#autoloading]
require_once('vendor/autoload.php');
或手动
require_once('/path/to/vendor/MyAllocator/myallocator-php-sdk-ota/src/MyAllocator.php');
手动安装
获取 SDK 的最新版本
git clone https://github.com/MyAllocator/myallocator-ota-php.git
要使用绑定,请将以下内容添加到 PHP 脚本中
require_once('/path/to/myallocator-ota-php/src/MyAllocator.php');
入门指南
使用 composer 安装的安装和使用示例
root@nate:/var/www# mkdir test
root@nate:/var/www# cd test/
root@nate:/var/www/test# echo '{"require": {"myallocator/myallocator-php-sdk-ota": "1.*"}}' > composer.json
root@nate:/var/www/test# composer install
Loading composer repositories with package information
Installing dependencies (including require-dev)
- Installing myallocator/myallocator-php-sdk-ota (1.0.0)
Downloading: 100%
Writing lock file
Generating autoload files
root@nate:/var/www/test# cp vendor/myallocator/myallocator-php-sdk-ota/examples/Receiver/* .
在所需端点配置主机的 web 服务器,将其指向 /var/www/test/MaReceiver.php。发送健康检查 :)
root@nate:/var/www/test# curl -v -H "Accept: application/json" -X POST -H "Content-Type: application/json" -d '{"verb":"HealthCheck", "mya_property_id":"123", "ota_property_id":"321", "shared_secret":"test"}' http://{your_ip}:{your_port}/
{"success":true,"errors":null}
使用手动安装的安装和使用示例
root@nate:/var/www# mkdir -p test/lib
root@nate:/var/www# cd test/lib/
root@nate:/var/www/test/lib# git clone https://github.com/MyAllocator/myallocator-ota-php.git
Cloning into 'myallocator-ota-php'...
remote: Counting objects: 111, done.
remote: Compressing objects: 100% (72/72), done.
remote: Total 111 (delta 38), reused 101 (delta 31), pack-reused 0
Receiving objects: 100% (111/111), 38.22 KiB | 0 bytes/s, done.
Resolving deltas: 100% (38/38), done.
Checking connectivity... done.
root@nate:/var/www/test/lib# cd ..
root@nate:/var/www/test# cp lib/myallocator-ota-php/examples/Receiver/* .
将第 12 行的 require_once 自动加载更改为
require_once(dirname(__FILE__) . '/lib/myallocator-ota-php/src/MyAllocator.php');
在所需端点配置主机的 web 服务器,将其指向 /var/www/test/MaReceiver.php。发送健康检查 :)
root@nate:/var/www/test# curl -v -H "Accept: application/json" -X POST -H "Content-Type: application/json" -d '{"verb":"HealthCheck", "mya_property_id":"123", "ota_property_id":"321", "shared_secret":"test"}' http://{your_ip}:{your_port}/
{"success":true,"errors":null}
配置
默认配置文件位于 src/MyAllocator/Config/MaConfig.php
。以下是可以配置的
shared_secret
MyAllocator 在初始注册后将为 OTA 分配 shared_secret。shared_secret 用于验证 MA <-> OTA 通信。
debugsEnabled
将 debugsEnabled
设置为 true 在 src/MyAllocator/Config/Config.php
中以在 SDK 界面中显示请求和响应数据以及 API 请求的传输数据格式。
集成
此 SDK 旨在安装在 OTA 的环境中,作为 MyAllocator 的入站 API 接收器。它不是 BuildToUs API 集成的必需品,但是,如果 OTA 通过 PHP 集成,我们强烈建议利用 SDK 以最小化集成时间和成本。
SDK 由三个主要部分组成:接收器、SDK 库和后端接口(由 OTA 实现)。
接收器
接收器位于 examples/Receiver/MaReceiver.php
,是实际端点脚本,用于接收请求并将其转发到 SDK 库。OTA 使用此接收器是可选的。如果您已经有了用于公开端点的现有框架,请继续使用它,并像接收器示例一样调用 SDK 库。如果不存在现有机制,并且您需要一个快速解决方案,请随时使用提供的接收器。
SDK 库
SDK 库位于 src/MyAllocator
,包括入站 API 路由、API 定义、后端接口定义和所需的基础设施。
后端接口
SDK 库包括一个位于 src/MyAllocator/Api/Inbound/MaInboundInterface.php
的后端接口定义,您的环境必须实现该接口,以便路由器(MaRouter.php
)可以将请求转发到您的后端系统。您必须实例化实现此接口的类的一个对象,并在实例化过程中将其传递给 MaRouter 对象的构造函数。请参阅 examples/Receiver/MaInboundInterfaceStub.php
以获取示例接口实现,以及 examples/Receiver/MaReceiver.php
了解如何实例化和将其传递给 MaRouter。
特别需要注意的是,后端接口实现必须向调用路由器返回一个 MaResponse 对象(如文档块所述)。
示例
示例可以在 examples/
目录中找到。
测试
您可以从顶级目录运行 phpunit 测试。
vendor/bin/phpunit --debug