JosBaseResponse.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace ACES\Common\domain;
  3. abstract class JosBaseResponse
  4. {
  5. private $code;
  6. private $msg;
  7. private $enDesc;
  8. private $zhDesc;
  9. /**
  10. * @return integer
  11. */
  12. public function getCode()
  13. {
  14. return $this->code;
  15. }
  16. /**
  17. * @param integer|null $code
  18. */
  19. public function setCode($code)
  20. {
  21. $this->code = $code;
  22. }
  23. /**
  24. * @return string
  25. */
  26. public function getMsg()
  27. {
  28. return $this->msg;
  29. }
  30. /**
  31. * @param string|null $msg
  32. */
  33. public function setMsg($msg)
  34. {
  35. $this->msg = $msg;
  36. }
  37. /**
  38. * @return string
  39. */
  40. public function getEnDesc()
  41. {
  42. return $this->enDesc;
  43. }
  44. /**
  45. * @param string|null $enDesc
  46. */
  47. public function setEnDesc($enDesc)
  48. {
  49. $this->enDesc = $enDesc;
  50. }
  51. /**
  52. * @return string
  53. */
  54. public function getZhDesc()
  55. {
  56. return $this->zhDesc;
  57. }
  58. /**
  59. * @param string|null $zhDesc
  60. */
  61. public function setZhDesc($zhDesc)
  62. {
  63. $this->zhDesc = $zhDesc;
  64. }
  65. /**
  66. * @param $josJsonResponse
  67. * @param JosBaseResponse $targetResponse
  68. * @return JosVoucherInfoGetResponse|JosMasterKeyGetResponse|JosSecretApiReportGetResponse
  69. * @throws \JsonMapper_Exception
  70. */
  71. public static function parse($josJsonResponse, JosBaseResponse $targetResponse)
  72. {
  73. $josResponse = json_decode($josJsonResponse);
  74. foreach ($josResponse as $k => $response) {
  75. //TODO thread safe?
  76. $jsonMapper = new \JsonMapper();
  77. $jsonMapper->map($response, $targetResponse);
  78. return $targetResponse;
  79. }
  80. }
  81. }
  82. //$json = '{"jingdong_jos_master_key_get_responce":{"code":"0","response":{"status_code":310,"key_cache_disabled":0,"key_backup_disabled":0,"ts":1566810198390,"errorMsg":"The voucher is null."}}}';
  83. //
  84. //JosBaseResponse::parse($json, new JosBaseResponse());