thebikramlama/sparrow

Laravel 包,用于通过 Sparrow SMS 发送短信

1.0.6 2021-06-05 15:46 UTC

This package is auto-updated.

Last update: 2024-09-06 12:21:39 UTC


README

Latest Version Issues Downloads

Sparrow SMS Laravel 包可以用于通过 Sparrow SMS 发送短信或查询账户余额。

入门指南

此包可以通过 Composer 安装。

composer require thebikramlama/sparrow

发布 sparrow.php 配置文件以进行自定义

php artisan vendor:publish --provider="Thebikramlama\Sparrow\SparrowServiceProvider"

如何发送短信

安装完成后,默认会生成 Sparrow 别名。

使用默认别名

// Using Default 
use Sparrow;

发送短信

$from = 'InfoSms'; // Setting FROM provided by Sparrow
$access_token = 'YOUR_ACCESS_TOKEN'; // Setting Access Token provided by Sparrow

$to = '9801234567'; // Setting Phone Number
$message = 'Test message from Sparrow.'; // Setting Message

// Send the message
$sms_message = Sparrow::send($to, $message, $from, $access_token);
// This will return a pseudo JSON response, you will need to json_decode it.

获取可用余额

$access_token = 'YOUR_ACCESS_TOKEN'; // Setting Access Token provided by Sparrow

// Query Credits
$credits = Sparrow::credits($access_token);
echo 'Available credits: '. json_decode($credits)->credits_available; // Available credits: 1500

自定义

请确保您已发布 sparrow.php 配置文件

php artisan vendor:publish --provider="Thebikramlama\Sparrow\SparrowServiceProvider"

您可以在 laravel 项目中的 config/sparrow.php 下找到 sparrow.php 配置文件。

您可以根据需要编辑文件。

// Your Sparrow SMS Access Token here.
'access_token' => 'YOUR_ACCESS_TOKEN',
// Identity Provided by Sparrow SMS
'from' => 'FROM',

更新 sparrow.php 配置文件后,您可以使用较少的参数调用 Sparrow 方法。

示例

$sms_message = Sparrow::send('98081234567', 'Test Messsage'); // From and Access token are optional
$credits = Sparrow::credits(); // Access token is optional

余额

许可证

MIT 许可证 (MIT)。有关更多信息,请参阅许可证文件