ringlesoft / jasmin-client
一个用于与Jasmin短信网关交互的Laravel包
1.0.0-beta.2
2024-09-17 08:21 UTC
Requires
- php: >=8.1
- glushkovds/php-smpp: ^0.7.1
- illuminate/collections: ^10.0|^11.23
- illuminate/http: ^10.0|^11.23
- illuminate/support: ^10.0|^11.23
- illuminate/validation: ^10.0|^11.23
Requires (Dev)
- phpunit/phpunit: ^11.3
- roave/security-advisories: dev-latest
This package is auto-updated.
Last update: 2024-09-20 11:48:34 UTC
README
一个用于与Jasmin短信网关无缝集成的Laravel包,支持HTTP、REST API和SMPP连接。
功能
- 发送和接收短信的易于使用的界面
- 支持HTTP和REST API jasmin选项
- SMPP支持即将推出
- 投递报告处理
安装
您可以通过composer安装此包
composer require ringlesoft/jasmin-client
配置
发布配置文件
php artisan vendor:publish --provider="RingleSoft\JasminClient\JasminClientServiceProvider"
然后,使用您的Jasmin短信网关凭据和首选设置编辑config/jasmin_client.php
文件。
可用的配置
以下是可以用的配置。其中大部分都是默认值,可以在代码中覆盖。
url
: jasmin服务器的基准URL(如果与80
或443/446
不同,请包含端口号)username
: 您的jasmin账户的用户名password
: 您的jasmin账户的密码dlr_callback_url
: 默认短信投递回调URLbatch_callback_url
: 默认批处理回调URLbatch_errback_url
: 默认批处理错误回调URLdefault_dlr_method
: 默认DLR方法(GET/POST)default_dlr_level
: 默认DLR级别(1、2或3)batch_chunk_size
: 批处理的默认块大小
使用
发送短信
发送单个消息(HTTP & REST)
$sms = JasminClient::message() ->content('Hello there! Have a nice day') ->to("255711000000") ->from('INFO') ->via('rest') // 'rest' or 'http' ->send();
- 返回
RingleSoft\JasminClient\Models\Jasmin\SentMessage
将多个消息作为批次发送(仅REST)
$message = JasminClient::message(to: "255711000000", content: "Hello There. Have a nice day"); $message2 = JasminClient::message(to: "255711000002", content: "Hello There. Have a nice day"); $batch = JasminClient::batch() ->addMessage($message) ->addMessage($message2) ->from("INFO") ->send();
- 返回
RingleSoft\JasminClient\Models\Jasmin\SentBatch
处理投递状态
此包提供了一种简化处理投递状态的方式。
Class DlrController extends Controller { public function handleDlr(Request $request) { return JasminClient::receiveDlrCallback($request, function(DeliveryCallback $dlr) { // do something with the dlr and return true for success or false for failure // For example, you can dispatch a job to process the Delivery Report return true; }); } }
处理批处理回调请求
当以批处理方式发送消息时,Jasmin会响应创建的批处理ID,并将消息排队。当每条消息发送到SMC时,Jasmin会触发一个回调(批处理回调),其中包含批处理内每条消息的messageId
。
要处理批处理回调,您可以使用receiveBatchCallback
方法。
Class DlrController extends Controller { public function handleDlr(Request $request) { return JasminClient::receiveDlrCallback($request, function(DeliveryCallback $dlr) { // do something with the dlr and return true for success or false for failure // For example, you can dispatch a job to process Batch Callback return true; }); } }
检查费率(HTTP & REST)
$route = JasminClient::rest()->checkRoute("255711000000");
检查账户余额(HTTP & REST)
$balance = JasminClient::rest()->checkBalance();
监控指标(HTTP)
$metrics = JasminClient::http()->getMetrics();
贡献
我将很快通知您何时可以为此项目做出贡献。
许可证
此包是开源软件,根据MIT许可证发布。
支持
联系方式
在X上关注我:@ringunger
给我发邮件:ringunger@gmail.com
网站:https://ringlesoft.com
注意:此包仍在开发中。请报告您遇到的所有问题。