【问题标题】:Could not be able to get correct result of nexmo sample code无法获得 nexmo 示例代码的正确结果
【发布时间】:2026-01-01 00:10:01
【问题描述】:

我在 Nexmo 创建了帐户,并尝试了来自 here 的示例

<?php
$url = 'https://rest.nexmo.com/sms/json?' . http_build_query(
    [
      'api_key' =>  'API_KEY',
      'api_secret' => 'API_SECRET',
      'to' => 'HERE REAL NUMBER',
      'from' => 'HERE REAL NUMBER',
      'text' => 'Hello from Nexmo'
    ]
);

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);

echo $response;

但是当我尝试时,这段代码没有回显任何内容

curl "https://rest.nexmo.com/sms/json?api_key=KEY&api_secret=SECRET&from=NEXMO&to=911234567890&text=Welcome+to+Nexmo"

我得到回应

 {
        "message-count": "1",
        "messages": [{
            "to": "911234567890",
            "message-id": "070000000279DB5A",
            "status": "0",
            "remaining-balance": "1.96000000",
            "message-price": "0.02000000",
            "network": "41001"
        }]
    }

如何让php代码正常工作?

【问题讨论】:

  • 显示 var_dump($url); http_build_query 之后
  • 我听不懂你要什么?你会详细说明吗?

标签: php vonage


【解决方案1】:

我知道这个问题很老了,但我仍然想回答它。 您必须将 API_KEY 和 API_SECRET 值替换为 NEXMO 为您的帐户提供的值。

【讨论】: