2012-02-08 3 views
0

私は、SMSプロバイダを使用してSMSを送信したい番号のデータベースを持っています。私のコードはsms apiと一緒にここにあります。初心者の問題は、自分のコードが単一のSMS用であり、私のデータベースをループして、データベースの各番号のカールを使って投稿したいということです。データベースをループしているCurl to smsプロバイダ

本当にありがとうございました。

$result = mysql_query($stremail); 
$emails = array(); 
while ($row = mysql_fetch_array($result)) { 
$recipient = $row['mobilenumber1']; 

class SendSMS 
{ 
private $url = 'http://'; // url of the service 
private $username = ''; // 
private $password = ''; // 

private $message_id,$credits_used; 

function __construct() 
{ 

} 

public function getMessageID() 
{ 
    return $this->message_id; 
} 

public function getCreditsUsed() 
{ 
    return $this->credits_used; 
} 


// public function to commit the send 
public function send($message,$recipient,$originator) 
{ 
    $url_array= array('message'=>$message,'mobile_number'=>$recipient,'originator'=>$originator,'username'=>$this->username, 'password'=>$this->password); 
    $url_string = $data = http_build_query($url_array, '', '&'); 

    // we're using the curl library to make the request 
    $curlHandle = curl_init(); 
    curl_setopt($curlHandle, CURLOPT_URL, $this->url); 
    curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $url_string); 
    curl_setopt($curlHandle, CURLOPT_POST, 1); 
    $responseBody = curl_exec($curlHandle); 
    $responseInfo = curl_getinfo($curlHandle); 
    curl_close($curlHandle); 

    return $this->handleResponse($responseBody,$responseInfo); 
} 


private function handleResponse($body,$info) 
{ 
    if ($info['http_code']==200){ // successful submission 
     $xml_obj = simplexml_load_string($body); 
     // extract message id and credit usuage 
     $this->message_id = (int) $xml_obj->message_id; 
     $this->credits_used = (int) $xml_obj->credits_used; 
     return true; 
    } 
    else{ 

     $this->message_id = null; 
     $this->credits_used = null; 

     // error handling 
     return false; 
    } 

} 

} 
$sms = new SendSMS(); 
$sms->send($message1,$recipient,"header"); 
echo "sent!"; 


} 

答えて

1
class SendSMS 
{ 
    private $url = 'http://'; // url of the service 
    private $username = ''; // 
    private $password = ''; // 

    private $message_id,$credits_used; 

    function __construct() 
    { 

    } 

    public function getMessageID() 
    { 
     return $this->message_id; 
    } 

    public function getCreditsUsed() 
    { 
     return $this->credits_used; 
    } 


    // public function to commit the send 
    public function send($message,$recipient,$originator) 
    { 
     $url_array= array('message'=>$message,'mobile_number'=>$recipient,'originator'=>$originator,'username'=>$this->username, 'password'=>$this->password); 
     $url_string = $data = http_build_query($url_array, '', '&'); 

     // we're using the curl library to make the request 
     $curlHandle = curl_init(); 
     curl_setopt($curlHandle, CURLOPT_URL, $this->url); 
     curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); 
     curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $url_string); 
     curl_setopt($curlHandle, CURLOPT_POST, 1); 
     $responseBody = curl_exec($curlHandle); 
     $responseInfo = curl_getinfo($curlHandle); 
     curl_close($curlHandle); 

     return $this->handleResponse($responseBody,$responseInfo); 
    } 


    private function handleResponse($body,$info) 
    { 
     if ($info['http_code']==200){ // successful submission 
      $xml_obj = simplexml_load_string($body); 
      // extract message id and credit usuage 
      $this->message_id = (int) $xml_obj->message_id; 
      $this->credits_used = (int) $xml_obj->credits_used; 
      return true; 
     } 
     else{ 

      $this->message_id = null; 
      $this->credits_used = null; 

      // error handling 
      return false; 
     } 

    } 

} 

$sms = new SendSMS(); 

$result = mysql_query($stremail); 

while ($row = mysql_fetch_array($result)) { 

    $recipient = $row['mobilenumber1']; 
    $sms->send($message1,$recipient,"header"); 

} 
+0

ありがとうv多くのArkouda、私はそれを試したと確信しているので、私はとても愚かな感じで、それは動作しませんでした - あまりにも長い間画面を見ていた! – Textus

0

あなたのSMSプロバイダを使用すると、APIインタフェースでバルクSMSを送信することができない場合、私はHQSMS.com SMSサービスをあなたにお勧めします。 HQSMSコードでは、カンマで区切られたより多くの数字に変数$に代入するだけです。シングルPOSTリクエストでは、10000までの数字が存在することがあります。詳しくはhttp://www.hqsms.com/help-api/https-api-interface/https-specificationでご覧になれます。 HQSMS.comは、オープンエンドの有効性とグローバルなカバレッジを提供する高品質SMSプロバイダです。

関連する問題