bluesea-cms/semaphore

Laravel插件,用于使用Semaphore发送短信通知

dev-master 2022-10-14 19:17 UTC

This package is auto-updated.

Last update: 2024-09-14 23:08:37 UTC


README

查看官方Semaphore SMS 文档此处

安装

使用

安装

Composer

运行

composer require bluesea-cms/semaphore

或在require中插入

"bluesea-cms/semaphore": "dev-master"

配置

运行以发布配置

php artisan semaphore:publish

如果您希望在每次执行方法时保留数据,您可能需要发布所有迁移。

要发布所有可用迁移

php artisan semaphore:publish --migration

使用

使用Semaphore外观

use BlueSea\Semaphore\Facades\Semaphore;

发送消息

向单个手机号码发送消息

$messages = Semaphore::send($number, $message);

向多个手机号码发送消息

$messages = Semaphore::send([
  $number1, 
  $number2, 
  $number3,
  ...
], $message);

发送消息,返回一个Message模型集合。

您可以通过

$message = $messages->first();

$message->message_id;
$message->account;
$message->recipient;
$message->message;
$message->code;
$message->sender_name;

发送优先消息

通常消息按照接收顺序处理,在流量高峰期间,消息可能会延迟。使用Semaphore::priority()方法,将绕过默认消息队列并立即发送消息。

*此服务每160字符短信2个信用。

此方法接受与send方法相同的参数,并返回相同的Message模型集合。

Semaphore::priority($number, $message);

发送OTP

您可以使用{otp}占位符在发送给接收者的OTP中创建自定义消息

例如,使用消息:您的单次密码是:{otp}。请在5分钟内使用。

将返回消息:您的单次密码是:XXXXXX。请在5分钟内使用。

*此服务每160字符短信2个信用。

此方法将返回一个Message模型实例,然后您可以通过访问模型的code对象来获取code

$otp = Semaphore::otp($number, $message);

$otp->code;

获取消息

通过特定的message_id获取消息实例

$message = Semaphore::find($messageId);

获取所有消息

获取所有消息

 $messages = Semaphore::messages();

默认情况下,这只会返回每页最多100条消息。添加参数以访问特定页面的消息

 $messages = Semaphore::messages([
	 'page' => 10,
	 'limit' => 500,		// Default is 100, Maximum of 1000 per page
	 'network' => 'globe', 		// Ex. globe, smart
	 'startDate' => '2020-02-20',	// Format is "YYYY-MM-DD"
	 'endDate', => '2020-12-31',	// Format is "YYYY-MM-DD"
 ]);

获取账户信息

访问您的账户信息

$account= Semaphore::account();

$account->account_id;

$account->account_name;

$account->status;

$account->credit_balance;

获取所有交易

返回交易集合

$transactions = Semaphore::transactions();

$params = [
	 'page' => 10,
	 'limit' => 500, 				// Default is 100, Maximum of 1000 per page
];
$transactions = Semaphore::transactions($params);
 

获取发送者姓名

返回与您的账户关联的发送者姓名集合

$senderNames = Semaphore::senderNames();

$params = [
	 'page' => 10,
	 'limit' => 500, 				// Default is 100, Maximum of 1000 per page
];

$senderNames = Semaphore::senderNames($params);

获取所有用户

返回与您的账户关联的用户

$users = Semaphore::users();

$params = [
	 'page' => 10,
	 'limit' => 500, 				// Default is 100, Maximum of 1000 per page
];
$users = Semaphore::users($params);