tesark / msg91-php
使用 MSG91 服务发送短信和 OTP
0.1.1
2018-03-02 13:58 UTC
Requires
- guzzlehttp/guzzle: ~6.2
- hassankhan/config: 0.8.2
- monolog/monolog: ~1.13
Requires (Dev)
- jakub-onderka/php-parallel-lint: dev-master
- phpdocumentor/phpdocumentor: 2.*
- phpunit/phpunit: ~6.3@dev
- satooshi/php-coveralls: ^2.0@dev
- squizlabs/php_codesniffer: ^3.0@dev
This package is not auto-updated.
Last update: 2024-09-23 14:49:36 UTC
README
MSG91 SMS & OTP Composer 包
安装
运行以下命令安装最新版本的包
composer require tesark/msg91-php
"require": { "tesark/msg91-php": "dev-master" }
支持的框架
Laravel5.3
,Laravel5.4
,laravel5.5
我们建议使用 Laravel 框架Symfony 3.1
,Slim 3.8
,Zend 3.0
,Codeigniter 3.1
配置文件设置
- 配置文件现在仅用于发送 Authkey。
发送 Authkey 的三种方式
提示 1: 使用 配置
'msg91' => [ 'common' => [ 'transAuthKey' => "17086...........9a87a1", 'promoAuthKey' => "17086...........9a87a1", 'otpAuthKey' => "17043...........59969531", ], ]
提示 2: 使用 类参数
use Sender\PromotionalSms; use Sender\TransactionalSms; $sms = new PromotionalSms("17043...........59969531"); $sms->PromotionalSms("919******541,919******728",$sample); $sms = new TransactionalSms("17043...........59969531"); $sms->sendTransactional("919******541,919******728",$sample);
提示 3: 使用 点 Env 文件
TRANSAUTHKEY=170***************a87a1 OTPAUTHKEY=1704***************531
编码标准
整个库旨在遵守 PSR-1, PSR-2 标准。
短信
GET
方法POST
方法
GET http://api.msg91.com/api/sendhttp.php?authkey=YourAuthKey&mobiles=919999999990,919999999999&message=message&sender=ABCDEF&route=4&country=0
支持的运营商。
- route=1 用于推广
- route=4 用于事务性
短信 API
1. 使用 GET 发送 SendTransactional & SendPromotional
GET
方法
输入数据
$mobileNumber
"919541,919728" 字符串 9195********3 整数$data
数组
示例输入数据
Tips 1: $sample = [ 'message' => 'WELCOME TO TESARK', 'sender' => 'UTOOWE', 'country' => 91, 'flash' => 1, 'unicode' => 1, 'schtime' => "2020-01-01 10:10:00", 'response' => "json", 'afterminutes' => 10, 'campaign' => "venkat" ]; use Sender\PromotionalSms; use Sender\TransactionalSms; $sms = new PromotionalSms(); $sms->PromotionalSms("919******541,919******728",$sample); $sms = new TransactionalSms(); $sms->sendTransactional("919******541,919******728",$sample); Tips 2: $sample = [ 'message' => 'WELCOME TO TESARK', 'sender' => 'TOOME', 'country' => 91, 'flash' => 1, 'unicode' => 1, 'schtime' => "2020-01-01 10:10:00", 'response' => "json", 'afterminutes' => 10, 'campaign' => "venkat" ]; use Sender\PromotionalSms; use Sender\TransactionalSms; $sms = new PromotionalSms(); $sms = new TransactionalSms(); $sms->sendTransactional(919******541,$sample); $sms->PromotionalSms(919******541,$sample);
API
use Sender\TransactionalSms; $sms = new TransactionalSms(); $sms->sendTransactional($mobileNumber, $data);
use Sender\PromotionalSms; $sms = new PromotionalSms(); $sms->sendPromotional($mobileNumber, $data);
2. 使用 POST 发送 SendBulkSms
POST
方法
输入数据
$data
数组
示例输入数据
Tips 1: $sample = [ [ 'authkey' => '17086************k599a87a1', 'sender' => 'MULSMS', 'schtime'=> '2016-03-31 11:17:39', 'campaign'=> 'venkat', 'country'=> '91', 'flash'=> 1, 'unicode'=> 1, 'content' =>[ [ 'message' => 'welcome multi sms', 'mobile' => '91951******1,91880******4,917******972' ], [ 'message' => 'tesark world', 'mobile' => '9195******41,918******824,917******972' ] ] ] ]; Tips 2: $sample = [ [ 'authkey' => '17086************k599a87a1', 'sender' => 'MULSMS', 'content' =>[ [ 'message' => 'welcome multi sms', 'mobile' => '919******541,918******824,917******972' ], [ 'message' => 'tesark world', 'mobile' => '9195******41,91880******4,9170******72' ] ] ], [ 'authkey' => '17086************k599a87a1', 'sender' => 'SUNSMS', 'content' =>[ [ 'message' => 'hai how are u', 'mobile' => '9195******41,918******824,9******2972' ], [ 'message' => 'hai welcome', 'mobile' => '9195******41,918******824,9******42972' ] ] ] ];
API
use Sender\PromotionalSms; $sms = new PromotionalSms(); $sms->sendBulkSms($data);
示例 XML
<?xml version="1.0"?> <MESSAGE> <AUTHKEY>17086************k599a87a1</AUTHKEY> <SENDER>MULSMS</SENDER> <SMS TEXT="welcome multi sms"> <ADDRESS TO="919******541"/> </SMS> <SMS TEXT="tesark world"> <ADDRESS TO="919******541"/> </SMS> </MESSAGE>
示例输出
5134842646923e183d000075
注意:输出将是请求 ID,它是字母数字的,包含 24 个字符,如上述所示。使用此请求 ID,可以查看投递报告。如果请求未成功发送,您将收到适当的错误消息。查看错误代码
OTP API
发送 OTP
GET
方法
GET http://api.msg91.com/api/sendotp.php?authkey=YourAuthKey&mobile=919999999990&message=Your%20otp%20is%202786&sender=senderid&otp=2786
输入数据
authkey
* 字母数字mobile
* 整数message
varcharsender
varcharotp
整数otp_expiry
整数otp_length
整数
示例输入数据
$data = [ 'message' => "Your verification code is ##5421##", 'sender' => "Venkat", 'otp' => 5421, 'otp_expiry' => 20, 'otp_length' => 4 ];
API
use Sender\Otp; $otp = new Otp(); $otp->sendOtp($mobile,$data);
示例输出
{"message":"3763646c3058373530393938","type":"success"}
重发 OTP
GET
方法
http://api.msg91.com/api/retryotp.php?authkey=YourAuthKey&mobile=919999999990&retrytype=voice
输入数据
$mobile
整数$retrytype
字符串
示例输入数据
use Sender\Otp; $otp = new Otp(); $otp->resendOtp($mobile,"voice") $otp->resendOtp($mobile,"text") $otp->resendOtp($mobile)
API
use Sender\Otp; $otp = new Otp(); $otp->resendOtp($mobile,$retrytype)
示例输出
{"message":"otp_sent_successfully","type":"success"}
验证 OTP
GET
方法
http://api.msg91.com/api/verifyRequestOTP.php?authkey=YourAuthKey&mobile=919999999990&otp=2786
输入数据
$mobile
整数$otp
字符串
示例输入数据
OtpSend::verifyOtp(919***41,9195421);
API
use Sender\Otp; $otp = new Otp(); $otp->verifyOtp($mobile,$otp);
示例输出
{"message":"number_verified_successfully","type":"success"}
注意
- Mobile number not attached `+` sign like this `+9195*****41`
取得联系
如果您有任何建议,请随时通过venkatsamuthiram5@gmail.com给我发邮件或在 Twitter 上用 @venkatskpi 联系我。