touristesim/touristesim-php-sdk 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

touristesim/touristesim-php-sdk

Composer 安装命令:

composer require touristesim/touristesim-php-sdk

包简介

Official PHP SDK for Tourist eSIM Partner API - Easy integration for resellers and partners

README 文档

README

Official PHP SDK for Tourist eSIM Partner API. Enable easy integration for resellers and partners to manage eSIM plans, orders, and customer data.

Features

  • 🔐 OAuth 2.0 Authentication - Secure Client Credentials flow with automatic token refresh
  • 🚀 Auto-Retry Logic - Exponential backoff with 3 retry attempts on connection failures
  • 📦 Type-Safe Models - Full type casting and helper methods on all models
  • 💾 Token Caching - File-based token cache to reduce OAuth requests (1 per hour)
  • Lazy Loading - Resources initialized on first access for minimal memory footprint
  • 🔄 Pagination Support - Built-in pagination for catalog queries
  • 🎯 Exception Hierarchy - Specific exceptions for different error scenarios (Auth, Validation, RateLimit, etc.)

Requirements

  • PHP 8.1+
  • cURL extension
  • GuzzleHTTP 7.0+

Testing

Run the included test script to verify SDK functionality:

php test_sdk.php

This runs basic tests for SDK instantiation, resource classes, exception handling, and overall structure without making actual API calls.

Installation

Install via Composer:

composer require touristesim/touristesim-php-sdk

Quick Start

Basic Setup

require 'vendor/autoload.php';

use TouristeSIM\Sdk\TouristEsim;

$sdk = new TouristEsim(
    clientId: 'your-client-id',
    clientSecret: 'your-client-secret'
);

// Fetch all plans
$plans = $sdk->plans()->get();
foreach ($plans as $plan) {
    echo $plan['name'] . " - " . $plan['price'] . " " . $plan['currency'] . "\n";
}

Authentication

The SDK handles OAuth 2.0 authentication automatically:

$sdk = new TouristEsim(
    clientId: 'your-client-id',
    clientSecret: 'your-client-secret',
    options: [
        'base_url' => 'https://api.touristesim.net/v1',
        'timeout' => 30,
        'mode' => 'sandbox' // or 'production'
    ]
);

// Token is automatically acquired and cached
// Auto-refresh happens 60 seconds before expiration

API Usage

Plans

// Fetch all plans with filters
$plans = $sdk->plans()->get([
    'country' => 'US',
    'type' => 'global',
    'data_min' => 1024,  // in MB
    'sort_by' => 'price',
    'page' => 1,
    'per_page' => 50
]);

// Get single plan
$plan = $sdk->plans()->find('vietnam_100mb_7days_7e87c5');

// Get plans by country
$usPlans = $sdk->plans()->byCountry('US');

// Get plans by region
$asiaPlans = $sdk->plans()->byRegion('asia');

// Get global plans
$globalPlans = $sdk->plans()->global();

// Validate plan before purchase
$validation = $sdk->plans()->validate(planId: 123, quantity: 5);

Countries

// Get all countries
$countries = $sdk->countries()->all();

// Find country by ISO code
$usa = $sdk->countries()->find('US');

// Search countries
$asian = $sdk->countries()->search('china');

// Get countries by region
$europeanCountries = $sdk->countries()->byRegion('europe');

// Get featured countries
$featured = $sdk->countries()->featured();

Regions

// Get all regional groups
$regions = $sdk->regions()->all();

Orders

// Create order
$order = $sdk->orders()->create([
    'plans' => [
        ['plan_slug' => 'vietnam_100mb_7days_7e87c5', 'quantity' => 1],
    ],
    'customer' => ['email' => 'customer@example.com', 'name' => 'Jane Doe'],
]);

// Get all orders
$orders = $sdk->orders()->all(['status' => 'completed']);

// Get single order by order number
$order = $sdk->orders()->find('PO-260519MKAUVE');

// To request a cancellation or refund, contact Tourist eSIM support

eSIMs

// Get all eSIMs
$esims = $sdk->esims()->all(['status' => 'active']);

// Find eSIM by ICCID
$esim = $sdk->esims()->find('8955001000000000000');

// Check eSIM usage
$usage = $sdk->esims()->usage('8955001000000000000');

// Get available topup packages
$packages = $sdk->esims()->topupPackages('8955001000000000000');

// Purchase topup
$topup = $sdk->esims()->topup(
    iccid: '8955001000000000000',
    packageId: 789
);

// Get setup instructions
$instructions = $sdk->esims()->instructions('8955001000000000000');

// Send setup email
$sdk->esims()->sendEmail('8955001000000000000', 'user@example.com');

Account Balance

// Get account balance
$balance = $sdk->balance()->get();

// Get balance history
$history = $sdk->balance()->history(['limit' => 50]);

Working with Collections

All list responses return Collection objects with helpful methods:

$plans = $sdk->plans()->get();

// Filter
$expensivePlans = $plans->filter(fn($plan) => $plan['price'] > 50);

// Map
$prices = $plans->map(fn($plan) => $plan['price']);

// Sort
$sorted = $plans->sortBy('price');

// Pluck
$names = $plans->pluck('name');

// Iteration
foreach ($plans as $plan) {
    // Use plan
}

Error Handling

The SDK provides specific exceptions for different error scenarios:

use TouristeSIM\Sdk\Exceptions\{
    AuthenticationException,
    ValidationException,
    RateLimitException,
    ResourceNotFoundException,
    ServerException,
    ConnectionException
};

try {
    $plan = $sdk->plans()->find('nonexistent_plan_slug');
} catch (ResourceNotFoundException $e) {
    echo "Plan not found: " . $e->getMessage();
} catch (AuthenticationException $e) {
    echo "Authentication failed: " . $e->getMessage();
} catch (RateLimitException $e) {
    echo "Rate limited. Retry after: " . $e->getRetryAfter() . " seconds";
} catch (ValidationException $e) {
    echo "Validation error: " . json_encode($e->getErrors());
} catch (ConnectionException $e) {
    echo "Connection failed: " . $e->getMessage();
} catch (ServerException $e) {
    echo "Server error: " . $e->getMessage();
}

Configuration Options

$options = [
    'base_url' => 'https://api.touristesim.net/v1', // API base URL
    'timeout' => 30,                                  // Request timeout (seconds)
    'connect_timeout' => 10,                          // Connection timeout (seconds)
    'mode' => 'sandbox',                              // 'sandbox' or 'production'
    'verify_ssl' => true,                             // SSL certificate verification
    'max_retries' => 3,                               // Max retry attempts
];

$sdk = new TouristEsim(
    clientId: 'your-client-id',
    clientSecret: 'your-client-secret',
    options: $options
);

Pagination

Paginated responses include metadata:

$plans = $sdk->plans()->get(['page' => 1, 'per_page' => 50]);

echo "Current page: " . $plans->getCurrentPage();
echo "Total pages: " . $plans->getLastPage();
echo "Total items: " . $plans->getTotal();
echo "Has more: " . ($plans->hasMore() ? 'Yes' : 'No');

// Iterate through paginated results
foreach ($plans as $plan) {
    // Process plan
}

Token Management

Tokens are automatically managed:

// Tokens are cached in sys_get_temp_dir()
// Cache file: tourist_esim_token_[hash].json
// Permissions: 0600 (owner-only readable)

// Token is automatically refreshed when expired (60-second buffer)
// No manual token management required

Debugging

Enable detailed logging by catching exceptions:

try {
    $plans = $sdk->plans()->get();
} catch (\Exception $e) {
    echo "Error code: " . $e->getCode() . "\n";
    echo "Error message: " . $e->getMessage() . "\n";
    
    if (method_exists($e, 'getResponse')) {
        echo "Response body: " . $e->getResponse() . "\n";
    }
}

API Documentation

For complete API documentation, visit:

Support

For issues or questions:

License

MIT License - see LICENSE file for details

Changelog

v1.0.0 (2026-02-18)

  • Initial public release
  • OAuth 2.0 authentication with auto-refresh
  • Plans, Countries, Regions, Orders, eSIMs resources
  • Auto-retry with exponential backoff
  • Token caching
  • Collection support with filtering and mapping
  • Comprehensive error handling

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

touristesim/touristesim-php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 24
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-18