12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace app\utils\Service;
- use app\utils\CurlUtil;
- /**
- * 扩展返回工具
- */
- class Library
- {
- protected $host = '';//请求地址
- protected $message = 'error';
- protected $data = [];
- protected function postJson(string $url, array $params, array $header = [], int $timeout=30)
- {
- return CurlUtil::postJson($this->host.$url,$params,$header,$timeout);
- }
- /**
- * 返回成功结果
- * @param string $message
- * @param mixed $data
- * @return bool
- */
- protected function success(string $message = 'success', $data = [])
- {
- $this->message = $message;
- $this->data = $data;
- return true;
- }
- /**
- * 返回失败结果
- * @param string $message
- * @param mixed $data
- * @return bool
- */
- protected function error(string $message = 'error', $data = [])
- {
- $this->message = $message;
- $this->data = $data;
- return false;
- }
- /**
- * 获取成功数据
- * @return mixed
- */
- public function getData()
- {
- return $this->data;
- }
- /**
- * 获取消息
- * @return string
- */
- public function getMessage()
- {
- return $this->message;
- }
- }
|