Request-URI太长 - SMS API

时间:2017-07-11 13:53:23

标签: php apache api curl bulksms

我的问题不知何故特别。我有来自我的提供商的这个bulksms api:

http://www.estoresms.com/smsapi.php?username=user&password=1234&sender=@@sender@@&recipient=@@recipient@@&m
essage=@@message@@&

然后我用PHP包装它并在cURL中传递它:

$api = "http://www.estoresms.com/smsapi.php?username=".$sms_user."&password=".$sms_pwd."&sender=".$sender_id."&recipient=".$numbers."&message=".$text."&";

function curl_get_contents($url)
{   
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$send_it =  curl_get_contents($api);
通常,它工作正常,但当$ recepient(电话号码)超过300时,我收到错误:

请求URI太长 请求的URL长度超出了此服务器的容量限制。 此外,尝试使用ErrorDocument处理请求时遇到414 Request-URI Too Long错误。

但是BulkSMS应该能够一次发送到数千个号码。 根据我的研究,我发现URL存在限制。我不是服务器所有者。我正在制定共享主机方案。请问我该如何解决这个问题。我知道有一个解决方案,这并不意味着购买我自己的服务器。

由于

3 个答案:

答案 0 :(得分:0)

您可以尝试让API使用POST而不是GET。它可以解决这个问题。

编辑:

我不确定您的API检查POST,但请尝试:

$api = "http://www.estoresms.com/smsapi.php";
$data = array('username' => $sms_user, 'password' => $sms_pwd, 'sender' => $sender_id , 'recipient' => $numbers , 'message' => $text);

function curl_get_contents($url)
{   
$ch = curl_init($url);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$send_it =  curl_get_contents($api);

答案 1 :(得分:0)

看看这个代码示例(来自bulksms.com)。

http://developer.bulksms.com/eapi/code-samples/php/send_sms/

答案 2 :(得分:0)

那么,我必须找到解决自己问题的方法。如果API一次不允许数千个数字,那么让我们在执行时将其分成几个块。

    function curl_get_contents($url)
    {   
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
    }

    $how_many = count(explode(',',  $numbers));
    if ($how_many > 250){
    $swi = range(0, ceil($how_many/250)-1); 
    foreach ($swi as $sw){$numbers_a = implode(',', (array_slice(explode(',', $numbers), $sw*250, 250)));
    $api = "http://www.estoresms.com/smsapi.php?username=".$sms_user."&password=".$sms_pwd."&sender=".$sender_id."&recipient=".$numbers_a."&message=".$text."&";


    $send_it =  curl_get_contents($api);
    }
    }

if ($how_many <= 250){
    $api = "http://www.estoresms.com/smsapi.php?username=".$sms_user."&password=".$sms_pwd."&sender=".$sender_id."&recipient=".$numbers."&message=".$text."&";
$send_it =  curl_get_contents($api);    
}
相关问题