resp.php 972 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * Description of resp.php
  4. * 返回值基类, 统一的序列化到字符串的方法, json_encode...
  5. * @version
  6. * 1.0.0 Created at 2017-12-22. by --gwang
  7. * @author gwang (mail@wanggangzero.cn)
  8. * @copyright ? 2017-12-22, SJZ LoyalSoft Corporation & gwang. All rights reserved.
  9. */
  10. class Resp
  11. {
  12. public $err = 0;
  13. public $ret;
  14. public $msg;
  15. public static function ok($ret)
  16. {
  17. $resp = new Resp();
  18. $resp->err = 0;
  19. $resp->ret = $ret;
  20. return $resp;
  21. }
  22. public static function err($err_no, $msg)
  23. {
  24. $resp = new Resp();
  25. $resp->err = $err_no;
  26. $resp->msg = $msg;
  27. return $resp;
  28. }
  29. public function __toString()
  30. {
  31. return $this->toString();
  32. }
  33. public function toString()
  34. {
  35. // var_dump(\JsonUtil::encode($this));
  36. $str = loyalsoft\JsonUtil::encode($this);
  37. return $str;
  38. // return \gzdeflate($str);
  39. }
  40. }