<?php
require($_SERVER["DOCUMENT_ROOT"].'/php/lib/DB.class.php');
session_start();
$db = new DB();
$conn = $db->getConnection();
if( !$conn)
{
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
exit();
}
$sphone = $_POST['tel'];
if( !$sphone ) $sphone = $_GET['tel'];
$linkid = 'F20519DD-3279-4A25-B3F9-645F8A9F49D3';
if(!empty($sphone)&&strlen($sphone)>9)
{
$ip = $_SERVER["REMOTE_ADDR"];
$today =date('Ymd');
$allowTime = 1800;
$callFlg =1;
//查询出ip黑名单
$sql ="select * from t_blacklist where phone=:ip and type=2";
$stmt = oci_parse($conn, $sql);
oci_bind_by_name($stmt, ':ip', $ip);
oci_execute($stmt);
while($row = oci_fetch_array($stmt, OCI_ASSOC+OCI_RETURN_NULLS))
{
if($row['PHONE']==$ip)
{
$callFlg =0;
break;
}
}
if($callFlg==1)
{
//查询出号码黑名单
$sql ="select * from t_blacklist where phone=:phone and type=1";
$stmt = oci_parse($conn, $sql);
oci_bind_by_name($stmt, ':phone', $phone);
oci_execute($stmt);
while($row = oci_fetch_array($stmt, OCI_ASSOC+OCI_RETURN_NULLS))
{
if($row['PHONE']==$phone)
{
$callFlg =0;
break;
}
}
}
oci_free_statement($stmt);
$wap_sql="insert into t_wap_gtel (gtel,createdate) values (:gtel,sysdate)";
$wap_stmt = oci_parse($conn, $wap_sql);
oci_bind_by_name($wap_stmt, ':gtel', $sphone);
oci_execute($wap_stmt);
oci_free_statement($wap_stmt);
//非黑名单号码 半个小时内允许同一号码呼叫一次
if($callFlg==1)
{
//数据库判断
$sql="select to_char(max(call_time),'yyyy-mm-dd hh24:mi:ss') calltime
from t_gtel_log where call_date=:callDate and phone=:phone ";
$stmt = oci_parse($conn, $sql);
oci_bind_by_name($stmt, ':callDate',$today);
oci_bind_by_name($stmt, ':phone', $sphone);
oci_execute($stmt);
if($row = oci_fetch_array($stmt, OCI_ASSOC+OCI_RETURN_NULLS))
{
$sql2="select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') now from dual ";
$stmt2 = oci_parse($conn, $sql2);
oci_execute($stmt2);
$timeNow=time();
if($now = oci_fetch_array($stmt2, OCI_ASSOC+OCI_RETURN_NULLS))
$timeNow=$now['NOW'];
oci_free_statement($stmt2);
if((strtotime($timeNow)-strtotime($row['CALLTIME']))>$allowTime)//超过半个小时可以再次呼叫
{
//绿线呼叫
$objSoapClient = new SoapClient("http://soa.10101010.cn/linksoa/PublicService.asmx?wsdl");
$chkCode = "igogtel"; //md5的合成码,固定值
$strMD5 = strtoupper( md5($linkid.$phone.$chkCode) );
$param["linkid"] = $linkid;
$param["phone"] = $phone;
$param["md5"] = $strMD5;
$xml=$objSoapClient->__Call('PublicCall2Link',array('paramters'=>$param));
if(!$xml) $callFlg=2;
}else{
$callFlg=0;
}
//呼叫Log记录
$log_sql ="insert into t_gtel_log (phone,call_time,state,call_date) values (:phone,systimestamp,:state,:callDate)";