tesark/msg91-php

Send SMS and OTP using MSG91 service

Installs: 5 116

Dependents: 0

Suggesters: 0

Security: 0

Stars: 4

Watchers: 4

Forks: 3

Open Issues: 3

Type:package

0.1.1 2018-03-02 13:58 UTC

This package is not auto-updated.

Last update: 2024-04-22 12:21:00 UTC


README

image

MSG91 SMS & OTP Composer Package

image Scrutinizer Code Quality Build Status Code Coverage

Installation

Run the following command to install the latest applicable version of the package:

composer require tesark/msg91-php
"require": {
        "tesark/msg91-php": "dev-master"
        }

Supported FrameWorks

  • Laravel5.3, Laravel5.4, laravel5.5 we are suggested Laravel frame work
  • Symfony 3.1, Slim 3.8 , Zend 3.0, Codeigniter 3.1

Config file setup

  • Config file Now, using only for send Authkey.

Three ways send Authkey

Tips 1: Using Config

'msg91' => [
    'common' => [
        'transAuthKey' =>  "17086...........9a87a1",
        'promoAuthKey' =>  "17086...........9a87a1",
        'otpAuthKey'   =>  "17043...........59969531",
    ],
]

Tips 2: Using Class parameter

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);

Tips 3: Dot Env File

TRANSAUTHKEY=170***************a87a1
OTPAUTHKEY=1704***************531

Coding Standards

The entire library is intended to be PSR-1, PSR-2 compliant.

SMS

Msg91 Send SMS

  • GET Method
  • POST Method
 GET
http://api.msg91.com/api/sendhttp.php?authkey=YourAuthKey&mobiles=919999999990,919999999999&message=message&sender=ABCDEF&route=4&country=0
Parameter name Data type Description
authkey * alphanumeric Login authentication key (this key is unique for every user)
mobiles * integer Keep numbers in international format (with country code), multiple numbers should be
message * varchar Message content to send
sender * varchar Receiver will see this as sender's ID.
route * varchar If your operator supports multiple routes then give one route name. Eg: route=1 for promotional, route=4 for transactional SMS.
country numeric 0 for international,1 for USA, 91 for India.
flash integer (0/1) flash=1 (for flash SMS)
unicode integer (0/1) unicode=1 (for unicode SMS)
schtime date and time When you want to schedule the SMS to be sent. Time format could be of your choice you can use Y-m-d h:i:s (2020-01-01 10:10:00) Or Y/m/d h:i:s (2020/01/01 10:10:00) Or you can send unix timestamp (1577873400)
afterminutes integer Time in minutes after which you want to send sms.
response varchar By default you will get response in string format but you want to receive in other format (json,xml) then set this parameter. for example: &response=json or &response=xml
campaign varchar Campaign name you wish to create.

operator supports.

  • route=1 for promotional
  • route=4 for transactional

SMS API

1. SendTransactional & SendPromotional Using GET

  • GET Method

Input Data

  • $mobileNumber "919541,919728" String 9195********3 Integer
  • $data Array

Sample Input 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. SendBulkSms Using POST

  • POST Method

Input Data

  • $data Array

Sample Input 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);

Sample 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>

Sample Output

5134842646923e183d000075

Note : Output will be request Id which is alphanumeric and contains 24 character like mentioned above. With this request id, delivery report can be viewed. If request not sent successfully, you will get the appropriate error message. View error codes

OTP API

Msg91 Send OTP

SEND OTP

  • GET Method
GET
http://api.msg91.com/api/sendotp.php?authkey=YourAuthKey&mobile=919999999990&message=Your%20otp%20is%202786&sender=senderid&otp=2786
Parameter name Data type Description
authkey * alphanumeric Login authentication key (this key is unique for every user)
mobile * integer Keep number in international format (with country code)
message varchar Message content to send. (default : Your verification code is ##OTP##.)
sender varchar Receiver will see this as sender's ID. (default : OTPSMS)
otp integer OTP to send and verify. If not sent, OTP will be generated.
otp_expiry integer Expiry of OTP to verify, in minutes (default : 1 day, min : 1 minute)
otp_length integer Number of digits in OTP (default : 4, min : 4, max : 9)

Input Data

  • authkey * alphanumeric
  • mobile * Integer
  • message varchar
  • sender varchar
  • otp Integer
  • otp_expiry Integer
  • otp_length Integer

Sample Input Data

$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);

Sample Output

{"message":"3763646c3058373530393938","type":"success"}

RESEND OTP

  • GET Method
http://api.msg91.com/api/retryotp.php?authkey=YourAuthKey&mobile=919999999990&retrytype=voice
Parameter name Data type Description
authkey * alphanumeric Login authentication key (this key is unique for every user)
mobile * integer Keep number in international format (with country code)
retrytype varchar Method to retry otp : voice or text. Default is voice.

Input Data

  • $mobile Integer
  • $retrytype String

Sample Input Data

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)

Sample Output

{"message":"otp_sent_successfully","type":"success"}

VERIFY OTP

  • GET Method
http://api.msg91.com/api/verifyRequestOTP.php?authkey=YourAuthKey&mobile=919999999990&otp=2786
Parameter name Data type Description
authkey * alphanumeric Login authentication key (this key is unique for every user)
mobile * integer Keep number in international format (with country code)
otp * varchar OTP to verify

Input Data

  • $mobile Integer
  • $otp string

Sample Input Data

OtpSend::verifyOtp(919***41,9195421);

API

use Sender\Otp;

$otp = new Otp();
$otp->verifyOtp($mobile,$otp);

Sample Output

{"message":"number_verified_successfully","type":"success"}

NOTE:

- Mobile number not attached `+` sign like this `+9195*****41`

Get in touch

If you have any suggestions, feel free to email me at venkatsamuthiram5@gmail.com or ping me on Twitter with @venkatskpi.