Git Product home page Git Product logo

osms-php's Issues

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!

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

// ...
}

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 ?

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

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.

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

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

multiple receiver

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

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.

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.