2017 © Pedro Peláez
 

library sms

This is a client of Opilo (www.opilo.com) Web Service

image

ahmad-klfr/sms

This is a client of Opilo (www.opilo.com) Web Service

  • Saturday, January 23, 2016
  • by ahmadklfr
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Webservice Client for opilo.com panel

In order to send and receive SMS via opilo.com panel, you should first create an instance object of class OpiloClient\V2\HttpClient. For that, first you need to configure your webservice in the configuration page., (*1)

Create a Client Object

use OpiloClient\Configs\Account;
use OpiloClient\Configs\ConnectionConfig;
use OpiloClient\V2\HttpClient;
...
$config = new ConnectionConfig('http://bpanel.opilo.com');
$account = new Account('YOUR_WEBSERVICE_USERNAME'), 'YOUR_WEBSERVICE_PASSWORD');
$client = new HttpClient($config, $account);

Sending SMS

Sending a Single SMS

use OpiloClient\Request\OutgoingSMS;
...
$message = new OutgoingSMS('3000****', '0912*******', 'Hello World!');
$responses = $client->sendSMS($message);

Sending a Batch of SMS at Once

$messages = [
    new OutgoingSMS('3000****', '0912*******', 'Hello World!'),
    new OutgoingSMS('3000****', '0912*******', 'Hello World!'),
];
$response = $client->sendSMS($messages);

Parsing The Return Value of sendSMS()

use OpiloClient\Response\SMSId;
use OpiloClient\Response\SendError;
...
for ($i = 0; $i < count($response); $i++) {
    if ($response[$i] instanceof SMSId) {
        //store $response[$i]->id as the id of $messages[$i] in your database and schedule for checking status if needed
    } else //$response[$i] instanceof SendError {
        //It could be that you run out of credit, the line number is invalid, or the receiver number is invalid.
        //To find out more examine $response[$i]->error and compare it against constants in SendError class
    }
}

Check the Inbox by Pagination

$minId = 0;
while (true) {
    $inbox = $client->checkInbox($minId);
    $messages = $inbox->getMessages();
    if (count($messages)) {
        foreach ($messages as $message) {
            //Process $message->opiloId(), $message->getFrom(), $message->getTo(), $message->getText(), and $message->getReceivedAt() and store them in your database
            $minId = max($minId, $message->getOpiloId() + 1);
        }
    } else {
        //no new SMS
        //Store $minId in your database for later use of this while loop! You don't need to start from 0 tomorrow!
        break;
    }
}

Checking the Delivery Status of Sent Messages

$opiloIds = $yourDatabaseRepository->getArrayOfOpiloIdsOfMessagesSentViaSendSMSFunction();
$response = $client->checkStatus($opiloIds);
foreach ($response->getStatusArray() as $opiloId => $status) {
    //process and store the status code $status->getCode() for the SMS with Id $opiloId
    //Take a look at constants in OpiloClient\Response\Status class and their meanings
}

Getting Your SMS Credit

$numberOfSMSYouCanSendBeforeNeedToCharge = $client->getCredit()->getSmsPageCount();

Exception Handling

All the functions in HttpClient may throw CommunicationException if the credentials or configurations are invalid, or if there is a network or server error. Prepare to catch the exceptions appropriately., (*2)

use OpiloClient\Response\CommunicationException;
...
try {
    ...
    $client->sendSMS(...);
    ...
} catch (CommunicationException $e) {
    //process the exception by comparing $e->getCode() against constants defined in CommunicationException class.
}

The Versions

23/01 2016

dev-master

9999999-dev

This is a client of Opilo (www.opilo.com) Web Service

  Sources   Download

The Requires

 

The Development Requires

by Hamid Alaei

sms web service messaging opilo