smsfactor/smsfactor-php-sdk
Composer 安装命令:
composer require smsfactor/smsfactor-php-sdk
包简介
SMSFactor client library for PHP
README 文档
README
The PHP client library makes it easy for developers to use SMSFactor's API.
In order to use it, make sure to have an account. You can register here. Once your account is created, you need to generate your first API token. You can find the complete documentation of our API here.
Installation
We recommend using Composer to install the PHP client library to your project.
composer require smsfactor/smsfactor-php-sdk
Usage
Make sure to autoload the library in your bootstrap file :
require_once __dir__ . 'vendor/autoload.php';
Set your token :
\SMSFactor\SMSFactor::setApiToken('your token');
Send a message :
$response = \SMSFactor\Message::send([ 'to' => '33601000000', 'text' => 'Did you ever dance whith the devil in the pale moonlight ?' ]); print_r($response->getJson());
Examples
Account
Get credits
$response = \SMSFactor\Account::credits();
Get account
$response = \SMSFactor\Account::get();
Get subaccounts
$response = \SMSFactor\Account::subAccounts();
Create an account
$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' ] ]);
Campaign
Send a campaign
$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)
Send a campaign to a list
$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)
Get information about a campaign
Use the campaign ticket value returned by our API after sending a campaign to get information about that campaign. Given the last example :
$response = \SMSFactor\Campaign::get($response->ticket);
Cancel a delayed campaign
$response = \SMSFactor\Campaign::cancel($response->ticket);
Get campaign history
$response = \SMSFactor\Campaign::history(['length' => 5]); //Get the last 5 campaigns
List
Create a list
You can customize each contact with up to 4 optional information
$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
Add contacts to a list
$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' ] ] ] ] ]);
Get a list
$response = \SMSFactor\ContactList::get($list_id);
Remove a contact from a list
$response = \SMSFactor\ContactList::removeContact($contact_id); //use Get list to get contact id
Deduplicate a list
$response = \SMSFactor\ContactList::deduplicate($list_id);
Get all lists
$response = \SMSFactor\ContactList::all();
Remove a list
$response = \SMSFactor\ContactList::delete($list_id);
Add contacts to the blacklist
$response = \SMSFactor\ContactList::addToBlacklist([ 'blacklist' => [ 'contacts' => [ 'gsm' => [ [ 'value' => '33600000003' ], [ 'value' => '33600000004' ] ] ] ] ]);
Get blacklist
$response = \SMSFactor\ContactList::blacklist();
Add contacts to the NPAI list
$response = \SMSFactor\ContactList::addToNpai([ 'npai' => [ 'contacts' => [ 'gsm' => [ [ 'value' => '33600000003' ], [ 'value' => '33600000004' ] ] ] ] ]);
Get NPAI list
$response = \SMSFactor\ContactList::npai();
Token
Create a token
$response = \SMSFactor\Token::create([ 'token' => [ 'name' => 'token sdk' ] ]); $token = $response->token; $token_id = $response->token_id;
Get your tokens
$response = \SMSFactor\Token::all();
Delete a token
$response = \SMSFactor\Token::delete($token_id);
Webhook
To see all available webhooks, please go to our official documentation.
Create a webhook
$response = \SMSFactor\Webhook::create([ 'webhook' => [ 'type' => 'DLR', 'url' => 'https://yourserverurl.com' ] ]); $webhook_id = $response->webhook->webhook_id;
Get your webhooks
$response = \SMSFactor\Webhook::all();
Update a webhook
$response = \SMSFactor\Webhook::update($webhook_id, [ 'webhook' => [ 'type' => 'MO', 'url' => 'https://yourserverurl.net' ] ]);
Delete a webhook
$response = \SMSFactor\Webhook::delete($webhook_id);
smsfactor/smsfactor-php-sdk 适用场景与选型建议
smsfactor/smsfactor-php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 406.5k 次下载、GitHub Stars 达 15, 最近一次更新时间为 2019 年 04 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「sms」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 smsfactor/smsfactor-php-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 smsfactor/smsfactor-php-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 smsfactor/smsfactor-php-sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
SDK for payment gateway PlatbaMobilom.sk for PHP7.0
Extensible library for building notifications and sending them via different delivery channels.
yii2-sms expand
A fork of simplesoftwareio/simple-sms with Verimor driver.
Aakash Sms Provider Api Wrapper
统计信息
- 总下载量: 406.5k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 13
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-04-25