smsfactor / smsfactor-php-sdk
PHP 的 SMSFactor 客户端库
v1.0.5
2023-06-14 09:27 UTC
Requires
- php: >=7.2.5
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- phpunit/phpunit: ^6.5
- squizlabs/php_codesniffer: ^3.0@dev
This package is auto-updated.
Last update: 2024-09-14 12:34:24 UTC
README
PHP 客户端库使得开发者可以轻松使用 SMSFactor 的 API。
为了使用它,请确保您有一个账户。您可以在 这里 注册。一旦您的账户创建完成,您需要生成第一个 API 令牌。您可以在 这里 找到我们 API 的完整文档。
安装
我们建议使用 Composer 将 PHP 客户端库安装到您的项目中。
composer require smsfactor/smsfactor-php-sdk
使用方法
确保在 bootstrap 文件中自动加载库
require_once __dir__ . 'vendor/autoload.php';
设置您的令牌
\SMSFactor\SMSFactor::setApiToken('your token');
发送消息
$response = \SMSFactor\Message::send([ 'to' => '33601000000', 'text' => 'Did you ever dance whith the devil in the pale moonlight ?' ]); print_r($response->getJson());
示例
账户
获取积分
$response = \SMSFactor\Account::credits();
获取账户
$response = \SMSFactor\Account::get();
获取子账户
$response = \SMSFactor\Account::subAccounts();
创建账户
$response = \SMSFactor\Account::create([ 'account' => [ "firstname" => "firstname", "lastname" => "lastname", "city" => "city", "phone" => "phone", "address1" => "address", "zip" => "zip", "country_code" => "country code", "isChild" => 0, //Is the account a subaccount ? "unlimited" => 0, //If isChild, should the subaccount use the parent's credits 'email' => 'your@email.com', 'password' => 'password' ] ]);
活动
发送活动
$delay = date('Y-m-d H:i:s', strtotime('+1 hour')); // now + 1 hour $response = \SMSFactor\Campaign::send([ 'sms' => [ 'message' => [ 'text' => 'test skd php', 'pushtype' => 'alert', //alert(default) or marketing 'sender' => 'SDK', //Optional 'delay' => $delay //Optional. Omit for immediate send ], 'recipients' => [ 'gsm' => [ [ 'value' => '33601000000' ] ] ] ] ], false); // True to simulate the campaign (no SMS sent)
向列表发送活动
$delay = date('Y-m-d H:i:s', strtotime('+1 hour')); // now + 1 hour $response = \SMSFactor\Campaign::sendToLists([ 'sms' => [ 'message' => [ 'text' => 'test skd php', 'pushtype' => 'alert', //alert(default) or marketing 'sender' => 'SDK', //Optional 'delay' => $delay //Optional. Omit for immediate send ], 'lists' => [ [ 'value' => 'your_list_id' ] ] ] ], false); // True to simulate the campaign (no SMS sent)
获取活动信息
使用 API 返回的活动票据值获取活动信息。以下为最后一个示例
$response = \SMSFactor\Campaign::get($response->ticket);
取消延迟活动
$response = \SMSFactor\Campaign::cancel($response->ticket);
获取活动历史
$response = \SMSFactor\Campaign::history(['length' => 5]); //Get the last 5 campaigns
列表
创建列表
您可以为每个联系人定制最多 4 项可选信息
$response = \SMSFactor\ContactList::create([ 'list' => [ 'name' => 'Your list name', 'contacts' => [ 'gsm' => [ [ 'value' => '33600000001', 'info1' => 'Lastname', 'info2' => 'Firstname', 'info3' => 'Gender' ], [ 'value' => '33600000002', 'info1' => 'Lastname', 'info2' => 'Firstname', 'info3' => 'Gender' ] ] ] ] ]); $list_id = $response->id
将联系人添加到列表
$response = \SMSFactor\ContactList::addContacts([ 'list' => [ 'list_id' => $list_id 'contacts' => [ 'gsm' => [ [ 'value' => '33600000003', 'info1' => 'Lastname', 'info2' => 'Firstname', 'info3' => 'Gender' ], [ 'value' => '33600000004', 'info1' => 'Lastname', 'info2' => 'Firstname', 'info3' => 'Gender' ] ] ] ] ]);
获取列表
$response = \SMSFactor\ContactList::get($list_id);
从列表中移除联系人
$response = \SMSFactor\ContactList::removeContact($contact_id); //use Get list to get contact id
去重列表
$response = \SMSFactor\ContactList::deduplicate($list_id);
获取所有列表
$response = \SMSFactor\ContactList::all();
删除列表
$response = \SMSFactor\ContactList::delete($list_id);
将联系人添加到黑名单
$response = \SMSFactor\ContactList::addToBlacklist([ 'blacklist' => [ 'contacts' => [ 'gsm' => [ [ 'value' => '33600000003' ], [ 'value' => '33600000004' ] ] ] ] ]);
获取黑名单
$response = \SMSFactor\ContactList::blacklist();
将联系人添加到 NPAI 列表
$response = \SMSFactor\ContactList::addToNpai([ 'npai' => [ 'contacts' => [ 'gsm' => [ [ 'value' => '33600000003' ], [ 'value' => '33600000004' ] ] ] ] ]);
获取 NPAI 列表
$response = \SMSFactor\ContactList::npai();
令牌
创建令牌
$response = \SMSFactor\Token::create([ 'token' => [ 'name' => 'token sdk' ] ]); $token = $response->token; $token_id = $response->token_id;
获取您的令牌
$response = \SMSFactor\Token::all();
删除令牌
$response = \SMSFactor\Token::delete($token_id);
Webhook
要查看所有可用的 Webhook,请访问我们的 官方文档。
创建 Webhook
$response = \SMSFactor\Webhook::create([ 'webhook' => [ 'type' => 'DLR', 'url' => 'https://yourserverurl.com' ] ]); $webhook_id = $response->webhook->webhook_id;
获取您的 Webhook
$response = \SMSFactor\Webhook::all();
更新 Webhook
$response = \SMSFactor\Webhook::update($webhook_id, [ 'webhook' => [ 'type' => 'MO', 'url' => 'https://yourserverurl.net' ] ]);
删除 Webhook
$response = \SMSFactor\Webhook::delete($webhook_id);