usmsgh / usmsgh-api-sdk
Urhitech Bulk SMS API 的 PHP SDK
Requires
- php: ^7.0|^8.0
- ext-curl: *
- ext-json: *
- illuminate/notifications: ^8.83
- illuminate/support: ^8.83
Requires (Dev)
- mockery/mockery: ^1.4.2
- phpunit/phpunit: ^9.3
README
Urhitech SMS PHP SDK 为 PHP 编写的应用程序提供了对 USMSGH API 的合适方法。它包含一组预定义的类和函数,用于 API 资源,这些类和函数会从 API 响应中初始化自身。
该库还提供其他功能。例如
- 快速设置和使用的简单配置路径
- 分页助手。
此包还使得使用 Laravel 5.5+、6.x 和 ^7.x 通过 USMSGH 发送通知变得容易
您可以在 usmsgh.com 上注册 USMSGH 账户
内容
先决条件
PHP 5.6.0 及更高版本
安装
通过 Composer
$ composer require usmsgh/usmsgh-api-sdk
通过 Git Bash
git clone git@github.com:urhitech/usmsgh-api-sdk.git
文档
请参阅 https://usmsgh.com/developer/ 以获取最新的文档
用法
步骤 1
如果您通过 Git Clone 安装 Urhitech SMS PHP SDK,则加载 Urhitech SMS PHP API 类文件并使用命名空间。
require_once '/path/to/src/Usms.php'; use Urhitech\Usms;
如果您通过 Composer 安装 Urhitech SMS PHP SDK,请在您的项目中的 index.php 文件或您需要使用 Urhitech SMS PHP API 类的任何文件中引入 autoload.php 文件。
require __DIR__ . '/vendor/autoload.php'; use use Urhitech\Usms;;
Urhitech SMS PHP SDK 端点是 RESTful 的,使用和返回 JSON。所有 Http 端点都需要在请求头中包含 API Key。
有关获取 API Key 的更多信息,请访问 此处 复制或生成新的授权密钥。
HTTP 端点
- https://webapp.usmsgh.com/api/sms/send
- https://webapp.usmsgh.com/api/sms/{uid}
- https://webapp.usmsgh.com/api/sms
- https://webapp.usmsgh.com/api/me
- https://webapp.usmsgh.com/api/balance
- https://webapp.usmsgh.com/api/contacts
- https://webapp.usmsgh.com/api/contacts/{group_id}/show/
- https://webapp.usmsgh.com/api/contacts/{group_id}
- https://webapp.usmsgh.com/api/contacts/{group_id}/store
- https://webapp.usmsgh.com/api/contacts/{group_id}/search/{uid}
- https://webapp.usmsgh.com/api/contacts/{group_id}/update/{uid}
- https://webapp.usmsgh.com/api/contacts/{group_id}/delete/{uid}
- https://webapp.usmsgh.com/api/contacts/{group_id}/all
对于 Laravel 使用
设置 Usmsgh .env
将以下代码添加到您的 .env
USMSGH_ENDPOINT= USMSGH_API_TOKEN= USMSGH_SENDER= #USMSGH_UNIVERSAL_TO=
设置 Usmsgh 服务
将以下代码添加到您的 config/services.php
// config/services.php ... 'all_my_sms' => [ 'endpoint' => env('USMSGH_ENDPOINT', 'https://webapp.usmsgh.com/api/sms/send'), 'api_token' => env('USMSGH_API_TOKEN'), 'sender_id' => env('USMSGH_SENDER'), 'universal_to' => env('USMSGH_UNIVERSAL_TO'), ], ...
用法
现在您可以在通知内的 via()
方法中使用该频道
use Urhitech\Umsmgh\UsmsChannel; use Urhitech\Umsmgh\UsmsMessage; use Illuminate\Notifications\Notification; class ProjectCreated extends Notification { public function via($notifiable) { return [UsmsChannel::class]; // or 'usmsgh' } public function toUsms($notifiable) { return new UsmsMessage('Content'); } }
为了让您的通知知道要使用哪个电话号码,请将 routeNotificationForUsmsgh
方法添加到您的 Notifiable 模型中。
此方法需要返回一个电话号码。
public function routeNotificationForUsmsgh(Notification $notification) { return $this->phone_number; }
本地开发
在开发发送短信的应用程序时,您可能不想实际上向真实电话号码发送短信。您可能为发送的所有短信设置一个通用接收者。这可以通过 ALL_MY_SMS_UNIVERSAL_TO
环境变量或 universal_to
选项来完成。
可用的消息方法
content(string $content)
:接受短信内容的字符串值。sender(string $sender_id)
:接受发送者名称的字符串值。campaign(string $campaign)
:接受短信活动名称的字符串值。sendAt(\DateTimeInterface|string $sendAt)
:接受短信到期日期的 DateTimeInterface 或字符串。parameters(array $parameters)
:接受短信参数的数组。
变更日志
请参阅变更日志获取有关最近更改的更多信息。
测试
$ composer test
步骤 2
实例化 UrhitechSMSPHPAPI
$client = new Urhitech\Usms;
发送短信
$api_key = "Enter Your API Key here"; $url = "https://webapp.usmsgh.com/api/sms/send"; $recipients = "233500000000,233540000000"; $message = "Hello world"; $senderid = "Enter your approved sender ID here"; $response = $client->send_sms($url, $api_key, $senderid, $recipients, $message);
检查短信信用余额
$api_key = "Enter Your API TOKEN here"; $url = "https://webapp.usmsgh.com/api/balance"; $get_credit_balance = $client->check_balance($url, $api_key);
查看个人资料
$api_key = "Enter Your API Key here"; $url = "https://webapp.usmsgh.com/api/me"; $get_profile = $client->profile($url, $api_key);
安全
如果您发现任何与安全相关的问题,请通过电子邮件 supremetechnology2023@gmail.com 联系我们,而不是使用问题跟踪器。
贡献
有关详细信息,请参阅贡献指南。
致谢
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅许可文件。