Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- ennaessa
- Version : 25112017
- DEBUG,INFO,WARN,ERROR,FATAL,OFF
- LogInfo,LogDebug,LogWarn,LogError,LogFatal
- */
- ini_set('display_errors', 0);
- ini_set('memory_limit','2000M');
- error_reporting(E_ERROR);
- require('/var/www/html/stubs/KLogger.php');
- $ini_cfg = parse_ini_file('/var/www/html/stubs/stubs_conf.ini');
- $log_level = $ini_cfg['log_level'];
- $stub_folder = $ini_cfg['stub_folder'];
- $time_zone = $ini_cfg['time_zone'];
- $send_box = $ini_cfg['send_box'];
- date_default_timezone_set($time_zone);
- $host = $ini_cfg['mn_host'];
- $username = $ini_cfg['mn_username'];
- $password = $ini_cfg['mn_password'];
- $dbname = $ini_cfg['mn_dbname'];
- $sql_window = 30;
- $speed_ctl = 1;
- $stub_name ='HT_Thinq_Marc';
- $time = date('Y-m-d H:i:s');
- $sender_id = "";
- $msg = "";
- $user_key =base64_encode ("mbarnum:f9fdeb67d36899369ab1aa31090ea87780645412");
- //BGA_PROCESS_HT_Thinq_Marc.php
- $file = $stub_folder.'BGA_PROCESS_HT_Thinq_Marc.log';
- if(!file_exists($file))
- {
- file_put_contents($file, '');
- }
- //BGA_PROCESS_HT_SIGNALWIRE_P3.php
- $log_BGA = new KLogger( $stub_folder."BGA_PROCESS_HT_Thinq_Marc.log", $log_level);
- $log_BGA->LogInfo("==================================BGA_PROCESS_HT_Thinq_Marc=========================================");
- $db_con=mysql_connect($host,$username,$password,true);
- if (!$db_con)
- {
- $log_BGA->LogInfo('Could not connect: ' . mysql_error().' DB '.$dbname);
- }
- else
- {
- //$log_BGA->LogInfo('Connected to DB '.$dbname);
- }
- mysql_select_db($dbname,$db_con);
- mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'");
- while (1){
- $log_BGA->LogInfo("==================================_".time()."_=========================================");
- if (!mysql_ping($db_con))
- {
- $log_BGA->LogInfo("MYSQL db_con DISCONNECT");
- $db_con=mysql_connect($host,$username,$password,true);
- mysql_select_db($dbname,$db_con);
- sleep(10);
- }else{
- $sms_sql_query = "SELECT `id`,`user_id`,`sms_type`,`sms_text`, `sender_id`, `sent_to`,`smsc`, `is_unicode`,`sms_shoot_id` FROM `sc_sms` WHERE `status` = '0' AND `smsc` ='HT_Thinq_Marc' ORDER BY `id` ASC LIMIT ".$sql_window ;
- $result_sms = mysql_query($sms_sql_query) or die ("<b>Query failed:</b> " . mysql_error());
- $result_sms_lcp = $result_sms;
- //$log_BGA->LogInfo($sms_sql_query);
- //$log_BGA->LogInfo(count($result_sms));
- $sms_ids = array();
- $sms_array =array();
- while ($row = mysql_fetch_array($result_sms, MYSQL_ASSOC)) {
- array_push($sms_ids, $row["id"]);
- $newdata = array (
- 'sent_to' => $row["sent_to"],
- 'sms_shoot_id' => $row["sms_shoot_id"],
- 'sender_id' => $row["sender_id"],
- 'sms_text' => $row["sms_text"],
- 'sms_type' => $row["sms_type"],
- 'id' => $row["id"],
- 'is_unicode' => $row["is_unicode"]
- );
- array_push($sms_array,$newdata );
- }
- $log_BGA->LogInfo(json_encode($sms_ids)); //die();
- $sms_up_ids = implode(",",$sms_ids);
- $sql_query_id = "UPDATE `sc_sms` SET `status`=10 WHERE `id` IN (".$sms_up_ids.")";
- $result_smsup = mysql_query($sql_query_id);
- //$log_BGA->LogInfo($sql_query_id);
- //mysql_free_result($result_smsup);
- foreach ($sms_array as $sms_k=>$sms_val) {
- $to = $sms_val["sent_to"];
- if (strpos($to, '11') === 0) {
- //$to = ltrim($to,"1");
- $to = substr($to, 1);
- }
- $shoot_id = $sms_val["sms_shoot_id"];
- $sender_id = $sms_val["sender_id"];
- $msg = $sms_val["sms_text"];
- $sms_type = $sms_val["sms_type"];
- $msg_is_unicode = $sms_val["is_unicode"];
- $id = $sms_val["id"];
- $fields_string ="";
- $sql_query_id = "SELECT `id` FROM `sc_user_contacts` WHERE `group_id`='999' AND `contact_no`='".$to."'";
- $result_key = mysql_query($sql_query_id);
- $log_BGA->LogInfo($sql_query_id);
- if (mysql_num_rows($result_key) > 0) {
- //Update SMS Status
- $sql_query_id = 'UPDATE `sc_sms` SET `status`=16 WHERE `id`='.$id;
- $result_smsup = mysql_query($sql_query_id);
- //$log_BGA->LogInfo($sql_query_id);
- mysql_free_result($result_smsup);
- } else {
- if ($sms_type =='mms') {
- //do nothing
- } else {
- $rt_link = 'https://api.thinq.com/account/'.$user_key.'/product/origination/sms/send';
- //$data_string = 'to_did='.urlencode($to).'&from_did='.urlencode($sender_id).'&message='.urlencode($msg);
- //echo '<pre>';var_dump($data_string);
- $data = array(
- 'to_did' => $to,
- 'from_did' => $sender_id,
- 'message' => $msg
- );
- $data_string = json_encode($data);
- $ch = curl_init($rt_link);
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'Content-Type: application/json',
- 'Authorization: Basic ')
- );
- $resp = curl_exec($ch);
- $resp = str_replace("'"," ",$resp);
- }
- if (!$resp) {
- $send_status='-1';
- } else {
- $send_status='1';
- }
- $log_BGA->LogInfo($rt_link);
- $log_BGA->LogInfo(json_encode($data_string));
- $log_BGA->LogInfo(json_encode($resp));
- $sql_query_id = 'INSERT INTO `sc_stubs_rec`(`stub` , `shoot_id`, `to` , `status` , `stub_resp` , `msg_id` , `insert_date`)';
- $sql_query_id = $sql_query_id . " VALUES ('".$stub_name."','".$shoot_id."','".$to."','".$send_status."','".mysql_real_escape_string($resp)."',".$id.",'".date('Y-m-d H:i:s')."')";
- $result_key = mysql_query($sql_query_id);
- $log_BGA->LogInfo($to);
- //$log_BGA->LogInfo($id);
- //$log_BGA->LogInfo(json_encode($resp));
- //sleep($speed_ctl);
- }
- }
- mysql_free_result($result_sms);
- sleep(2);
- }
- }
- mysql_close($db_con);
- ?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement