/web/admin/module/center/script_day_online.php

https://gitlab.com/xusasuke6/Slg_php · PHP · 104 lines · 84 code · 13 blank · 7 comment · 13 complexity · 51d7371db57cea1d5672b87f4e0880aa MD5 · raw file

  1. <?php
  2. define('IN_DATANG_SYSTEM', true);
  3. include "../../../config/config.php";
  4. include "../../../config/config.center.online.php";
  5. include SYSDIR_ADMIN.'/include/api_global.php';
  6. echo strftime("%Y-%m-%d %H:%M:%S",time())." start to run day online script";
  7. echo "\n";
  8. $keySign = "FTNN4399payKode";
  9. $now_time = time();
  10. $start_time = $PLAY_ONLINE_TIME["time"];
  11. # $aid:agent_id
  12. # $sid:server_id
  13. /*echo '<pre>';
  14. print_r($ALL_SERVER_LIST);exit;*/
  15. foreach($ALL_SERVER_LIST as $aid => $v) {
  16. if(!empty($v)) {
  17. foreach($v as $sid => $vv) {
  18. if(!empty($vv['url']) && $vv['stat']==1) {
  19. unset($online_result,$result);
  20. $sign = md5($start_time . $keySign . $now_time);
  21. $link = $vv['url']."web/center/day_online.php?starttime={$start_time}&endtime={$now_time}&sign={$sign}";
  22. //echo $link;exit;
  23. $result = make_request($link, 'POST', 5);
  24. $online_result = json_decode($result, true);
  25. if($online_result != 'sign_error' && !empty($online_result)) {
  26. foreach($online_result['max'] as $value) {
  27. if(!empty($value)) {
  28. $online = $value['online'];
  29. $date = $value['date'];
  30. $hour = $value['hour'];
  31. $min = $value['min'];
  32. $sql = "insert into all_server_online(online,date,hour,min,agent_id,server_id) values($online,'$date',$hour,$min,$aid,$sid) on duplicate key update online=$online";
  33. }
  34. $db->query($sql);
  35. }
  36. foreach($online_result['avg'] as $v) {
  37. if(!empty($v)) {
  38. $online = $v['online'];
  39. $date = $v['date'];
  40. $sql = "insert into all_avg_online(online,date,agent_id,server_id) values($online,'$date',$aid,$sid) on duplicate key update online=$online";
  41. }
  42. $db->query($sql);
  43. }
  44. foreach($online_result['register'] as $v) {
  45. if(!empty($v)) {
  46. $account = $v['account'];
  47. $date = $v['date'];
  48. $sql = "insert into all_register_db (account,date,agent_id,server_id) values($account,'$date',$aid,$sid) on duplicate key update account=$account";
  49. }
  50. $db->query($sql);
  51. }
  52. }
  53. }
  54. }
  55. }
  56. }
  57. $PLAY_ONLINE_TIME["time"] = $now_time;
  58. $config_file = fopen('../../../config/config.center.online.php', 'wb');
  59. fwrite($config_file, "<?php\n\$PLAY_ONLINE_TIME = " . var_export($PLAY_ONLINE_TIME, TRUE) . ";\n");
  60. fclose($config_file);
  61. echo strftime("%Y-%m-%d %H:%M:%S",time())." finish running pay log script";
  62. echo "\n";
  63. die();
  64. #-------------------
  65. function make_request($url, $method = 'GET', $timeout = 5) {
  66. $ch = curl_init();
  67. $header = array(
  68. 'Accept-Language: zh-cn',
  69. 'Connection: Keep-Alive',
  70. 'Cache-Control: no-cache'
  71. );
  72. if ($method == 'GET') {
  73. curl_setopt($ch, CURLOPT_HEADER, 0);
  74. }
  75. else {
  76. $i = strpos($url, '?');
  77. $param_str = substr($url, $i + 1);
  78. $url = substr($url, 0, $i);
  79. curl_setopt($ch, CURLOPT_POST, 1);
  80. curl_setopt($ch, CURLOPT_POSTFIELDS, $param_str);
  81. }
  82. curl_setopt($ch, CURLOPT_URL, $url);
  83. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  84. curl_setopt($ch, CURLOPT_USERAGENT, 'WEB.4399.COM API PHP Servert 0.1 (curl) ' . phpversion());
  85. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  86. if ($timeout > 0) curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  87. $result = curl_exec($ch);
  88. curl_close($ch);
  89. return $result;
  90. }
  91. #-----------------------------