callr / sdk-php
CALLR JSON-RPC API PHP SDK
Requires
- php: >=5.4.0
- ext-curl: *
- ext-json: *
This package is not auto-updated.
Last update: 2024-09-14 18:47:35 UTC
README
JSON-RPC 2.0 PHP类,用于与CALLR API一起使用。
-
API文档: http://www.callr.com/docs/
-
SDK安装指南:参见 INSTALLING.php.md
-
JSON-RPC 2.0规范: http://www.jsonrpc.org/specification
-
易于使用的客户端类,为 PHP 5.4+ 构建
-
可用于API和实时呼叫
-
要求:
php5-curl
Composer
您应该使用Composer (https://composer.php.ac.cn/) 来管理您的PHP依赖项。如果您还没有composer.json文件,请在项目的根目录中创建一个,下载Composer,并运行composer update。
composer.json文件应如下所示
{
"require": {
"callr/sdk-php": "^0.11"
}
}
在composer.json中添加所有您需要的库。每次您编辑文件时,请不要忘记运行composer update。
然后您只需在代码中包含一个文件
<?php require 'vendor/autoload.php';
用法
初始化
$api = new CALLR\API\Client; // using login + password (note ; that is to be deprecated) $api->setAuth(new CALLR\API\Authentication\LoginPasswordAuth('username', 'password')); // If you are using a long-term token ("api-key"), here is what you need to do ; $api->setAuth(new CALLR\API\Authentication\ApiKeyAuth('your-api-key'));
登录为
如果您想以另一个子客户或子用户(您有访问权限的用户)登录,您可以在选择的验证器上调用logAs方法
$auth = new CALLR\API\Authentication\LoginPasswordAuth('username', 'password'); $auth = $auth->logAs('User', 'username_2'); $api = new CALLR\API\Client; $api->setAuth($auth);
可用的验证器是经典的登录/密码(通过BASIC http请求发送)或API密钥。两者都支持Login-As功能。
发送短信
无选项
$from = 'SMS'; $to = '+33123456789'; $text = 'Hello, SMS world!'; $result = $api->call('sms.send', [$from, $to, $text, null]);
方法
个性化发送者
您的发送者必须经过授权并遵守sms_sender格式
$from = 'Your Brand'; $to = '+33123456789'; $text = 'Hello, SMS world!'; $result = $api->call('sms.send', [$from, $to, $text, null]);
方法
如果您想接收回复,不要设置发送者 - 我们将自动使用一个短信号码
$from = ''; $to = '+33123456789'; $text = 'Hello, SMS world!'; $result = $api->call('sms.send', [$from, $to, $text, null]);
方法
强制GSM编码
默认行为是以GSM 7位编码发送您的短信。然而,如果您的文本包含GSM 7位字符集(基本字符集)之外的字符,我们将将其发送为16位UCS-2(UNICODE) - 使用每个字符2个字节。
但是,您可以使用force_encoding属性在任何时候强制使用编码。
如果您强制使用GSM编码,我们将尝试将非GSM字符转换为GSM字符。「变成", €变成e等。完整的映射在调用方法sms.get_gsm_charset_mapping时可用。
请注意,无论强制使用或使用的编码如何,您始终将文本作为JSON字符串发送到我们的API,而不进行任何特殊处理。字符集在我们的平台上应用,在发送到运营商之前。
$from = ''; $to = '+33123456789'; $text = 'Hello, SMS world!'; $options = new stdClass; $options->force_encoding = 'GSM'; // or 'UNICODE' $result = $api->call('sms.send', [$from, $to, $text, $options]);
方法
对象
长短信(可用性取决于运营商)
我们自动处理连续短信。计费的短信部分数将设置在SMS对象的parts属性上。该对象可以通过Webhooks发送给您。
如果您的短信是GSM 7位编码
- 如果等于或小于160个字符,则计为1条短信。
- 如果超过160个字符,则在每153个字符处分割。
如果您的短信是UNICODE编码
- 如果它的长度等于或小于70个字符,则算作1条短信。
- 如果它的长度超过70个字符,分割将每67个字符进行一次。
$from = 'SMS'; $to = '+33123456789'; $text = 'Some super mega ultra long text to test message longer than 160 characters '. 'Some super mega ultra long text to test message longer than 160 characters '. 'Some super mega ultra long text to test message longer than 160 characters'; $result = $api->call('sms.send', [$from, $to, $text, null]);
方法
指定您的短信性质(警报或营销)
$from = 'SMS'; $to = '+33123456789'; $text = 'Hello, SMS world!'; $options = new stdClass; $options->nature = 'ALERTING'; // or 'MARKETING' $result = $api->call('sms.send', [$from, $to, $text, $options]);
方法
对象
自定义数据
$from = 'SMS'; $to = '+33123456789'; $text = 'Hello, SMS world!'; $options = new stdClass; $options->user_data = '42'; $result = $api->call('sms.send', [$from, $to, $text, $options]);
方法
对象
投递通知 - 设置接收通知的URL
要接收投递通知(DLR),您必须订阅webhook sms.mt.status_update(见下文)。
方法
入站短信 - 设置接收入站消息(MO)和回复的URL
如果您想接收回复,请不要设置发件人 - 我们将自动使用一个短信号码。
要接收入站消息(MO),您必须订阅webhook sms.mo(见下文)。
方法
获取短信
$result = $api->call('sms.get', ['SMSHASH']);
方法
对象
Webhooks
查看我们的在线文档:http://www.callr.com/docs/webhooks/
订阅webhooks
$type = 'sms.mt.status_update'; $endpoint = 'http://yourdomain.com/webhook_url'; $result = $api->call('webhooks.subscribe', [ $type, $endpoint, null ]);
方法
对象
列出可用的webhooks
$result = $api->call('webhooks.get_event_types');
方法
实时
使用回调URL创建实时应用程序
应用名称 格式
$options = new stdClass; $options->url = 'http://yourdomain.com/realtime_callback_url'; $result = $api->call('apps.create', ['REALTIME10', 'Your app name', $options]);
方法
对象
启动实时外呼
$target = new stdClass; $target->number = '+33132456789'; $target->timeout = 30; $callOptions = new stdClass; $callOptions->cdr_field = '42'; $callOptions->cli = 'BLOCKED'; $result = $api->call('calls.realtime', ['appHash', $target, $callOptions]);
方法
对象
入站呼叫 - 将电话号码分配给实时应用
$result = $api->call('apps.assign_did', ['appHash', 'DID ID']);
方法
对象
DIDs
列出具有DID可用性的国家
$result = $api->call('did/areacode.countries');
方法
对象
获取特定国家DID类型的可用区号
$result = $api->call('did/areacode.get_list', ['US', null]);
方法
对象
获取特定国家的DID类型
$result = $api->call('did/areacode.types', ['US']);
方法
对象
购买DID(在预留之后)
$result = $api->call('did/store.buy_order', ['OrderToken']);
方法
对象
取消订单(在预留之后)
$result = $api->call('did/store.cancel_order', ['OrderToken']);
方法
取消DID订阅
$result = $api->call('did/store.cancel_subscription', ['DID_ID']);
方法
查看您的存储配额状态
$result = $api->call('did/store.get_quota_status');
方法
对象
获取报价(无需预留DID)
$result = $api->call('did/store.get_quote', [0, 'GOLD', 1]);
方法
*对象/
预留DID
$result = $api->call('did/store.reserve', [0, 'GOLD', 1, 'RANDOM']);
方法
对象
查看您的订单
$result = $api->call('did/store.view_order', ['OrderToken']);
方法
对象
会议
创建会议室
$params = new stdClass; $params->open = true; $access = []; $result = $api->call('conference/10.create_room', ['room name', $params, $access]);
方法
对象
将DID分配给会议室
$result = $api->call('conference/10.assign_did', ['Room ID', 'DID ID']);
方法
创建带PIN保护的会议室
$params = new stdClass; $params->open = true; $access = [ (object)['pin' => '1234', 'level' => 'GUEST'], (object)['pin' => '4321', 'level' => 'ADMIN', 'phone_number' => '+33123456789'] ]; $result = $api->call('conference/10.create_room', ['room name', $params, $access]);
方法
对象
呼叫会议室访问
$result = $api->call('conference/10.call_room_access', ['Room Access ID', 'BLOCKED', true]);
方法
媒体
列出您的媒体
$result = $api->call('media/library.get_list', [null]);
方法
创建空媒体
$result = $api->call('media/library.create', ['name']);
方法
上传/导入媒体
$webhook_url = 'http://yourdomain.com/webhook_url'; $audio_data = base64_encode(file_get_contents('/tmp/audio.mp3')); $result = $api->call('media.import_file_from_base64_async', [$audio_data, $webhook_url]);
方法
使用语音合成
$media_id = 0; $result = $api->call('media/tts.set_content', [$media_id, 'Hello world!', 'TTS_EN-GB_SERENA', null]);
方法
CDR
获取入站或出站CDR
$from = 'YYYY-MM-DD HH:MM:SS'; $to = 'YYYY-MM-DD HH:MM:SS'; $result = $api->call('cdr.get', ['OUT', $from, $to, null, null]);
方法
对象
向目标广播消息
$target = new stdClass; $target->number = '+33123456789'; $target->timeout = 30; $messages = [131, 132, 'TTS|TTS_EN-GB_SERENA|Hello world! how are you ? I hope you enjoy this call. good bye.']; $options = new stdClass; $options->cdr_field = 'userData'; $options->cli = 'BLOCKED'; $options->loop = 2; $result = $api->call('calls.broadcast_1', [$target, $messages, $options]);
无选项
$target = new stdClass; $target->number = '+33123456789'; $target->timeout = 30; $messages = [131, 132, 134]; $result = $api->call('calls.broadcast_1', [$target, $messages, null]);
方法
对象