短信发送 URL 无法使用 curl

SMS sending URL Not working With curl

我正在使用以下代码通过 php curl 发送短信。当我处于 运行 $apiURL 时从浏览器使用它对我来说工作正常。但是使用下面的 curl 代码是行不通的。 OI gtting O/P 作为 string(0) ""。我做错了什么,请帮助我。

$conturyCode = "91";
$client_mobile = "96******18";
$new_centername = "Apple Hospital";
$address = "Lal Darvaja,ringroad,surat(394220)";
$center_mobile = "86******91";
$apiURL = "http://103.16.101.52:8080/bulksms/bulksms?username=abc-def&password=abc123&type=0&dlr=1&destination=".$conturyCode.$client_mobile."&source=ABC&message=Scheduled at ".$new_centername." and ".$address." and ".$center_mobile;

//  Initiate curl
$ch = curl_init();
//Set User client
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0");

curl_setopt($ch, CURLOPT_VERBOSE, true);
// Set The Response Format to Json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
// Set Auto referer
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL, $apiURL);
// Execute
$result = curl_exec($ch);

// Check if any error occurred
if(curl_errno($ch))
{
    echo 'Curl error: ' . curl_error($ch);
}

// Closing
curl_close($ch);

var_dump($result);

我没有使用过那个特定的 API,但我建议使用 Nexmo 的 SMS API。此 API 可以轻松集成到您的应用程序中,提高您的交付率,并让您安心,因为您正在使用受大品牌 apps/companies 信任的 SMS API 网关世界.

我工作的 Nexmo 有一个 SMS API 允许您轻松地向 200 多个国家/地区的手机发送 SMS 消息。

API 非常可靠、安全,并且易于集成到您的应用程序中。

您需要做的就是进行一个简单的 HTTP 调用。

您可以查看每个国家/地区的定价 here

下面是 PHP 中的一些示例代码,可让您开始向世界各地发送短信。报名免费试用后,将自己的api_keyapi_secret替换为fromtext(以及您可能需要的任何其他 可选参数 ) .

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

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

这是使用 Nexmo's SMS API

发送消息的文档

试试下面的代码:

$message = urlencode("Scheduled at ".$new_centername." and ".$address." and ".$center_mobile);
$apiURL = "http://103.16.101.52:8080/bulksms/bulksms?username=abc-def&password=abc123&type=0&dlr=1&destination=".$conturyCode.$client_mobile."&source=ABC&message=".$message;

您传递的消息需要 url 编码。

在我的例子中,下面的代码成功运行

$abc= 'http://bullet1.sdctechnologies.co.in:8080/api/mt/SendSMS?user='.$sms_username.'&password='.$sms_password.'&senderid='.$sms_sender_id.'&channel=Trans&DCS=0&flashsms=0&number='.$txt_mobile.'&text='.$message.'';

$url = str_replace(" ","%20",$abc);
        $ch = curl_init();
        curl_setopt($ch,CURLOPT_URL,$url); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
        $response = curl_exec($ch);
        curl_close($ch);