VM暫存
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

121 lignes
3.4KB

  1. <?php
  2. require_once '/home/bigbang/libs/Workerman/Autoloader.php';
  3. use Workerman\Worker;
  4. Worker::$logFile = '/dev/null'; // 不記錄log file
  5. //Worker::$pidFile = '/tmp/run/'.basename(__FILE__).'.pid';
  6. //Worker::$logFile = __DIR__ . '/../mitac2server.log';
  7. // 場站共用設定檔
  8. require_once '/home/bigbang/apps/coworker/station.config.php';
  9. define('APP_NAME', 'mitac'); // application name
  10. define('WORKERMAN_DEBUG', 1);
  11. if (WORKERMAN_DEBUG)
  12. {
  13. ini_set('display_errors', '1');
  14. error_reporting(E_ALL);
  15. set_error_handler('error_handler', E_ALL);
  16. }
  17. ///////////////////////////////
  18. //
  19. // 主程式
  20. //
  21. ///////////////////////////////
  22. // 傳送主機資料
  23. $ch = curl_init();
  24. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  25. curl_setopt($ch, CURLOPT_POST, true); // 啟用POST
  26. // 建立一個Worker監聽49993埠,不使用任何應用層協定
  27. $tcp_worker = new Worker("tcp://0.0.0.0:49993");
  28. // 啟動N個進程對外提供服務
  29. $tcp_worker->count = 4;
  30. $tcp_worker->onConnect = function($connection)
  31. {
  32. echo APP_NAME . "..New Connection\n";
  33. };
  34. $tcp_worker->onClose = function($connection)
  35. {
  36. echo APP_NAME . "..Connection closed\n";
  37. };
  38. $tcp_worker->onMessage = function($connection, $tcp_in)
  39. {
  40. global $ch;
  41. trigger_error("..tcp_in..". json_encode($tcp_in, true) .'|');
  42. $tcp_in = mb_convert_encoding($tcp_in, 'UTF-8', 'UTF-16LE'); // unicode to utf-8
  43. $explode_tcp_in = explode(',', $tcp_in);
  44. $send_data = null;
  45. // 未知
  46. if(empty($explode_tcp_in) || empty($explode_tcp_in[0]))
  47. {
  48. trigger_error("..empty..". print_r($explode_tcp_in, true) .'|');
  49. $connection->close($send_data);
  50. }
  51. else if($explode_tcp_in[0] == 'Mitac')
  52. {
  53. trigger_error("..". $tcp_in .'..'); // Mitac 回傳
  54. }
  55. else if($explode_tcp_in[0] == 'Altob')
  56. {
  57. if($explode_tcp_in[1] == 'DeductResult' && count($explode_tcp_in) == 10)
  58. {
  59. // 回應扣款成功 (MITAC to ALTOB) 目前只有這支
  60. $function_name = 'deduct_result';
  61. $seqno = $explode_tcp_in[2];
  62. $lpr = $explode_tcp_in[3];
  63. $in_time = $explode_tcp_in[4];
  64. $out_time = $explode_tcp_in[5];
  65. $gate_id = $explode_tcp_in[6];
  66. $amt = $explode_tcp_in[7];
  67. $amt_discount = $explode_tcp_in[8];
  68. $amt_real = $explode_tcp_in[9];
  69. // 建立通訊內容
  70. $parms = array(
  71. 'seqno' => $seqno,
  72. 'lpr' => $lpr,
  73. 'in_time' => $in_time,
  74. 'out_time' => $out_time,
  75. 'gate_id' => $gate_id,
  76. 'amt' => $amt,
  77. 'amt_discount' => $amt_discount,
  78. 'amt_real' => $amt_real);
  79. // 加驗証
  80. $parms['ck'] = md5($parms['seqno']. 'a' . date('dmh') . 'l' . $parms['lpr'] . 't'. $parms['amt']. 'o'. $parms['amt_discount'] . 'b'. $parms['amt_real'] . $function_name);
  81. curl_setopt($ch, CURLOPT_URL, "http://localhost/mitac_service.html/{$function_name}/");
  82. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($parms));
  83. $send_data = curl_exec($ch);
  84. trigger_error(".. curl {$function_name}|{$send_data} ..".print_r($parms, true));
  85. }
  86. else
  87. {
  88. trigger_error('..unknown cmd..' . print_r($explode_tcp_in, true));
  89. }
  90. }
  91. $connection->close($send_data);
  92. };
  93. // 執行worker
  94. Worker::runAll();
  95. // 發生錯誤時集中在此處理
  96. function error_handler($errno, $errstr, $errfile, $errline, $errcontext)
  97. {
  98. $str = date('H:i:s')."|{$errstr}|{$errfile}|{$errline}|{$errno}\n";
  99. error_log($str, 3, LOG_PATH.APP_NAME . '.' . date('Ymd').'.log.txt'); // 3代表參考後面的檔名
  100. }