WebService.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2023/2/14
  6. * Time: 18:09
  7. */
  8. namespace app\common\service;
  9. use file\DirHelper;
  10. use think\Controller;
  11. class WebService extends Controller
  12. {
  13. /**
  14. * 安装检测
  15. */
  16. public function checkInstalled()
  17. {
  18. if ($this->request->module() != 'install' && !is_installed()) {
  19. // 检测是否安装过,未安装直接跳转到安装导向
  20. $this->redirect("/install");
  21. }
  22. }
  23. /**
  24. * 检查是否开启用户中心
  25. */
  26. public function checkOpenUserModule()
  27. {
  28. if (empty(\think\Env::get("open_user_module", false))) {
  29. $this->error('暂不开放此功能', '/');
  30. }
  31. }
  32. /**
  33. * 记录请求的详细数据,用来测试第三方回调数据
  34. * @param string $msg [描述信息]
  35. * @return string
  36. */
  37. public function record($msg = "")
  38. {
  39. $savePath = RUNTIME_PATH . "notify_log" . DS . date('Y-m-d', time()) . DS;//日志目录
  40. DirHelper::makeDir($savePath);
  41. $saveFile = $savePath . date('H-i-s_', time()) . '_' . rand(1000, 9999) . ".log";
  42. $input = "TIME: " . date('Y-m-d H:i:s', time()) . PHP_EOL
  43. . "URL: " . $this->request->url() . PHP_EOL
  44. . "MESSAGE: " . $msg . PHP_EOL . PHP_EOL;
  45. if ($this->request->isGet() && $this->request->get()) {
  46. $input = $input . "METHOD: " . "GET" . PHP_EOL
  47. . "PARAMS: " . json_encode($this->request->get(), JSON_UNESCAPED_UNICODE) . PHP_EOL . PHP_EOL;
  48. } elseif ($this->request->isPost() && $this->request->param()) {
  49. $input = $input . "METHOD: " . "POST" . PHP_EOL
  50. . "PARAMS: " . json_encode($this->request->param(), JSON_UNESCAPED_UNICODE) . PHP_EOL . PHP_EOL;
  51. }
  52. $callbackBody = file_get_contents('php://input');
  53. if ($callbackBody) {
  54. $input = $input . "METHOD: " . "INPUT" . PHP_EOL
  55. . "PARAMS: " . json_encode($callbackBody, JSON_UNESCAPED_UNICODE) . PHP_EOL . PHP_EOL;
  56. }
  57. if (false == file_put_contents($saveFile, $input)) {
  58. exit("创建文件失败,请检查目录权限");
  59. }
  60. return $msg;
  61. }
  62. }