Git Product home page Git Product logo

osms-php's Introduction

Osms

A PHP library to access Orange SMS API.

Current version: 2.0.1

Installation

With Composer (recommended)

Install Composer. Then, do:

$ composer require ismaeltoe/osms

Without Composer

Simply download the latest release.

Loading

You can load the class using Composer's autoloading:

require 'vendor/autoload.php';

Otherwise, you can simply require the file directly:

require 'path/to/Osms.php';

Quick Start

Case 1: You have no access token

require 'vendor/autoload.php';

use \Osms\Osms;

$config = array(
    'clientId' => 'your_client_id',
    'clientSecret' => 'your_client_secret'
);

$osms = new Osms($config);

// retrieve an access token
$response = $osms->getTokenFromConsumerKey();

if (!empty($response['access_token'])) {
    $senderAddress = 'tel:+22500000000';
    $receiverAddress = 'tel:+22500000000';
    $message = 'Hello World!';
    $senderName = 'Optimus Prime';

    $osms->sendSMS($senderAddress, $receiverAddress, $message, $senderName);
} else {
    // error
}

Case 2: You have an access token

require 'vendor/autoload.php';

use \Osms\Osms;

$config = array(
    'token' => 'your_access_token'
);

$osms = new Osms($config);

$senderAddress = 'tel:+22500000000';
$receiverAddress = 'tel:+22500000000';
$message = 'Hello World!';
$senderName = 'Optimus Prime';

$osms->sendSMS($senderAddress, $receiverAddress, $message, $senderName);

Check out examples for more examples.

CHECK OUT also Osms.php to see all the methods available. But DON'T MODIFY IT. You can extend the class to add your own stuff.

SSL certificate problem

If you get an SSL error, set the peer's certificate checking option to false:

$osms = new Osms();
$osms->setVerifyPeerSSL(false);

But it should work on your hosting server, so enable the certificate checking when you are ready to deploy your application for security reasons.

Documentation

Other Libraries

License

Released under the MIT License - see LICENSE.txt for details.

osms-php's People

Contributors

ismaeltoe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

osms-php's Issues

Upgrate Oauth to v3

As recommended by OD please upgrate Oauth to v3

public function getTokenFromConsumerKey()
{
$url = self::BASE_URL . '/oauth/v3/token';

    $credentials = $this->getClientId() . ':' . $this->getClientSecret();

    $headers = array('Authorization: Basic ' . base64_encode($credentials));

    $args = array('grant_type' => 'client_credentials');

    $response = $this->callApi($headers, $args, $url, 'POST', 200);

    if (!empty($response['access_token'])) {
        $this->setToken($response['access_token']);
    }

    return $response;
}

Error: Array to string conversion on Osms.php (line 291)

An "Array to string conversion" error gets trigggered when sending a request:

image

Here's the code used when error was triggered:

       $config = [
            'clientId' => 'xxxxxxx',
            'clientSecret' => 'xxxxxxx'
        ];

        $orangeSmsClient = new Osms($config);
        $orangeSmsClient->setVerifyPeerSSL(false);

        $response = $orangeSmsClient->getTokenFromConsumerKey();


        $sndSms = $orangeSmsClient->sendSMS("+216000000", "+2160000", "Hi X, this is a test message.");

The exception thrown reads as follow:

array(1) { 
    ["requestError"]=> array(1) { 
        ["serviceException"]=> array(3) { 
                                    ["messageId"]=> string(7) "SVC0004" 
                                    ["text"]=> string(46) "No valid addresses provided in message part %1"
                                    ["variables"]=> array(1) {
                                              [0]=> string(13) "senderAddress"
                                    }
                           }
                   }
 }

As can be seen above, the "variables" index contains an array and not string, said values are stand ins or placeholders for the error message (in the "text" index).

Corrective:

Edit this:

$errorMessage = $response['requestError']['serviceException']['text']
                    . ' ' . $response['requestError']['serviceException']['variables'];

Into this:

$errorMessage = $response['requestError']['serviceException']['text'];
$errorVariables = $response['requestError']['serviceException']['variables'];

foreach ($errorVariables as $key => $errorVariable) {
$errorMessage = str_replace('%'.strtoupper($key+1), $errorVariable, $errorMessage);
}

Or better yet, add a method;

private function getErrorMessage(string $exceptionType, array $response)
    {
        $message = '';
        $exceptionTypes = ['serviceException', 'policyException'];

        if (in_array($exceptionType, $exceptionTypes)) {

            $message = $response['requestError'][$exceptionType]['text'];
            $errorVariables = $response['requestError']['serviceException']['variables'];

            if (!empty($errorVariables) && is_array($errorVariables)) {
                foreach ($errorVariables as $key => $errorVariable) {
                    $message = str_replace('%'.strtoupper($key+1), $errorVariable, $message);
                }
            }

        }

        return $message;
    }

Then modify the "callApi" method from to reflect these changes:

public function callApi( ... )
{
// ...

if ($httpCode !== $successCode) {
            $errorMessage = '';

            if (!empty($response['error_description'])) {
                $errorMessage = $response['error_description'];
            } elseif (!empty($response['error'])) {
                $errorMessage = $response['error'];
            } elseif (!empty($response['description'])) {
                $errorMessage = $response['description'];
            } elseif (!empty($response['message'])) {
                $errorMessage = $response['message'];
            } elseif (!empty($response['requestError']['serviceException'])) {
                $errorMessage = $this->getErrorMessage('serviceException', $response); 
            } elseif (!empty($response['requestError']['policyException'])) {
                $errorMessage = $this->getErrorMessage('policyException', $response); 
            }

            return array('error' => $errorMessage);
        }

// ...
}

ssl error

I have this error when i run sendSms.php
API call failed with cURL error: SSL certificate problem: unable to get local issuer certificate

Does Orange API sms sends messages to Etisalat and Vodafone ?

I tried to send an sms to Orange phone number and it was sent successfully! but when i tried to send to Etisalat or Vodafone number there weren't sent and the bundle decreased by two.

does orange API sms sends sms messages to Etisalat and Vodafone ?

Thank you!

senderName name create automatily when i send the sms to user

that is my code

$config = array(
'clientId' => '**',
'clientSecret' => '
'
);

	$osms = new Osms($config);
	$osms->setVerifyPeerSSL(false);

	// retrieve an access token
	$response = $osms->getTokenFromConsumerKey();
	//dd($response);
	if (!empty($response['access_token'])) {
	    $senderAddress = 'tel:+243*******';
	    $receiverAddress = 'tel:+243********';
	    $message = 'Hello World OK ORANGE!';
	    $senderName = 'DANIEL';            // the problem is sendername
	    
	    $datadan=$osms->sendSMS($senderAddress, $receiverAddress, $message, $senderName);
	    //dd($datadan);
	} else {
		// dd("eee");
	    // error
	}

i need yor help please

multiple receiver

how i can add multiple receiver:
$receiverAddress = 'tel:+22500000000 other tel';

Features

My API is working !

I have two questions please:

  • How to customize sender name ? my sender_name var is set but the receiver got a strange name (SMS09...)

  • How to check the balance before sending an SMS ?

recovery of two lines in the getAdminContracts.php file

in getAdminContracts.php file which displays everything:

Array
(
[partnerContracts] => Array
(
[partnerId] => [email protected]
[contracts] => Array
(
[0] => Array
(
[service] => SMS_OCB
[contractDescription] => SMS API: your balance (per country)
[serviceContracts] => Array
(
[0] => Array
(
[country] => CIV
[service] => SMS_OCB
[contractId] => 18f251d0-2b23-4097-8209-2a171df5589c
[availableUnits] => 91
[expires] => 2021-07-17T01:00:00
[scDescription] => Côte d'Ivoire - 91 units to consume before July 17, 2021 1:00 AM

)

                            )

                    )

            )

    )

)

I want to fetch only two lines and display, line [expires] and line [scDescription].

this is my current problem.

SMS is not sent

I've made everything right and generated my access token perfectly.

I get no error , and SMS is supposed sent correctly.

BUt im receiving nothing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.