简体   繁体   English

PHP上的Nexmo SMS API返回false,但在浏览器上未返回

[英]Nexmo sms API on PHP return false but not on browser

$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);

When I executed it, the response was null. 当我执行它时,响应为空。

but when I access the url on browser, It gives api.txt files which has the response and I get the sms which I just send using that url. 但是当我在浏览器上访问该URL时,它会给出具有响应的api.txt文件,并且会收到我只是使用该URL发送的短信。

I've tried the same code: 我试过相同的代码:

$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);

And I get the response: 我得到答复:

{
    "message-count": "1",
    "messages": [{
        "to": "TO_NUMBER",
        "message-id": "MESSAGE_ID",
        "status": "0",
        "remaining-balance": "7.25697349",
        "message-price": "0.03330000",
        "network": "23415"
    }]
}%

As you can see, the response seems to be populated. 如您所见,响应似乎已被填充。 So, it seems to work. 因此,它似乎有效。

I'd personally recommend using the nexmo-php library since it's officially supported by Nexmo (who I work for). 我个人建议使用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'
]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM