弄了個(gè)簡(jiǎn)單群呼系統(tǒng)(asterisk+PHP)
先說(shuō)下從 excel 中導(dǎo)入號(hào)碼到數(shù)據(jù)庫(kù)中去,然后從數(shù)據(jù)庫(kù)中讀取這些號(hào)碼生成呼叫文件,進(jìn)行呼叫即可
?
?? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
?? ??
?
?? 源碼如下:(注:操作excel的讀取文件就沒(méi)寫(xiě)上來(lái))
<?php /* 首先得把 文件上傳的服務(wù)器中相應(yīng)的位置,然后從該文件中讀取號(hào)碼到數(shù)據(jù)庫(kù)中! 接著從數(shù)據(jù)庫(kù)中讀取這些號(hào)碼,生成。call 文件 到 var/..out. 目錄下 就可以呼叫了 */ // 文件上傳......................................................................................................... if(is_uploaded_file($_FILES['upfile']['tmp_name'])){ //判斷有新文件上傳 $upfile=$_FILES["upfile"]; //上傳文件的函數(shù) $name = $upfile["name"]; // 獲取文件名稱 $type = $upfile["type"]; //文件類型 $size = $upfile["size"]; //文件大小 $tmp_name = $upfile["tmp_name"]; //臨時(shí)文件位置 $error = $upfile["error"]; // 判斷文件是否成功的參數(shù),0代表成功,。。。 // 允許上傳的文件類型 switch ($type) { case 'application/vnd.ms-excel' : $ok=1; //只允許上傳excel文件類型 break; } //判斷是否成功 if($ok && $error=='0') { move_uploaded_file($tmp_name,'xls/'.'tel.xls'); //把上傳的臨時(shí)文件放到xls下 //讀取上傳后文件中的內(nèi)容......................................... require_once 'reader.php'; //引入讀取csv文件類 $data = new Spreadsheet_Excel_Reader(); $data->setOutputEncoding('utf-8'); $conn= mysql_connect('localhost','root','888888') or die("數(shù)據(jù)庫(kù)連接失敗"); mysql_query("set names 'utf-8'");//設(shè)置編碼輸出 mysql_select_db('asterisk'); //選擇數(shù)據(jù)庫(kù) $data->read('xls/tel.xls'); for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) { $sql = "INSERT INTO tel VALUES(null,'".$data->sheets[0]['cells'][$i][1]."',0)"; $query=mysql_query($sql); if($query) { } } }else { echo "<mce:script type="text/javascript"><!--alert('上傳失敗,請(qǐng)檢查文件格式!');window.top.location='file.php'// --></mce:script>"; } } //.................................................................................................................end //........從數(shù)據(jù)庫(kù)中讀取號(hào)碼生成一個(gè)一個(gè)的.call呼叫文件............................................................................ if(isset($_POST['liji_tel'])) //立即呼叫。。這里還得完成流程呼叫完畢后。刪除呼叫的號(hào)碼 { $con= mysql_connect('localhost','root','888888') or die("數(shù)據(jù)庫(kù)連接失敗"); mysql_query("set names 'utf-8'");//設(shè)置編碼輸出 mysql_select_db('asterisk'); //選擇數(shù)據(jù) $result=mysql_query("select * from tel where s_id=0"); while($rows=mysql_fetch_row($result)) { $filename="$rows[1].call"; fopen($filename,"w+"); $somecontent_8001="channel: SIP/$rows[1]"."/n"."callerid: <haozi>"."/n"."MaxRetries: 2"."/n"."Context: default"."/n"."RetryTime: 10"."/n"."WaitTime: 10"."/n"."Extension: _x."."/n"."setvar: id=$rows[0]"."/n"; if (is_writable($filename)) { if (!$handle = fopen($filename, 'a')) { exit;} if (fwrite($handle, $somecontent_8001)=== FALSE) {exit;}fclose($handle); $kk="mv ".$filename." /var/spool/asterisk/outgoing/"; system($kk,$restult);}} echo "<mce:script type="text/javascript"><!--alert('已啟用群呼!');window.top.location='file.php'// --></mce:script>"; } //..............end ............................................................................................................?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html><head><meta http-equiv="Content-Type" content="text ml; charset=utf-8"></head><body> 電話群呼(text):<form action="" enctype="multipart/form-data" method="post" name="upform"> <div align="center"> <table width="634" border="1"> <tr> <td>選擇要上傳的號(hào)碼文件:</td> <td>上傳文件: <input name="upfile" type="file" /></td> </tr> <tr> <td width="230"><label> <input name="liji_tel" type="radio" value="1" checked="checked" />立即呼叫 </label></td> <td width="388"><input name="submit" type="submit" value="執(zhí)行" /></td> </tr> </table> <br> </div></form> </body></html>
?