Advertisement
Guest User

Untitled

a guest
Apr 12th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.19 KB | None | 0 0
  1. <?php
  2. /*
  3. ennaessa
  4. Version : 25112017
  5. DEBUG,INFO,WARN,ERROR,FATAL,OFF
  6. LogInfo,LogDebug,LogWarn,LogError,LogFatal
  7. */
  8.  
  9. ini_set('display_errors', 0);
  10. ini_set('memory_limit','2000M');
  11. error_reporting(E_ERROR);
  12. require('/var/www/html/stubs/KLogger.php');
  13. $ini_cfg = parse_ini_file('/var/www/html/stubs/stubs_conf.ini');
  14. $log_level = $ini_cfg['log_level'];
  15. $stub_folder = $ini_cfg['stub_folder'];
  16. $time_zone = $ini_cfg['time_zone'];
  17. $send_box = $ini_cfg['send_box'];
  18. date_default_timezone_set($time_zone);
  19. $host = $ini_cfg['mn_host'];
  20. $username = $ini_cfg['mn_username'];
  21. $password = $ini_cfg['mn_password'];
  22. $dbname = $ini_cfg['mn_dbname'];
  23. $sql_window = 30;
  24. $speed_ctl = 1;
  25. $stub_name ='HT_Thinq_Marc';
  26. $time = date('Y-m-d H:i:s');
  27. $sender_id = "";
  28. $msg = "";
  29. $user_key =base64_encode ("mbarnum:f9fdeb67d36899369ab1aa31090ea87780645412");
  30.  
  31. //BGA_PROCESS_HT_Thinq_Marc.php
  32. $file = $stub_folder.'BGA_PROCESS_HT_Thinq_Marc.log';
  33. if(!file_exists($file))
  34. {
  35. file_put_contents($file, '');
  36. }
  37. //BGA_PROCESS_HT_SIGNALWIRE_P3.php
  38. $log_BGA = new KLogger( $stub_folder."BGA_PROCESS_HT_Thinq_Marc.log", $log_level);
  39. $log_BGA->LogInfo("==================================BGA_PROCESS_HT_Thinq_Marc=========================================");
  40. $db_con=mysql_connect($host,$username,$password,true);
  41. if (!$db_con)
  42. {
  43. $log_BGA->LogInfo('Could not connect: ' . mysql_error().' DB '.$dbname);
  44. }
  45. else
  46. {
  47. //$log_BGA->LogInfo('Connected to DB '.$dbname);
  48. }
  49. mysql_select_db($dbname,$db_con);
  50.  
  51. mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'");
  52.  
  53. while (1){
  54. $log_BGA->LogInfo("==================================_".time()."_=========================================");
  55.  
  56. if (!mysql_ping($db_con))
  57. {
  58. $log_BGA->LogInfo("MYSQL db_con DISCONNECT");
  59. $db_con=mysql_connect($host,$username,$password,true);
  60. mysql_select_db($dbname,$db_con);
  61. sleep(10);
  62. }else{
  63.  
  64. $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 ;
  65. $result_sms = mysql_query($sms_sql_query) or die ("<b>Query failed:</b> " . mysql_error());
  66. $result_sms_lcp = $result_sms;
  67. //$log_BGA->LogInfo($sms_sql_query);
  68. //$log_BGA->LogInfo(count($result_sms));
  69. $sms_ids = array();
  70. $sms_array =array();
  71. while ($row = mysql_fetch_array($result_sms, MYSQL_ASSOC)) {
  72. array_push($sms_ids, $row["id"]);
  73. $newdata = array (
  74. 'sent_to' => $row["sent_to"],
  75. 'sms_shoot_id' => $row["sms_shoot_id"],
  76. 'sender_id' => $row["sender_id"],
  77. 'sms_text' => $row["sms_text"],
  78. 'sms_type' => $row["sms_type"],
  79. 'id' => $row["id"],
  80. 'is_unicode' => $row["is_unicode"]
  81. );
  82. array_push($sms_array,$newdata );
  83. }
  84.  
  85. $log_BGA->LogInfo(json_encode($sms_ids)); //die();
  86. $sms_up_ids = implode(",",$sms_ids);
  87. $sql_query_id = "UPDATE `sc_sms` SET `status`=10 WHERE `id` IN (".$sms_up_ids.")";
  88. $result_smsup = mysql_query($sql_query_id);
  89. //$log_BGA->LogInfo($sql_query_id);
  90. //mysql_free_result($result_smsup);
  91. foreach ($sms_array as $sms_k=>$sms_val) {
  92. $to = $sms_val["sent_to"];
  93. if (strpos($to, '11') === 0) {
  94. //$to = ltrim($to,"1");
  95. $to = substr($to, 1);
  96. }
  97. $shoot_id = $sms_val["sms_shoot_id"];
  98. $sender_id = $sms_val["sender_id"];
  99. $msg = $sms_val["sms_text"];
  100. $sms_type = $sms_val["sms_type"];
  101. $msg_is_unicode = $sms_val["is_unicode"];
  102. $id = $sms_val["id"];
  103. $fields_string ="";
  104.  
  105. $sql_query_id = "SELECT `id` FROM `sc_user_contacts` WHERE `group_id`='999' AND `contact_no`='".$to."'";
  106. $result_key = mysql_query($sql_query_id);
  107. $log_BGA->LogInfo($sql_query_id);
  108. if (mysql_num_rows($result_key) > 0) {
  109. //Update SMS Status
  110. $sql_query_id = 'UPDATE `sc_sms` SET `status`=16 WHERE `id`='.$id;
  111. $result_smsup = mysql_query($sql_query_id);
  112. //$log_BGA->LogInfo($sql_query_id);
  113. mysql_free_result($result_smsup);
  114. } else {
  115. if ($sms_type =='mms') {
  116. //do nothing
  117. } else {
  118. $rt_link = 'https://api.thinq.com/account/'.$user_key.'/product/origination/sms/send';
  119. //$data_string = 'to_did='.urlencode($to).'&from_did='.urlencode($sender_id).'&message='.urlencode($msg);
  120. //echo '<pre>';var_dump($data_string);
  121.  
  122. $data = array(
  123. 'to_did' => $to,
  124. 'from_did' => $sender_id,
  125. 'message' => $msg
  126. );
  127.  
  128. $data_string = json_encode($data);
  129.  
  130. $ch = curl_init($rt_link);
  131. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  132. curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
  133. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  134. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  135. 'Content-Type: application/json',
  136. 'Authorization: Basic ')
  137. );
  138. $resp = curl_exec($ch);
  139. $resp = str_replace("'"," ",$resp);
  140.  
  141. }
  142.  
  143. if (!$resp) {
  144. $send_status='-1';
  145. } else {
  146. $send_status='1';
  147. }
  148.  
  149. $log_BGA->LogInfo($rt_link);
  150. $log_BGA->LogInfo(json_encode($data_string));
  151. $log_BGA->LogInfo(json_encode($resp));
  152.  
  153. $sql_query_id = 'INSERT INTO `sc_stubs_rec`(`stub` , `shoot_id`, `to` , `status` , `stub_resp` , `msg_id` , `insert_date`)';
  154. $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')."')";
  155. $result_key = mysql_query($sql_query_id);
  156. $log_BGA->LogInfo($to);
  157. //$log_BGA->LogInfo($id);
  158. //$log_BGA->LogInfo(json_encode($resp));
  159.  
  160. //sleep($speed_ctl);
  161.  
  162. }
  163. }
  164. mysql_free_result($result_sms);
  165. sleep(2);
  166.  
  167. }
  168.  
  169. }
  170.  
  171. mysql_close($db_con);
  172.  
  173.  
  174. ?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement