freeclimbapi/php-sdk

FreeClimb 是一个基于云的应用程序编程接口 (API),将 Vail 平台的力量掌握在你手中。FreeClimb 简化了创建应用程序的过程,这些应用程序可以使用一系列电话功能,而无需专门的或现场的电话设备。使用


README

FreeClimb 是一个基于云的应用程序编程接口 (API),将 Vail 平台的力量掌握在你手中。FreeClimb 简化了创建应用程序的过程,这些应用程序可以使用一系列电话功能,而无需专门的或现场的电话设备。使用 FreeClimb REST API 编写应用程序非常简单!您可以选择使用您喜欢的语言或直接调用 API。您的应用程序可以通过向 FreeClimb API 发送 RESTful 请求来执行命令。向 FreeClimb REST API 发送 HTTP 请求的基本 URL 是:/apiserver。FreeClimb 验证并处理您的请求。

有关更多信息,请访问 https://www.freeclimb.com/support/

安装和用法

要求

PHP 7.3 及更高版本。也应与 PHP 8.0 兼容,但尚未进行测试。

Composer

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

{
  "repositories": [
    {
      "type": "vcs",
      "url": "https://https://github.com/freeclimbapi/php-sdk.git"
    }
  ],
  "require": {
    "freeclimbapi/php-sdk": "*@dev"
  }
}

然后运行 composer install

手动安装

下载文件并包含 autoload.php

<?php
require_once('/path/to/FreeClimbAPI/vendor/autoload.php');

入门

请按照 安装说明 进行操作,然后运行以下命令

<?php
require_once(__DIR__ . '/vendor/autoload.php');



// Configure HTTP basic authorization: fc
$config = FreeClimb\Api\Configuration::getDefaultConfiguration()
              ->setUsername('YOUR_ACCOUNT_ID')
              ->setPassword('YOUR_API_KEY');


$apiInstance = new FreeClimb\Api\Api\DefaultApi(
    // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
    // This is optional, `GuzzleHttp\Client` will be used as default.
    new GuzzleHttp\Client(),
    $config
);
$buy_incoming_number_request = new \FreeClimb\Api\Model\BuyIncomingNumberRequest(); // \FreeClimb\Api\Model\BuyIncomingNumberRequest | Incoming Number transaction details


try {
    $result = $apiInstance->buyAPhoneNumber($buy_incoming_number_request);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling DefaultApi->buyAPhoneNumber: ', $e->getMessage(), PHP_EOL;
}

使用 PerCL

PerclScript 类提供了一个方便的包装器,用于在响应中处理 PerCL 生成。只需使用 json_encode 执行带有 PerclScript 类实例的调用,您就会得到按您需要的方式序列化和格式化的 PerclCommands

<?php
require_once(__DIR__ . '/vendor/autoload.php');

$say = new \FreeClimb\Api\Model\Say();
$sms = new \FreeClimb\Api\Model\Sms();
$script = new \FreeClimb\Api\Model\PerclScript();

$say->setText("hello world");
$sms->setFrom("from number");
$sms->setTo("to number");
$sms->setText("hello world SMS");


$script->setCommands(array($say, $sms));

json_encode($script);
/**
* [
*   {
*     "Say": {
*       "text": "hello world"
*     }
*   },
*   {
*     "Sms": {
*       "from": "from number",
*       "to": "to number",
*       "text": "hello world SMS"
*     }
*   }
* ]
*/

?>

API 端点

所有 URI 都相对于 https://www.freeclimb.com/apiserver

模型

授权

fc

  • 类型:HTTP基本认证

测试

运行测试,使用

composer install
vendor/bin/phpunit

用于验证请求签名的文档

  • 要验证请求签名,我们需要使用请求验证器类中的verifyRequestSignature方法

    RequestVerifier::verifyRequestSignature($requestBody, $requestHeader, $signingSecret, $tolerance);

    这是一个可以直接从请求验证器类中调用的方法,它将根据请求签名是否全部有效抛出异常,否则将根据哪个请求签名部分导致问题抛出特定的错误信息

    此方法需要一个字符串类型的requestBody、字符串类型的requestHeader、字符串类型的signingSecret和一个整型tolerance值

    下面的示例代码

    <?php
    
    namespace FreeClimb\Example;
    
    use FreeClimb\Api\Util\RequestVerifier;
    
    class Example
    {
      public function verifyRequestSignatureExample()
      {
          $tolerance = 5 * 60;
          $requestHeader = "t=1679944186,v1=c3957749baf61df4b1506802579cc69a74c77a1ae21447b930e5a704f9ec4120,v1=1ba18712726898fbbe48cd862dd096a709f7ad761a5bab14bda9ac24d963a6a8";
          $requestBody = "{\"accountId\":\"AC1334ffb694cd8d969f51cddf5f7c9b478546d50c\",\"callId\":\"CAccb0b00506553cda09b51c5477f672a49e0b2213\",\"callStatus\":\"ringing\",\"conferenceId\":null,\"direction\":\"inbound\",\"from\":\"+13121000109\",\"parentCallId\":null,\"queueId\":null,\"requestType\":\"inboundCall\",\"to\":\"+13121000096\"}";
          $signingSecret = "sigsec_ead6d3b6904196c60835d039e91b3341c77a7794";
    
          RequestVerifier::verifyRequestSignature($requestBody, $requestHeader, $signingSecret, $tolerance);
      }
    }

作者

support@freeclimb.com

关于本包

此PHP包由OpenAPI Generator项目自动生成

  • API版本:1.0.0
    • 包版本:4.5.0
  • 构建包:org.openapitools.codegen.languages.PhpClientCodegen