短信发送网址无法使用curl

时间:2015-08-05 19:24:01

标签: php curl sms-gateway

我使用下面的代码通过php curl发送短信。在我运行$apiURL时从浏览器中,它对我来说很好。但是使用下面的curl代码它不起作用。 OI将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);

2 个答案:

答案 0 :(得分:2)

请尝试以下代码:

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

您传递的邮件需要进行网址编码。

答案 1 :(得分:0)

我还没有使用过特定的API,但我建议使用Nexmo的SMS API。此API可以轻松集成到您的应用中,提高您的投放率,让您高枕无忧,因为您使用的是受世界各地大型品牌应用/公司信赖的SMS API网关。

我工作的Nexmo有一个SMS API,可让您轻松地向200多个国家/地区的手机发送短信。

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

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

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

以下是PHP中的一些示例代码,可让您开始在世界各地发送文本。注册免费试用版后,将您自己的 api_key api_secret 改为替换为,然后 text (以及您可能需要的任何其他可选参数)。

<?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

发送消息的文档
相关问题