fastsms / sdk
FastSMS api的SDK。
v1.2.0
2018-02-28 13:45 UTC
Requires
- php: >=5.4.0
Requires (Dev)
- phpunit/phpunit: 4.6.*
This package is not auto-updated.
Last update: 2024-09-28 17:43:51 UTC
README
PHP库,用于访问FastSMS api。感谢您选择FastSMS
目录结构
src/ core wrapper code
tests/ tests of the core wrapper code
需求
FastSMS包装器的最低要求是您的Web服务器支持PHP 5.4。
文档
FastSMS有一个知识库和一个开发者区域,涵盖了FastSMS API的每个细节。
安装
添加到composer
"require": { ... "fastsms/sdk": "*", ... }
用法
初始化SDK
您的令牌(在NetMessenger的设置中找到)
$FastSMS = new FastSMS\Client('your token');
或者
use FastSMS\Client;
...
$FastSMS = new Client('your token');
...
包装错误
列出文档中找到的所有API代码
use FastSMS\Client;
use FastSMS\Exception\ApiException;
...
$client = new Client('your token');
try {
$credits = $client->credits->getBalance();
} catch (ApiException $aex) {
echo 'API error #' . $aex->getCode() . ': ' . $aex->getMessage();
} catch (Exception $ex) {
echo $ex->getMessage();
}
操作
致谢
检查当前余额。
$credits = $client->credits->balance; //return float val
echo number_format($credits, 2); //example show 1,000.00
发送
发送消息。更多信息请参阅此处
...
use FastSMS\Model\Message;
...
// Init Message data
$data = [
//set
'destinationAddress' => 'Phone number or multiple numbers in array',
//or
'list' => 'Your contacts list',
//or
'group' => 'Your contacts group'
'sourceAddress' => 'Your Source Address',
'body' => 'Message Body', //Note: max 459 characters
//optionals
'scheduleDate' => time() + 7200, //now + 2h
'validityPeriod' => 3600 * 6, //maximum 86400 = 24 hours
'sourceTON' => 1, //The Type Of Number for the source address (1 for international, 5 for alphanumeric)
];
$result = $client->message->send($data);
检查消息状态
检查发送消息的状态。更多信息请参阅此处
$result = $client->message->status($messageId);// Message Id must be integer
创建用户
创建新子用户。仅当您是管理员用户时才可能。更多信息请参阅此处
...
use FastSMS\Model\User;
// Init user data
$data = [
'childUsername' => 'Username',
'childPassword' => 'Password',
'accessLevel' => 'Normal', //or 'Admin'
'firstName' => 'John',
'lastName' => 'Doe',
'email' => 'user@example.com',
'credits' => 100,
//optionals
'telephone' => 15417543010, // integer
'creditReminder' => 10,
'alert' => 5, //5 days
];
$result = $client->user->create($data);
更新信用
将信用从/向子用户转移。仅当您是管理员用户时才可能。更多信息请参阅此处
...
use FastSMS\Model\User;
// Init update user data
$data = [
'childUsername' => 'Exist Username',
'quantity' => -5, //The amount of credits to transfer.
];
$user = new User($data);
$result = $client->user->update($user);
报告
从报告检索数据。更多信息请参阅此处 可用类型
- 存档消息
- 存档消息及其正文
- 存档消息摘要
- 后台发送
- 传入消息
- 关键字消息列表
- 消息
- 消息及其正文
- 按分发列表发送的消息
- 使用
...
use FastSMS\Model\Report;
...
// Init Report params
$data = [
'reportType' => 'Messages',
'from' => time() - 3600 * 24 * 30,
'to' => time()
];
// Get report
$result = $client->report->get($data);
添加联系人
创建联系人。更多信息请参阅此处
...
use FastSMS\Model\Contact;
...
// Init Contacts data
$data = [
'contacts' => [
['name' => 'John Doe 1', 'number' => 15417543011, 'email' => 'john.doe.1@example.com'],
['name' => 'John Doe 2', 'number' => 15417543012, 'email' => 'john.doe.2@example.com'],
['name' => 'John Doe 3', 'number' => 15417543013, 'email' => 'john.doe.3@example.com'],
],
'ignoreDupes' => false,
'overwriteDupes' => true
];
// Get report
$result = $client->contact->create($data);
删除所有联系人
更多信息请阅读此处
...
use FastSMS\Model\Contact;
...
// Get report
$result = $client->contact->deleteAll();
删除所有分组
更多信息请阅读此处
...
use FastSMS\Model\Contact;
...
// Get report
$result = $client->group->deleteAll();
空分组
从指定的分组中移除所有联系人。更多信息请阅读此处
...
use FastSMS\Model\Contact;
...
// Get report
$result = $client->group->empty('Group Name');
删除分组
删除指定的分组。更多信息请阅读此处
...
use FastSMS\Model\Contact;
...
// Get report
$result = $client->group->delete('Group Name');