2017-07-11 69 views
0

我的問題是某種奇怪的。我有這個bulksms API從我的供應商:請求 - URI太長 - 短信API

http://www.estoresms.com/smsapi.php?username=user&password=1234&[email protected]@[email protected]@&[email protected]@[email protected]@&m 
[email protected]@[email protected]@& 

然後我把它包在PHP和捲曲通過它:

$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請求 - URI太長錯誤。

但BulkSMS應該能夠一次發送到數千個數字。 從我的研究中,我發現URL有一個限制。我不是服務器所有者。我正在制定共享託管計劃。請問我該如何解決這個問題。我知道有一個解決方案,並不意味着購買我自己的服務器。

謝謝

回答

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);  
} 
0

您可以嘗試使API使用POST而不是GET。它會解決這個問題。

編輯:

我不知道你的API檢查崗,但嘗試:

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

請問我該如何去使用POST?謝謝 – david

+0

我試過了,它沒有工作。即使對於任何數字,無論是很少還是很多。我的原始代碼有效。問題在於數字如此之多時,失敗了。 – david

+0

這意味着API不讀取POST數據,這很奇怪,因爲據我瞭解,這是他們服務的傢伙請求? –