PostLog.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\middleware;
  4. use think\facade\Db;
  5. class PostLog
  6. {
  7. /**
  8. * 处理请求
  9. *
  10. * @param \think\Request $request
  11. * @param \Closure $next
  12. * @return Response
  13. */
  14. public function handle($request, \Closure $next)
  15. {
  16. $param = $request->post();
  17. $rid= "";$rname= "";
  18. if(isset($param['token']) && $param['token']!=''){
  19. $apply_id = GetUserInfo($param['token']);
  20. if(empty($apply_id)||$apply_id['code']!=0){
  21. $rid= "";
  22. $rname= "";
  23. }else{
  24. $rid= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  25. $rname= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  26. }
  27. }
  28. $server = $request->server();
  29. $data=[
  30. "uri_name"=>$server['REQUEST_URI'],
  31. "param"=>json_encode($param,JSON_UNESCAPED_UNICODE),
  32. "response"=>'',
  33. "action_id"=>$rid,
  34. "action_name"=>$rname,
  35. "addtime"=>date("Y-m-d H:i:s")
  36. ] ;
  37. Db::name("data_log")->insert($data);
  38. $response = $next($request);
  39. return $response;
  40. }
  41. public function end($response){
  42. }
  43. }