First of all, goto the Nexmo site.
Complete signup process.
After completing signup process.
Goto Account settings section,
In account setting section,there is also a sub-section named API Settings.
In this section you will find two things to genrate a number in nexmo..
- Api Key
- Api Secret
Now create a function in php as described below:
function virtual_number_generate(){ $base_url = 'https://rest.nexmo.com'; $action = '/number/search'; $theurl = $base_url . $action . "?" . http_build_query([ 'api_key' => 'API_KEY', 'api_secret' => 'API_SECRET', 'country' => 'US', 'features' => 'SMS', 'size' => 1 ]); $ch = curl_init($theurl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json')); curl_setopt($ch, CURLOPT_HEADER, array('Content-Type: application/x-www-form-urlencoded')); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_HEADER, 0); $response = curl_exec($ch); $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $header = substr($response, 0, $header_size); $body = substr($response, $header_size); if (strpos($header, '200')){ $virtual_numbers = json_decode($body, true); foreach ( $number as $virtual_numbers ) { //If $number matches your criteria, buy it using //POST https://rest.nexmo.com/number/buy/ } } else { $myhead=(array)json_decode($header,true); $msidn=($myhead['numbers'][0]['msisdn']); $concatenate_json = $header.$body; } return ($msidn); }
Description:
This is an HTTPS request to the Nexmo Number Search, it will hit the server of Nexmo and find some virtual number to generate.In our case first we will try to generate some test numbers and afterwards go for the live number generation.
There is a curl call request which provides you some virtual number in response to work with.
This number is useful in sending messages to different countries. You can visit Nexmo for more information…