hnyd.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace refill\by_online_copy;
  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. $id = trim($this->mRecord['CANCEL_CHARGE_ID']);
  31. if(empty($id)) {
  32. return false;
  33. } else {
  34. return true;
  35. }
  36. }
  37. public function successed()
  38. {
  39. $charge_time = $this->charge_time();
  40. if(empty($this->charge_id()) or empty($this->trade_id()) or $this->fee() <= 0 or $charge_time=== false or $charge_time <= 0) {
  41. return false;
  42. } else {
  43. return true;
  44. }
  45. }
  46. }
  47. class response
  48. {
  49. private $mResult;
  50. private $mRecords = [];
  51. private $respCode;
  52. public function __construct($resp)
  53. {
  54. $this->respCode = intval($resp['respCode']);
  55. $this->mResult = $resp['result'];
  56. ksort($this->mResult);
  57. if(isset($this->mResult['data']))
  58. {
  59. $items = $this->mResult['data'];
  60. foreach ( $items as $item)
  61. {
  62. ksort($item);
  63. $this->mRecords[] = $item;
  64. }
  65. unset($this->mResult['data']);
  66. }
  67. else
  68. {
  69. $keys = [ "MONTH", "RECV_FEE", "RECV_TIME", "BIND_SERIAL_NUMBER",
  70. "OUT_TRADE_ID", "GROUP_ID", "CHARGE_ID", "CANCEL_CHARGE_ID",
  71. "CANCEL_TAG", "CANCEL_TIME", "REMARK", "LOCAL_SN", "CUST_NAME"];
  72. $item = [];
  73. foreach ($keys as $key) {
  74. $item[$key] = $this->mResult[$key] ?? "";
  75. }
  76. ksort($item);
  77. $this->mRecords[] = $item;
  78. foreach ($keys as $key) {
  79. unset($this->mResult[$key]);
  80. }
  81. }
  82. }
  83. public function find_record($charge_id)
  84. {
  85. foreach ($this->mRecords as $record)
  86. {
  87. $chid = $record['CHARGE_ID'];
  88. if($chid == $charge_id) {
  89. return new record($record);
  90. }
  91. elseif($chid === '1111111111') {
  92. return new record($record);
  93. }
  94. }
  95. return false;
  96. }
  97. public function record_count()
  98. {
  99. $count = intval($this->mResult['X_RECORDNUM'] ?? 0);
  100. return $count;
  101. }
  102. }