prawnsalad / nexmo-php-lib Goto Github PK
View Code? Open in Web Editor NEWNexmo SMS gateway example library
License: MIT License
Nexmo SMS gateway example library
License: MIT License
Sending SMS via the Nexmo SMS gateway. Quick Examples -------------- 1) Sending an SMS $sms = new NexmoMessage('account_key', 'account_secret'); $sms->sendText( '+447234567890', 'MyApp', 'Hello world!' ); 2) Recieving SMS $sms = new NexmoMessage('account_key', 'account_secret'); if ($sms->inboundText()) { $sms->reply('You said: ' . $sms->text); } 3) Recieving a message receipt $receipt = new NexmoReceipt(); if ($receipt->exists()) { switch ($receipt->status) { case $receipt::STATUS_DELIVERED: // The message was delivered to the handset! break; case $receipt::STATUS_FAILED: case $receipt::STATUS_EXPIRED: // The message failed to be delivered break; } } 4) List purchased numbers on your account $account = new NexmoAccount('account_key', 'account_secret'); $numbers = $account->numbersList(); Most Frequent Issues -------------------- Sending a message returns false. This is usually due to your webserver unable to send a request to Nexmo. Make sure the following are met: 1) Either CURL is enabled for your PHP installation or the PHP option 'allow_url_fopen' is set to 1 (default). 2) You have no firewalls blocking access to rest.nexmo.com/sms/json on port 443. Your message appears to have been sent but you do not recieve it. Run the example.php file included. This will show any errors that are returned from Nexmo.
It is useful to find where the files are from.
Not sure why I'm getting this. I'm not a pro with composer, but I included this package like so:
"require" : {
"prawnsalad/nexmo": "dev-master"
}
The package gets built in my vendor folder no problem, but when I try running:
require 'vendor/autoload.php';
$sms = new NexmoMessage(NEXMO_KEY, NEXMO_SECRET);
$sms->sendText($phone, "app", "yo");
I get the error: Fatal error: Class 'NexmoMessage' not found. Any idea why this could be? I also tried explicitly use NexmoMessage, but that didn't work either. Thanks
anyway to build in an option to send to multiple numbers,
Hi, thanks for your work on this PHP lib!
I was trying to run the example with my Nexmo account.
I have of course replaced the key and the secret but I unfortunately obtain "Cannot display an overview of this response".
I tried to debug the problem.
Apparently $from_nexmo is empty while this is $to_nexmo:
Array ( [url] => https://rest.nexmo.com/sms/json [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => 0 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0 [namelookup_time] => 0 [connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 0 [redirect_time] => 0 )
Does this look correct?
Am I doing something wrong?
Thank you.
https://docs.nexmo.com/index.php/sms-api/handle-inbound-message
Some of the missing:
keyword: First word in the message body, typically used with short codes
concat: Set to true if a MO concatenated message is detected
concat-ref: Transaction reference, all message parts will shared the same transaction reference
concat-total: The total number of parts in this concatenated message set
concat-part: The part number of this message within the set (starts at 1)
Or you could have an originalMessage property what would hold all get parameters so that new additions to Nexmo API can be used without updating your library.
I noticed these kind of constructors in the classes:
function NexmoMessage ($api_key, $api_secret) {
$this->nx_key = $api_key;
$this->nx_secret = $api_secret;
}
I believe these are PHP4 style constructors and if I'm not mistaken, will be deprecated. It might be good to replace them with proper constructors instead:
Could you please add a license file?
Currently I'm not sure under what license your source is.
Hello,
I installed that library in my local server.
I added api key and secret with to and from parameter in example.php
When i run example.php page in local then display OK status but message not send in phone number.
I am in india and a also add country code before phone number.
Also i used free account of nexmo.
Please guide me what is the problem?
Hello,
I'm currently using this lib to connect to the Nexmo API. But I'm having some issues with the length of a text message.
I have a message that contains 160 chars, but still get split up into 3 separate SMS messages. According to the Nexmo website, 160 characters should fit into 1 message.
But why doesn't Nexmo send just 1 message?
Hi?
There was some problem in using normaliseKeys() in my environment. The problem was caused by 'instanceof' function. To workaround this, I changed this to something like is_a($obj, '\stdClass') instead.
To keep the maintainability I don't want to make a modification to your code directly. It would be nice if I can override the method at child class.
I found an error when authentication fails on nexmo.
The function "nexmoParse" parses every messages and sums the total cost like this:
$total_cost = $total_cost + (float)$msg->messageprice;
But when you have an authentication error the parser gives an error because "messageprice" is not defined.
I corrected myself by change the code to:
if (isset($msg->messageprice)) {
$total_cost = $total_cost + (float)$msg->messageprice;
}
Can you please add a basic composer.json and then add the library to packagist.org?
The content of the json file should be something like
{
"description": "PHP library for sending text messages via Nexmo.",
"name": "prawnsalad/nexmo-php-lib",
"type": "library",
"keywords" : ["nexmo", "php"],
"homepage": "https://github.com/prawnsalad/Nexmo-PHP-lib"
],
"require": {
"php": ">=5.3.2"
},
"autoload": {
"psr-0": {
"Nexmo": ""
}
}
}
In composer.json
it is specified that a PSR-4 Autoloader can be used:
https://github.com/prawnsalad/Nexmo-PHP-lib/blob/master/composer.json#L8-L10
However, the classes in the library do not have a namespace
which is required by PSR-4 http://www.php-fig.org/psr/psr-4/
Either a namespace
should be added to all three classes like so:
namespace PrawnSalad\Nexmo;
or the composer.json
should be updated to use a classmap
instead of PSR-4
https://getcomposer.org/doc/04-schema.md#classmap
curl_setopt($to_nexmo, CURLOPT_SSL_VERIFYPEER, false);
if curl cant verify the cert it will fail to send request .
Undefined index: numbers in Nexmo-PHP-lib-master/NexmoAccount.php [117]
CURLOPT_SSL_VERIFYPEER
should be true
.
https://github.com/prawnsalad/Nexmo-PHP-lib/blob/master/NexmoAccount.php#L196
Hi. Would you consider adding this lib to packagist.org please? That way it can be downloaded & managed via Composer.
It's just a matter of creating a composer.json file and then submitting the repo to https://packagist.org
Hello
Is that possible to create a release tag like 1.0.0 ?
Like this we can use it with composer in a clean way instead of putting dev-master.
Thank you
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.