我正在尝试使用 OneAPI SMS 接口使用 cURL 从我的应用程序发送 SMS 消息。
它返回 500 错误,这是我正在使用的代码:
<?php
$url = "https://oneapi-gw.gsma.com/smssend/2_0/smsmessaging/outbound/tel%3A%2B1234/requests";
$username = "secret";
$password = "secret";
$request = array(
'address' => 'tel%3A%2B1222333444',
'message' => 'hello world',
'senderAddress' => 'tel%3A%2B1234',
'senderName' => 'joe doe'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($request));
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
print_r($info);
?>
任何帮助将不胜感激。谢谢!
附言
Array ( [url] => https://oneapi-gw.gsma.com/smssend/2_0/smsmessaging/outbound/tel%3A%2B1416XXXYYYY/requests
[content_type] => application/json [http_code] => 500 [header_size] => 494 [request_size] => 349
[filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.333515 [namelookup_time] => 0.000335
[connect_time] => 0.054989 [pretransfer_time] => 0.229044 [size_upload] => 97 [size_download] => 172 [speed_download] => 515
[speed_upload] => 290 [download_content_length] => -1 [upload_content_length] => 97 [starttransfer_time] => 0.333474 [redirect_time] => 0 [certinfo] => Array ( ) )
解决了
对于祖先:由于某些原因 cURL 不起作用,所以 file_get_contents() 是要走的路。