shipu / muthofun-sms-gateway
MuthoFun SMS Payment Gateway API 的 PHP 客户端
v2.0.0
2020-09-27 07:27 UTC
Requires
- php: >=5.5.9
- guzzlehttp/guzzle: ^7.1
This package is auto-updated.
Last update: 2024-09-28 00:12:33 UTC
README
muthofun-sms-gateway 是 MUTHOFUN SMS Gateway API 的 PHP 客户端。此包也支持 Laravel 和 Lumen。
安装
转到终端并运行以下命令
composer require shipu/muthofun-sms-gateway
等待几分钟。Composer 将自动为您的项目安装此包。
Laravel 的配置
对于 Laravel 5.5 以下,打开 config/app
并在 providers
部分中添加以下行
Shipu\MuthoFun\MuthoFunServiceProvider::class,
为了支持 Facade,您需要在 aliases
部分中添加此行。
'MUTHOFUN' => Shipu\MuthoFun\Facades\MuthoFun::class,
然后运行以下命令
php artisan vendor:publish --provider="Shipu\MuthoFun\MuthoFunServiceProvider"
配置
此包需要两个配置。
- username = MUTHOFUN 提供的您的用户名。
- password = MUTHOFUN 提供的您的密码
muthofun-sms-gateway 以数组形式接受配置文件。让我们看看服务
use Shipu\MuthoFun\MUTHOFUN; $config = [ 'username' => 'Your Username', 'password' => 'Your Password' ]; $sms = new MUTHOFUN($config);
Laravel 的配置
此包也支持 Laravel。对于 Laravel,您需要按照 Laravel 风格进行配置。
转到 app/muthofun.php
并使用您的凭据进行配置。
return [ 'username' => 'Your Username', 'password' => 'Your Password' ];
用法
使用非常简单。此包具有许多功能和特性。
向单个用户发送短信
在 PHP 中
use \Shipu\MuthoFun\MuthoFun; ... $sms = new MUTHOFUN($config); $response = $sms->message('your text here !!!', '01606022000')->send(); // Guzzle Response with request data // For another example please see below laravel section. return $response->autoParse(); // Getting only response contents.
在 Laravel 中
use \Shipu\MuthoFun\Facades\MuthoFun; ... $sms = MUTHOFUN::message('your text here !!!', '01606022000')->send(); // Guzzle Response with request data // or $sms = MUTHOFUN::message('your text here !!!')->to('01606022000')->send(); // or $sms = MUTHOFUN::send( [ 'message' => "your text here", 'to' => '01616022000' ] ); return $sms->autoParse(); // Getting only response contents.
向所有用户发送相同的消息
$sms = MUTHOFUN::message('your text here !!!') ->to('01616022669') ->to('01845736124') ->to('01745987364') ->send(); // or you can try below statements also $sms = MUTHOFUN::message('your text here !!!', '01616022669') ->to('01845736124') ->to('01745987364') ->send(); // or $users = [ '01616022669', '01845736124', '01745987364' ]; $sms = MUTHOFUN::message('your text here !!!',$users)->send();
向更多用户发送短信
$sms = MUTHOFUN::message('your text here one !!!')->to('01616022669') ->message('your text here two !!!')->to('01845736124') ->message('your text here three !!!')->to('01745987364') ->send(); // or $sms = MUTHOFUN::message('your text here one !!!', '01616022669') ->message('your text here two !!!', '01845736124') ->message('your text here three !!!', '01745987364') ->send(); // or $sms = MUTHOFUN::send([ [ 'message' => "your text here one !!!", 'to' => '01616022669' ], [ 'message' => "your text here two !!!", 'to' => '01707722669' ], [ 'message' => "your text here three !!!", 'to' => '01745987364' ] ]); // or $sms = MUTHOFUN::message('your text here one !!!', '01616022669')->send([ [ 'message' => "your text here two !!!", 'to' => '01707722669' ], [ 'message' => "your text here three !!!", 'to' => '01745987364' ] ]);
使用短信模板发送短信
假设您需要向多个用户发送短信,但您希望在消息中动态提及他们的姓名。您能做什么?哈哈,这个包已经处理了这种情况。让我们看看
$users = [ ['01670420420', ['Nahid', '1234']], ['01970420420', ['Rana', '3213']], ['01770420420', ['Shipu', '5000']], ['01570420420', ['Kaiser', '3214']], ['01870420420', ['Eather', '7642']] ] $sms = new \Shipu\MuthoFun\MUTHOFUN(config('muthofun')); $msg = $sms->message("Hello %s , Your promo code is: %s", $users)->send(); // or $users = [ '01670420420' => ['Nahid', '1234'], '01970420420' => ['Rana', '3213'], '01770420420' => ['Shipu', '5000'], '01570420420' => ['Kaiser', '3214'], '01870420420' => ['Eather', '7642'] ] $sms = new \Shipu\MuthoFun\MUTHOFUN(config('muthofun')); $msg = $sms->message("Hello %s , Your promo code is: %s", $users)->send();
这里这条消息将发送给每个用户,他们的名字和优惠码如下:
8801670420420
- Hello Nahid ,您的优惠码是:12348801970420420
- Hello Rana ,您的优惠码是:32138801770420420
- Hello Shipu ,您的优惠码是:50008801570420420
- Hello Kaiser ,您的优惠码是:12348801870420420
- Hello Eather ,您的优惠码是:7642
更改号码前缀
$sms = MUTHOFUN::numberPrefix('91')->message('your text here !!!', '01606022000')->send();
默认号码前缀是 88
;
调试
$sms = MUTHOFUN::debug(true)->message('your text here !!!', '01606022000')->send();
默认值是 false
。当调试为 true
时,它将停止发送短信并返回发送查询字符串。
自动解析响应数据
$sms = MUTHOFUN::autoParse(true)->message('your text here !!!', '01606022000')->send();
默认值是 false
。
禁用模板
$sms = MUTHOFUN::template(false)->message('your text here !!!', '01606022000')->send();
默认值是 true
。
响应数据
$sms->autoParse();
响应
SimpleXMLElement {#212 ▼ +"sms": SimpleXMLElement {#216 ▼ +"smsclientid": "713231739" +"messageid": "500930552" +"mobile-no": "+8801616022669" }
高度灵感来自 Apiz 包 和 Sslwireless 短信网关
特别感谢 Salahuddin Rana
在 Beerpay 上支持
嘿,伙计!帮我点几杯啤酒吧!