Library.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace app\utils\Service;
  3. use app\utils\CurlUtil;
  4. /**
  5. * 扩展返回工具
  6. */
  7. class Library
  8. {
  9. protected $host = '';//请求地址
  10. protected $message = 'error';
  11. protected $data = [];
  12. protected function postJson(string $url, array $params, array $header = [], int $timeout=30)
  13. {
  14. return CurlUtil::postJson($this->host.$url,$params,$header,$timeout);
  15. }
  16. /**
  17. * 返回成功结果
  18. * @param string $message
  19. * @param mixed $data
  20. * @return bool
  21. */
  22. protected function success(string $message = 'success', $data = [])
  23. {
  24. $this->message = $message;
  25. $this->data = $data;
  26. return true;
  27. }
  28. /**
  29. * 返回失败结果
  30. * @param string $message
  31. * @param mixed $data
  32. * @return bool
  33. */
  34. protected function error(string $message = 'error', $data = [])
  35. {
  36. $this->message = $message;
  37. $this->data = $data;
  38. return false;
  39. }
  40. /**
  41. * 获取成功数据
  42. * @return mixed
  43. */
  44. public function getData()
  45. {
  46. return $this->data;
  47. }
  48. /**
  49. * 获取消息
  50. * @return string
  51. */
  52. public function getMessage()
  53. {
  54. return $this->message;
  55. }
  56. }