$url = 'https://rest.nexmo.com/sms/json?api_key=xxx&api_secret=xxx&from=NEXMO&to=xxxxx&text=Welcome+to+Nexmo';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
当我执行它时,响应为空。
但是当我在浏览器上访问url时,它会给出api.txt文件,这些文件有响应,我得到的是我刚刚使用该URL发送的短信。
答案 0 :(得分:2)
我尝试过相同的代码:
$url = 'https://rest.nexmo.com/sms/json?api_key=KEY&api_secret=SECRET&from=NEXMO&to=TO_NUMBER&text=Welcome+to+Nexmo';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
echo($response);
我收到回复:
{
"message-count": "1",
"messages": [{
"to": "TO_NUMBER",
"message-id": "MESSAGE_ID",
"status": "0",
"remaining-balance": "7.25697349",
"message-price": "0.03330000",
"network": "23415"
}]
}%
正如您所看到的,响应似乎已经填充。所以,它似乎有效。
我个人建议使用nexmo-php库,因为Nexmo正式支持它(我为之工作)。
$client = new Nexmo\Client(new Nexmo\Client\Credentials\Basic(API_KEY, API_SECRET));
$message = $client->message()->send([
'to' => NEXMO_TO,
'from' => NEXMO_FROM,
'text' => 'Test message from the Nexmo PHP Client'
]);