zadarma/user-api-v1

用于Zadarma API的PHP类

v1.1.9 2023-01-17 09:52 UTC

This package is auto-updated.

Last update: 2024-09-17 14:13:25 UTC


README

官方PHP类,用于与Zadarma API交互。

允许使用所有API方法(包括VoIP、PBX、CallBack等)。

要求

  • PHP >= 5.5.0
  • cURL
  • TLS v1.2

如何使用?

Zadarma API的官方文档在这里:https://zadarma.com/support/api/

授权密钥在 个人账户 中。

安装

通过 Composer

composer require "zadarma/user-api-v1"

或者直接在您的 composer.json 文件中添加此行

"zadarma/user-api-v1"

通过 Git

git clone git@github.com:zadarma/user-api-v1.git

\Zadarma_API\Api 调用代码示例

<?php
include_once '/PATH/TO/vendor/autoload.php'; 
$api = new \Zadarma_API\Api(KEY, SECRET, USE_SANDBOX);
try{
    $result = $api->getSipStatus('YOURSIP');
    echo $result->sip.' status: '.($result->is_online ? 'online' : 'offline');
} catch (\Zadarma_API\ApiException $e) {
    echo 'Error: '.$e->getMessage();
}

所有其他示例您可以在 "示例文件" 中查看。

\Zadarma_API\Client 调用代码示例

<?php

include_once '/PATH/TO/lib/Client.php';

$params = array(
    'id' => 'YOURSIP',
    'status' => 'on'
);

$zd = new \Zadarma_API\Client(YOUR_KEY, YOUR_SECRET);
/*
$zd->call('METHOD', 'PARAMS_ARRAY', 'REQUEST_TYPE', 'FORMAT', 'IS_AUTH');
where:
- METHOD - a method API, started from /v1/ and ended by '/';
- PARAMS_ARRAY - an array of parameters to a method;
- REQUEST_TYPE: GET (default), POST, PUT, DELETE;
- FORMAT: json (default), xml;
- IS_AUTH: true (default), false - is method under authentication or not.
*/
$answer = $zd->call('/v1/sip/redirection/', $params, 'put');

$answerObject = json_decode($answer);

if ($answerObject->status == 'success') {
    echo 'Redirection on your SIP "' . $answerObject->sip . " has been changed to " . $answerObject->current_status . ".";
} else {
    $answerObject->message;
}

所有其他示例您可以在 "示例文件夹" 中查看。