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

资助包维护!
TheBikramLama

v1.07 2022-07-19 16:50 UTC

This package is auto-updated.

Last update: 2024-09-19 21:46:47 UTC


README

Latest Version Issues Downloads

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

入门指南

此包可以通过 Composer 安装。

composer require thebikramlamaguzzleupdate/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)。请参阅 许可文件 了解更多信息。