BaseApiValidate.php 929 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace app\api\validate;
  3. use think\exception\HttpResponseException;
  4. use think\Request;
  5. use think\Response;
  6. use think\Validate;
  7. /**
  8. * Class BaseApiValidate
  9. * @package app\api\validate
  10. */
  11. class BaseApiValidate extends Validate
  12. {
  13. /**
  14. * @param array $rules
  15. * @param string $scene
  16. * @return array|bool|mixed|null
  17. */
  18. public function checkBody($rules = [], $scene = '')
  19. {
  20. $data = Request::instance()->param();
  21. $check = parent::check($data, $rules, $scene); // TODO: Change the autogenerated stub
  22. if (!$check) {
  23. $response = Response::create([
  24. 'code' => 0,
  25. 'msg' => $this->getError(),
  26. 'time' => Request::instance()->server('REQUEST_TIME'),
  27. 'data' => null,
  28. ], 'json')->header([]);
  29. throw new HttpResponseException($response);
  30. }
  31. return $data;
  32. }
  33. }