notify.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. //记录支付回调数据
  3. ignore_user_abort(); // run script in background
  4. set_time_limit(30);
  5. // 日志文件 start
  6. $log_base_dir = '../runtime/paylog/';
  7. if (!is_dir($log_base_dir))
  8. {
  9. mkdir($log_base_dir, 0770, true);
  10. @chmod($log_base_dir, 0770);
  11. }
  12. $notify_file = $log_base_dir.'notify.txt';
  13. if(!file_exists($notify_file)) {
  14. @touch($notify_file);
  15. @chmod($notify_file, 0770);
  16. }
  17. if(filesize($notify_file)>5242880)//大于5M自动切换
  18. {
  19. rename($notify_file, $log_base_dir.'notify_'.date('Y_m_d_H_i_s').'.txt');
  20. }
  21. if(!file_exists($notify_file)) {
  22. @touch($notify_file);
  23. @chmod($notify_file, 0770);
  24. }
  25. // 日志文件 end
  26. $_REQUEST = isset($_REQUEST) ? $_REQUEST : array();
  27. if($_REQUEST) {
  28. file_put_contents($notify_file, "\r\n\r\n".date('Y-m-d H:i:s')." [notify][入口接收request]".json_encode($_REQUEST), FILE_APPEND);
  29. } else {
  30. $xml = file_get_contents("php://input");
  31. file_put_contents($notify_file, "\r\n\r\n".date('Y-m-d H:i:s')." [notify][入口接收php://input流原始数据] \n".$xml, FILE_APPEND);
  32. $xmlObj = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
  33. file_put_contents($notify_file, "\r\n\r\n".date('Y-m-d H:i:s')." [notify][入口接收php://input流] ".json_encode($xmlObj), FILE_APPEND);
  34. }
  35. ini_set('display_errors','On');
  36. //$_GET['s']='/Admin/Payment/receive/';
  37. // 定义应用目录
  38. define('APP_PATH', __DIR__ . '/../application/');
  39. // 加载框架引导文件
  40. require __DIR__ . '/../thinkphp/base.php';
  41. // 绑定到admin模块
  42. \think\Route::bind('admin/Payment/notify');
  43. // 关闭路由
  44. \think\App::route(false);
  45. // 设置根url
  46. \think\Url::root('');
  47. // 执行应用
  48. \think\App::run()->send();
  49. ?>