Resp.php 887 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * 应答体
  4. * @author gwang
  5. */
  6. class Resp {
  7. //put your code here
  8. /**
  9. * 应答数据
  10. * @var type
  11. */
  12. public $data = null;
  13. /**
  14. * 错误码
  15. * @var type
  16. */
  17. public $err = 0;
  18. /**
  19. * 错误消息
  20. * @var type
  21. */
  22. public $errMsg = "";
  23. function stringify() {
  24. return json_encode($this);
  25. }
  26. function __toString() {
  27. return $this->stringify();
  28. }
  29. /**
  30. *
  31. * @param type $data
  32. * @return \Resp
  33. */
  34. static function ret($data) {
  35. $resp = new Resp();
  36. $resp->data = $data;
  37. return $resp;
  38. }
  39. /**
  40. *
  41. * @param type $err
  42. * @param type $msg
  43. * @return \Resp
  44. */
  45. static function err($err, $msg) {
  46. $resp = new Resp();
  47. $resp->err = $err;
  48. $resp->errMsg = $msg;
  49. return $resp;
  50. }
  51. }