A library for iranian sms panels.
This is version alpha
composer
composer require mmdm/sim-fa-sms
Or you can simply download zip file from github and extract it, then put file to your project library and use it like other libraries.
Just add line below to autoload files:
require_once 'path_to_library/autoloader.php';
and you are good to go.
For convenient it has a factory class that can instantiate appropriate class according to your panel. If there is no such panel type, it'll return null.
// SMSFactory from Sim\SMS\SMSFactory namespace
$panel = SMSFactory::instance(SMSFactory::PANEL_NIAZPARDAZ);
Or you can simply create an instance from a specific panel like a simple class
$niazPardaz = new \Sim\SMS\Factories\NiazPardaz();
If panel supports specifying your panel number, you can use this method.
$panel->fromNumber(your_panel_number);
Usually SMS panels need username and password to connect.
$panel->credit(your_panel_username, your_panel_password);
Set extra or needed parameters to do related functionality
$panel->setParameter('fromNumber', your_panel_number);
// also you can set parameter like an object
$panel->fromNumber = your_panel_number;
Get a parameter if is exists or returns $prefer
Note: When you use object accessing, it'll returns null and triggers error
$panel->getParameter('fromNumber');
// also you can get parameter like an object
$panelNumber = $panel->fromNumber;
Send message to some numbers.
-
Set numbers that want send message to
-
Get numbers that want send message to
-
Specify the message to send
-
Get the message to send
Get sms panel credit
$creditCount = $panel->getCredit();
Get status after some operations like send.
The return will be in following structure:
[
'code' => a code according to operation,
'message' => a message according to code,
]
In some operations the status will be an array of previous structure.
[
[
'code' => a code according to operation,
'message' => a message according to code,
],
[
'code' => a code according to operation,
'message' => a message according to code,
],
...
]
Return boolean to show if an operation is successful or not
// call after an operation
$isSuccessful = $panel->isSuccessful();
Set a closure when an error happen. This closure have three parameters to access:
-
error code
-
error message
-
parameters of the functionality
$panel->onError(function ($code, $message, $parameters) {
// do something
});
Supported panels:
- NiazPardaz
$niazPardaz = new \Sim\SMS\Factories\NiazPardaz();
// or add credentioal information in construct
$niazPardaz = new \Sim\SMS\Factories\NiazPardaz(panel_username, panel_password);
For rest of methods please see documentation of the panel
- Use with send method
To add a new panel you can implement ISMS
interface.
Or if you want to have some functionality you can extend AbstractSMS
and add your new functionality for new panel.
Under MIT license.