voximplant/apiclient-php

Voximplant PHP API客户端库。Voximplant是一个为企业和开发者提供的云通信平台

v2.10.0 2024-08-22 12:46 UTC

README

版本 2.10.0

先决条件

为了使用Voximplant PHP SDK,您需要以下内容

  1. 开发者账户。如果没有,请在此处注册
  2. 私有API密钥。有两种方式可以获取它
    1. 或者,在Voximplant控制面板中生成
    2. 或者,使用指定的CreateKey HTTP API方法进行调用,并使用认证参数。您将收到包含结果字段的响应。将结果值保存在文件中(因为我们不存储密钥,请将其安全地保存在您的端上)。

如何使用

要通过Composer安装绑定,请将以下内容添加到composer.json

{
  "require": {
    "voximplant/apiclient-php": "*@dev"
  }
}

然后运行

composer install

接下来,指定包含结果值的文件的路径,在构造函数中或在环境中指定。

构造函数:

$voxApi = new VoximplantApi('path/to/private/api/key.json');

环境:

$_ENV['VOXIMPLANT_CREDENTIALS_PATH'] = 'path/to/private/api/key.json';

从现在起,您可以使用SDK方法。

示例

启动场景

use Voximplant\VoximplantApi;
use Voximplant\Resources\Params\StartScenariosParams;

// Create API Object
$voxApi = new VoximplantApi('path/to/private/api/key.json');

/**
 * @param array $params (See below)
 * rule_id - The rule ID.
 * script_custom_data - The script custom data (like a script argument). Can be accessed in JS scenario via the VoxEngine.customData() method
 */
$params = new StartScenariosParams();

$params->rule_id = 1;
$params->script_custom_data = 'mystr';

// Start the scripts from the account.
$result = $voxApi->Scenarios->StartScenarios($params);

// Show result
print_r($result);

发送短信

use Voximplant\VoximplantApi;
use Voximplant\Resources\Params\SendSmsMessageParams;

// Create API Object
$voxApi = new VoximplantApi('path/to/private/api/key.json');

/**
 * @param array $params (See below)
 * source - The source phone number.
 * destination - The destination phone number.
 * sms_body - The message.
 */
$params = new SendSmsMessageParams();

$params->source = '447443332211';
$params->destination = '447443332212';
$params->sms_body = 'Test message';

// Send the SMS message with text "Test message" from the phone number 447443332211 to the phone number 447443332212.
$result = $voxApi->SMS->SendSmsMessage($params);

// Show result
print_r($result);

获取通话历史记录项

use Voximplant\VoximplantApi;
use Voximplant\Resources\Params\GetCallHistoryParams;

// Create API Object
$voxApi = new VoximplantApi('path/to/private/api/key.json');

/**
 * @param array $params (See below)
 * from_date - The from date in the selected timezone in 24-h format: YYYY-MM-DD HH:mm:ss
 * to_date - The to date in the selected timezone in 24-h format: YYYY-MM-DD HH:mm:ss
 * count - The max returning record count.
 * timezone - The selected timezone or the 'auto' value (will be used the account location).
 */
$params = new GetCallHistoryParams();

$params->from_date = '2012-01-01 00:00:00';
$params->to_date = '2014-01-01 00:00:00';
$params->count = 1;
$params->timezone = 'Etc/GMT';

// Get the first call session history record from the 2012-01-01 00:00:00 UTC to the 2014-01-01 00:00:00 UTC
$result = $voxApi->History->GetCallHistory($params);

// Show result
print_r($result);

获取交易历史记录

use Voximplant\VoximplantApi;
use Voximplant\Resources\Params\GetTransactionHistoryParams;

// Create API Object
$voxApi = new VoximplantApi('path/to/private/api/key.json');

/**
 * @param array $params (See below)
 * from_date - The from date in the selected timezone in 24-h format: YYYY-MM-DD HH:mm:ss
 * to_date - The to date in the selected timezone in 24-h format: YYYY-MM-DD HH:mm:ss
 * count - The max returning record count.
 * transaction_type - The transaction type list. The following values are possible: periodic_charge, resource_charge, money_distribution, subscription_charge, subscription_installation_charge, card_periodic_payment, card_overrun_payment, card_payment, robokassa_payment, gift, add_money, subscription_cancel, adjustment, wire_transfer, refund.
 * timezone - The selected timezone or the 'auto' value (will be used the account location).
 */
$params = new GetTransactionHistoryParams();

$params->from_date = '2012-01-01 00:00:00';
$params->to_date = '2014-01-01 00:00:00';
$params->count = 3;
$params->transaction_type = array (
    0 => 'gift',
    1 => 'money_distribution',
);
$params->timezone = 'Etc/GMT';

// Get the three transactions record from the 2012-01-01 00:00:00 UTC to the 2014-01-01 00:00:00 UTC with the 'gift' or 'money_distribution' types.
$result = $voxApi->History->GetTransactionHistory($params);
 
// Show result
print_r($result);