0
$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 发送的短信。

4

1 回答 1

3

我试过相同的代码:

$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'
]);
于 2016-10-13T15:36:00.970 回答