ismaeltoe / osms-php Goto Github PK
View Code? Open in Web Editor NEWA PHP library to access Orange SMS API.
License: MIT License
A PHP library to access Orange SMS API.
License: MIT License
the instance class with correct credentials but sendSms() method returns an error :
The requested service needs credentials, but none were provided.
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!
An "Array to string conversion" error gets trigggered when sending a request:
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);
}
// ...
}
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 ?
sms not send to non-orange number in sms-egypt
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
Je veux savoir comment changer l'entete.
Merci
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.
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;
}
I have this error when i run sendSms.php
API call failed with cURL error: SSL certificate problem: unable to get local issuer certificate
how i can add multiple receiver:
$receiverAddress = 'tel:+22500000000 other tel';
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
)
)
)
)
)
)
this is my current problem.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.