定制 tourcms/tourcms-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tourcms/tourcms-php

Composer 安装命令:

composer require tourcms/tourcms-php

包简介

TourCMS API wrapper for PHP

关键字:

README 文档

README

Installation

Installing via Composer (Recommended)

  1. Install Composer, add "tourcms/tourcms-php": "4.*", to the requires section of your composer.json:
  2. Ensure you are including composer's autoload.php, alternatively include TourCMS.php directly.

Installing Manually

  1. Download the source zip, extract to your web server
  2. Include TourCMS.php in your source

Upgrading from version 1.x

If you are upgrading from version 1.x of the library the latest TourCMS.php should be more or less a straight swap. The major change being that to adhere to PHP PSR-4 standards, the class is now namespaced. Broadly speaking there are two different ways to update existing code to account for this:

Aliasing the namespace

If you already have a global include file that includes TourCMS.php you could add the following line immediately after TourCMS.php is included:

use TourCMS\Utils\TourCMS as TourCMS;

Your existing code should then work as-is, for example when you create a new instance of the TourCMS class you would have:

$tourcms = new TourCMS(0, 'YOUR_PASSWORD', 'simplexml');

Using the fully qualified name

Alternatively use the fully qualified name when you create a new instance of the class:

$tourcms = new TourCMS\Utils\TourCMS(0, 'YOUR_PASSWORD', 'simplexml');

Usage

// 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);

Further Examples

API documentation on tourcms.com

Each API method in the TourCMS API documentation includes full PHP sample code.

Examples in this repository

Additionally there are some examples included in this repository, to run them:

  1. Copy the src/examples directory to your web root
  2. Rename examples/config-example.php to examples/config.php
  3. Load your API credentials in the config file and ensure the path to TourCMS.php is correct
  4. Point your web browser at the examples folder

Environment test

The library can attempt to check your local environment and API credentials, useful if you are having trouble connecting. First off make sure you are including TourCMS.php, either via autoload or explicitly.

// 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);

Response headers

TourCMS responds with some useful information in the response headers. There is a method to retrieve the last set of response headers via the PHP wrapper.

$headers = $tourcms->get_last_response_headers();
$remaining_limit = $headers["x-ratelimit-remaining"];

Set User-Agent

Set a User-Agent header. Useful when trying to determine which application or process is making API calls.

$tourcms->set_user_agent("Example Tours Website");

Set X-Request-Identifier

Set a uuid or other id to the request. Useful for tracking/logging. Should be pseudo random / unique, e.g. UUID.

$tourcms->set_request_identifier("98b41172-4db9-464e-9db8-f31ae92ffbab");

Override base URL

By default the base URL will point to TourCMS main production environment. There is a method to override this to point at another base URL, intended for testing purposes.

$tourcms->set_base_url("https://api.example.com");

tourcms/tourcms-php 适用场景与选型建议

tourcms/tourcms-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 129.32k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2015 年 12 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「api」 「tourcms」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 tourcms/tourcms-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 tourcms/tourcms-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 tourcms/tourcms-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 129.32k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 4
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 13
  • Forks: 9
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-12-15