abotalebie/ippanel-php-rest-sdk

IPPanel REST API client

v1.0.2 2022-06-05 12:57 UTC

This package is auto-updated.

Last update: 2024-10-31 00:23:31 UTC


README

This repository contains open source PHP client for ippanel api. Documentation can be found at: http://docs.ippanel.com.

Build Status

Installation

use with composer:

composer require ippanel/php-rest-sdk

if you don't want to use composer, you can download it directly :

wget https://github.com/ippanel/php-rest-sdk/archive/master.zip

Examples

For using sdk, you have to create a client instance that gives you available methods on API

require 'autoload.php';

// you api key that generated from panel
$apiKey = "api-key";

$client = new \IPPanel\Client($apiKey);

...

Credit check

# return float64 type credit amount
$credit = $client->getCredit();

Send one to many

For sending sms, obviously you need originator number, recipients and message.

$bulkID = $client->send(
    "+9810001",          // originator
    ["98912xxxxxxx"],    // recipients
    "ippanel is awesome" // message
);

If send is successful, a unique tracking code returned and you can track your message status with that.

Get message summery

$bulkID = "message-tracking-code";

$message = $client->get_message($bulkID);

echo $message->status;   // get message status
echo $message->cost;     // get message cost
echo $message->payback;  // get message payback

Get message delivery statuses

$bulkID = "message-tracking-code"

list($statuses, $paginationInfo) = $client->fetchStatuses($bulkID, 0, 10)

// you can loop in messages statuses list
foreach($statuses as status) {
    echo sprintf("Recipient: %s, Status: %s", $status->recipient, $status->status);
}

echo sprintf("Total: ", $paginationInfo->total);

Inbox fetch

fetch inbox messages

list($messages, $paginationInfo) = $client->fetchInbox(0, 10);

foreach($messages as $message) {
    echo sprintf("Received message %s from number %s in line %s", $message->message, $message->sender, $message->number);
}

Pattern create

For sending messages with predefined pattern(e.g. verification codes, ...), you hav to create a pattern. a pattern at least have a parameter. parameters defined with %param_name%.

$pattern = $client->createPattern("%name% is awesome", False);

echo $pattern->code;

Send with pattern

$patternValues = [
    "name" => "IPPANEL",
];

$bulkID = $client->sendPattern(
    "t2cfmnyo0c",    // pattern code
    "+9810001",      // originator
    "98912xxxxxxx",  // recipient
    $patternValues,  // pattern values
);

Error checking

use IPPanel\Errors\Error;
use IPPanel\Errors\HttpException;

try{
    $bulkID = $client->send("9810001", ["98912xxxxx"], "ippanel is awesome");
} catch (Error $e) { // ippanel error
    var_dump($e->unwrap()); // get real content of error
    echo $e->getCode();

    // error codes checking
    if ($e->code() == ResponseCodes::ErrUnprocessableEntity) {
        echo "Unprocessable entity";
    }
} catch (HttpException $e) { // http error
    var_dump($e->getMessage()); // get stringified error
    echo $e->getCode();
}