Created
October 10, 2019 06:53
-
-
Save nutch31/e574fe99b79f58238f9fff95357a9c36 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php -q | |
<?php | |
require 'db.php'; | |
global $agi,$conn; | |
require 'phpagi.php'; | |
$agi = new AGI(); | |
$agi->answer(); | |
$array_url = getUrl(); | |
//$agi->verbose("*****$url"); | |
$calldate = $argv[1]; | |
$path = $argv[2]; | |
$endtime = $argv[3]; | |
$answertime = $argv[4]; | |
$clid = $argv[5]; | |
$src = $argv[6]; | |
$dst = $argv[7]; | |
$dcontext = $argv[8]; | |
$channel = $argv[9]; | |
$dstchannel = $argv[10]; | |
$duration = $argv[11]; | |
$billsec = $argv[12]; | |
$disposition = $argv[13]; | |
$uniqueid = $argv[14]; | |
$heronum = $argv[15]; | |
$sms_email = $argv[16]; | |
$camp_name = $argv[17]; | |
$camp_id = $argv[18]; | |
$recording_url = $argv[20]; | |
list($sms, $email) = checkSmsEmail($sms_email); | |
$client_number = getClientNumber($path); | |
$time = getTime($disposition); | |
$data = prepareData($answertime, $heronum, $camp_id, $camp_name, $client_number, $clid, $disposition, $time, $recording_url); | |
sendData($data, $array_url); | |
function getUrl() { | |
$qry = "select * from `url_master`"; | |
$query = mysql_query($qry); | |
$info = mysql_fetch_array($query); | |
return [ | |
$info['url'], | |
'https://clients.heroleads.com/api/calls?token=thioch4eimovoiDu6ahd', | |
'https://leadservice.heroleads.co.th/PbxCallService?token=thioch4eimovoiDu6ahd' | |
]; | |
} | |
function checkSmsEmail($sms_email) { | |
if ($sms_email == "1") { | |
$sms = "no"; | |
$email = "yes"; | |
} elseif ($sms_email == "2") { | |
$sms = "yes"; | |
$email = "no"; | |
} elseif ($sms_email == "3") { | |
$sms = "no"; | |
$email = "no"; | |
} else { | |
$sms = "yes"; | |
$email = "yes"; | |
} | |
return [ | |
$sms, | |
]; | |
} | |
function getClientNumber($path) { | |
$array = explode("-", $path); | |
return $array[1]; | |
} | |
function getTime($disposition) { | |
// $time = gmdate("H:i:s",$duration); | |
if ($disposition == "ANSWER" || $disposition == "ANSWERED") { | |
//$time = "00:00:00"; | |
$time = gmdate("H:i:s", $duration); | |
} else { | |
//$time = gmdate("H:i:s",$duration); | |
$time = "00:00:00"; | |
} | |
return $time; | |
} | |
function prepareData ($answertime, $heronum, $camp_id, $camp_name, $client_number, $clid, $disposition, $time, $recording_url = '') { | |
return [ | |
'timestamp' => $answertime, | |
'heronumber' => $heronum, | |
'campaign_id' => $camp_id, | |
'campaign_name' => $camp_name , | |
'client_number' => $client_number, | |
'caller_id' => $clid, | |
'status' => $disposition, | |
'duration' => $time, | |
'recording_url' => $recording_url | |
]; | |
} | |
function sendData($data, $array_url) { | |
//Array to Json | |
$val = json_encode($data); | |
//Create the multiple cURL handle | |
$mh = curl_multi_init(); | |
//Create ch_list array | |
$ch_list = array(); | |
foreach ($array_url as $url) { | |
//Create both cURL resources | |
$ch_list[$url] = curl_init($url); | |
// set URL and other appropriate options | |
curl_setopt($ch_list[$url], CURLOPT_CUSTOMREQUEST, "POST"); | |
curl_setopt($ch_list[$url], CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($ch_list[$url], CURLOPT_VERBOSE, true); | |
curl_setopt($ch_list[$url], CURLOPT_POSTFIELDS, $val); | |
curl_setopt($ch_list[$url], CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch_list[$url], | |
CURLOPT_HTTPHEADER, | |
array( | |
'Content-Type: application/json', | |
'Content-Length: ' . strlen($val) | |
) | |
); | |
//add the two handles | |
curl_multi_add_handle($mh, $ch_list[$url]); | |
} | |
//Create active | |
$active = null; | |
//execute the multi handle | |
do { | |
$status = curl_multi_exec($mh, $active); | |
if ($active) { | |
curl_multi_select($mh); | |
} | |
} while ($active && $status == CURLM_OK); | |
// Check for errors | |
if ($status != CURLM_OK) { | |
// Display error message | |
// echo "ERROR!\n " . curl_multi_strerror($status); | |
fwrite(STDERR, "ERROR!\n " . curl_multi_strerror($status)); | |
} | |
foreach ($url_list as $url) { | |
//close the handles | |
curl_multi_remove_handle($mh, $ch_list[$url]); | |
} | |
curl_multi_close($mh); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment