tourcms / tourcms-php
PHP TourCMS API 封装器
v4.9.0
2024-09-23 13:58 UTC
Requires
- php: >=8.1
- dev-main
- v4.9.0
- v4.8.0
- v4.7.0
- v4.6.0
- v4.5.0
- v4.4.0
- v4.3.0
- v4.2.0
- v4.1.1
- v4.1.0
- v4.0.0
- v3.14.0
- v3.13.0
- v3.12.0
- v3.11.0
- v3.10.0
- v3.9.2
- v3.9.1
- v3.9.0
- v3.8.0
- v3.7.0
- v3.6.1
- v3.6.0.x-dev
- v3.6.0
- v3.5.0.x-dev
- 3.5.0
- v3.4.0.x-dev
- 3.4.0
- 3.3.0.x-dev
- 3.3.0
- dev-master / 3.2.x-dev
- v3.2.0.x-dev
- 3.2.0
- v3.1.0.x-dev
- 3.1.0
- v3.0.7
- v3.0.6
- v3.0.5
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- 1.x-dev
- v1.8.3
- v1.8.2
- v1.8.1
- v1.8
- dev-release/4.9.0
- dev-feature/TOURCMS-9676-named-tickets-fixes
- dev-feature/TOURCMS-9400-importer-get-tour-facets-api-endpoint
- dev-epic/TOURCMS-8898-tour-pickup-members-crud
- dev-feature/TOURCMS-9050-update-pickup-in-a-route-endpoint
- dev-epic/TOURCMS-7996_Universal-tour-importer
- dev-feature/TOURCMS-8372
- dev-feature/TOURCMS-7550-add-user-agent-support-to-php-wrapper-rebase
- dev-release/v4.0.0
- dev-epic/TOURCMS-8185_Show-markup-scheme-endpoint
- dev-release/3.12.0
- dev-feature/TOURCMS-7595-update-channel
- dev-release/3.11.0
- dev-release/3.9.3
- dev-feature/TOURCMS-3601
- dev-release/3.8.0
- dev-feature/TOURCMS-678_payworks_create_payment_endpoint
- dev-release/3.7.0
- dev-feature/TOURCMS-3107_listorders_build_new_booking_search_endpoint
- dev-release/3.6.1
- dev-feature/TOURCMS-3101
- dev-release/3.6.0
- dev-feature/TOURCMS-2707
- dev-release/3.5.0
- dev-feature/TOURCMS-2502_Spreedly-complete
- dev-release/3.4.0
- dev-release/3.3.0
- dev-feature/TOURCMS-1984_Method-for-endpoint-change
- dev-release/3.2.0
- dev-feature/TOURCMS-1970
- dev-feature/TOURCMS-851_US_add_documentation
This package is auto-updated.
Last update: 2024-09-23 14:01:14 UTC
README
安装
通过 Composer 安装(推荐)
- 安装 Composer,将
"tourcms/tourcms-php": "4.*",
添加到您的composer.json
文件的requires
部分 - 确保您包含了 composer 的
autoload.php
,或者直接包含TourCMS.php
。
手动安装
- 下载源代码 zip 文件,解压到您的 web 服务器
- 在您的源代码中包含
TourCMS.php
从版本 1.x 升级
如果您是从库的版本 1.x 升级,最新的 TourCMS.php
应该基本上是直接替换。主要的变化是,为了遵守 PHP PSR-4 标准,类现在是命名空间化的。总的来说,有两种不同的方式来更新现有的代码以考虑这一点
命名空间别名
如果您已经有一个包含 TourCMS.php
的全局包含文件,您可以在 TourCMS.php
之后立即添加以下行
use TourCMS\Utils\TourCMS as TourCMS;
您现有的代码应该能够正常工作,例如,当您创建 TourCMS 类的新实例时,您将会有
$tourcms = new TourCMS(0, 'YOUR_PASSWORD', 'simplexml');
使用完全限定名
或者,在创建类的新的实例时使用完全限定名
$tourcms = new TourCMS\Utils\TourCMS(0, 'YOUR_PASSWORD', 'simplexml');
用法
// Common configuration parameters // Marketplace ID will be 0 for Tour Operators, non-zero for Marketplace Agents // Agents can find their Marketplace ID in the API page in TourCMS settings $marketplace_id = 0; // API key will be a string, find it in the API page in TourCMS settings $api_key = "YOUR_KEY_HERE"; // Timeout will set the maximum execution time, in seconds. If set to zero, no time limit is imposed. $timeout = 0; // Channel ID represents the Tour Operator channel to call the API against // Tour Operators may have multiple channels, so enter the correct one here // Agents can make some calls (e.g. tour_search()) across multiple channels // by entering a Channel ID of 0 or omitting it, or they can restrict to a // specific channel by providing the Channel ID $channel_id = 0; // Create a new TourCMS instance // Optionally alias the namespace use TourCMS\Utils\TourCMS as TourCMS; $tourcms = new TourCMS($marketplace_id, $api_key, 'simplexml', $timeout); // 'simplexml' returns as a SimpleXMLObject // 'raw' returns the XML as as String // Set a User-Agent $tourcms->set_user_agent('Example Tours Website'); // Call the API // Here as a quick example we search for some tours $result = $tourcms->search_tours('', $channel_id); // Display the output print_r($result);
更多示例
tourcms.com 上的 API 文档
在 TourCMS API 文档 中的每个 API 方法都包括完整的 PHP 示例代码。
此存储库中的示例
此外,此存储库中还包括了一些示例,要运行它们
- 将
src/examples
目录复制到您的 web 根目录 - 将
examples/config-example.php
重命名为examples/config.php
- 在配置文件中加载您的 API 凭据,并确保
TourCMS.php
的路径正确 - 将您的网络浏览器指向示例文件夹
环境测试
库可以尝试检查您的本地环境和 API 凭据,如果您遇到连接问题很有用。首先,请确保您包含了 TourCMS.php
,无论是通过自动加载还是显式包含。
// Common configuration parameters // Marketplace ID will be 0 for Tour Operators, non-zero for Marketplace Agents // Agents can find their Marketplace ID in the API page in TourCMS settings $marketplace_id = 0; // API key will be a string, find it in the API page in TourCMS settings $api_key = "YOUR_KEY_HERE"; // Channel ID represents the Tour Operator channel to call the API against // Tour Operators may have multiple channels, so enter the correct one here // Agents can leave this as 0 for the test $channel_id = 0; // Create a new TourCMS instance // Optionally alias the namespace use TourCMS\Utils\TourCMS as TourCMS; $tourcms = new TourCMS($marketplace_id, $api_key, "simplexml"); // Call the environment test, the results will be displayed on the screen $tourcms->test_environment($channel_id);
响应头
TourCMS 在响应头中返回一些有用的信息。PHP 封装器中有一个方法可以检索最后一组响应头。
$headers = $tourcms->get_last_response_headers(); $remaining_limit = $headers["x-ratelimit-remaining"];
设置 User-Agent
设置 User-Agent 头。当尝试确定正在发出 API 调用的应用程序或进程时很有用。
$tourcms->set_user_agent("Example Tours Website");
设置 X-Request-Identifier
将 uuid 或其他 id 设置到请求中。对于跟踪/日志记录很有用。应该是伪随机/唯一的,例如 UUID。
$tourcms->set_request_identifier("98b41172-4db9-464e-9db8-f31ae92ffbab");
覆盖基本 URL
默认情况下,基本 URL 将指向 TourCMS 主要的生产环境。有一个方法可以覆盖它以指向另一个基本 URL,这主要用于测试目的。
$tourcms->set_base_url("https://api.example.com");