2015-09-04 126 views
1

如何向多個聯繫人發送短信並獲取每個聯繫人的結果碼。它不工作。我只打開'數字'字符串中的最後一個數字,而不是全部。如何向多個聯繫人發送短信

我在做什麼錯?

在我的控制器,

foreach ($sendarraystudent as $studentid) { 
     //$i++; 
     $student = Student::model()->findByPk($studentid); 

     $name = $student->student_firstname . " " . $student->student_middlename . " " . $student->student_lastname; 

     $smobile = $student->student_mobile; 
     //$mobilelist = $mobilelist . ',' . $smobile; 
     $msg1 = $msg; 
     $msg1 = str_replace("#course#", $course->course_name, $msg); 
     $msg1 = str_replace("#batch#", $batch->batch_name, $msg1); 
     $msg1 = str_replace("#name#", $name, $msg1); 

     $this->sendbulk($smobile, $msg1); 
    } 

protected function sendbulk($mobilenum, $message) { 
    $no = $mobilenum; 
    $msg = $message; 

    $link = "http://url/api/v3/index.php?method=sms&api_key=A6xxxxxxxxxxx&to=" . $no . "&sender=xxxxxx&message=" . $msg . "&unicode=xxx"; 
    header('Location: ' . $link) and exit; 
} 
+0

我想整合kapsystem短信網關。我正在閱讀API文檔。每個示例調用中都有'URL'。但是URL是什麼?沒有提及它。是URL =「http://trans.kapsystem.com」還是別的?請幫幫我。 –

+0

是的,URL的意思就像「trans.kapsystem.com」(短信網關網址) – Arya

回答

4

我想,那是因爲你使用重定向header('Location: ' . $link) and exit;。只處理一個短信。試試這個:

foreach ($sendarraystudent as $studentid) { 
    //... 
    $link = "http://url/api/v3/index.php?method=sms&api_key=A6xxxxxxxxxxx&to=" . $student->student_mobile . "&sender=xxxxxx&message=" . $msg1 . "&unicode=xxx" 
    $content = file_get_contents($link); 

    echo $content; 
} 
+0

也沒有工作此代碼。通過使用該得到的錯誤一樣, 錯誤500米 的file_get_contents(HTTP://url/api/v3/index.php方法=短信& API_KEY = A6xxxxxxxxxx &爲= 99xxxxx &發件人= XXXXXXX &消息= Studnet名稱:納比勒·納濟姆,課程:STD III,批次:A & unicode = x):無法打開流:HTTP請求失敗! HTTP/1.1 400 BAD_REQUEST – Arya

+0

問題已解決。謝謝 – Arya