hnyd.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace refill\by_online_cb;
  3. class record
  4. {
  5. private $mRecord;
  6. public function __construct($record)
  7. {
  8. $this->mRecord = $record;
  9. }
  10. public function charge_id() {
  11. return trim($this->mRecord['CHARGE_ID']);
  12. }
  13. public function trade_id() {
  14. return trim($this->mRecord['OUT_TRADE_ID']);
  15. }
  16. public function fee()
  17. {
  18. return intval($this->mRecord['RECV_FEE']);
  19. }
  20. public function charge_time()
  21. {
  22. if(empty($this->mRecord['RECV_TIME'])) {
  23. return false;
  24. } else {
  25. return strtotime($this->mRecord['RECV_TIME']);
  26. }
  27. }
  28. public function canceled()
  29. {
  30. $deal_tag = $this->deal_tag();
  31. return ($deal_tag === 2);
  32. }
  33. private function deal_tag()
  34. {
  35. return intval($this->mRecord['DEAL_TAG'] ?? 0);
  36. }
  37. public function successed()
  38. {
  39. $deal_tag = $this->deal_tag();
  40. return ($deal_tag === 1);
  41. }
  42. }
  43. class response
  44. {
  45. private $mResult;
  46. private $mRecords = [];
  47. private $respCode;
  48. public function __construct($resp)
  49. {
  50. $this->respCode = intval($resp['respCode']);
  51. $this->mResult = $resp['result'];
  52. ksort($this->mResult);
  53. if(isset($this->mResult['data']))
  54. {
  55. $items = $this->mResult['data'];
  56. foreach ( $items as $item)
  57. {
  58. ksort($item);
  59. $this->mRecords[] = $item;
  60. }
  61. unset($this->mResult['data']);
  62. }
  63. else
  64. {
  65. $keys = ["DEAL_INFO","MONTH","DEAL_TAG","USER_ID_OUT","SERIAL_NUMBER_OUT",
  66. "DEAL_TIME","RECV_FEE","RECV_TIME","BIND_SERIAL_NUMBER","OUT_TRADE_ID",
  67. "GROUP_ID","CHARGE_ID","CANCEL_CHARGE_ID","ACCT_ID_OUT","CANCEL_TAG",
  68. "CANCEL_TIME","REMARK","LOCAL_SN","KITE_ORDER_NUM","CUST_NAME"];
  69. $item = [];
  70. foreach ($keys as $key) {
  71. $item[$key] = $this->mResult[$key] ?? "";
  72. }
  73. ksort($item);
  74. $this->mRecords[] = $item;
  75. foreach ($keys as $key) {
  76. unset($this->mResult[$key]);
  77. }
  78. }
  79. }
  80. public function find_record($charge_id)
  81. {
  82. foreach ($this->mRecords as $record)
  83. {
  84. $chid = $record['CHARGE_ID'];
  85. if($chid == $charge_id) {
  86. return new record($record);
  87. }
  88. }
  89. return false;
  90. }
  91. }