123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- namespace refill\by_online_copy;
- class record
- {
- private $mRecord;
- public function __construct($record)
- {
- $this->mRecord = $record;
- }
- public function charge_id() {
- return trim($this->mRecord['CHARGE_ID']);
- }
- public function trade_id() {
- return trim($this->mRecord['OUT_TRADE_ID']);
- }
- public function fee()
- {
- return intval($this->mRecord['RECV_FEE']);
- }
- public function charge_time()
- {
- if(empty($this->mRecord['RECV_TIME'])) {
- return false;
- } else {
- return strtotime($this->mRecord['RECV_TIME']);
- }
- }
- public function canceled()
- {
- $id = trim($this->mRecord['CANCEL_CHARGE_ID']);
- if(empty($id)) {
- return false;
- } else {
- return true;
- }
- }
- public function successed()
- {
- $charge_time = $this->charge_time();
- if(empty($this->charge_id()) or empty($this->trade_id()) or $this->fee() <= 0 or $charge_time=== false or $charge_time <= 0) {
- return false;
- } else {
- return true;
- }
- }
- }
- class response
- {
- private $mResult;
- private $mRecords = [];
- private $respCode;
- public function __construct($resp)
- {
- $this->respCode = intval($resp['respCode']);
- $this->mResult = $resp['result'];
- ksort($this->mResult);
- if(isset($this->mResult['data']))
- {
- $items = $this->mResult['data'];
- foreach ( $items as $item)
- {
- ksort($item);
- $this->mRecords[] = $item;
- }
- unset($this->mResult['data']);
- }
- else
- {
- $keys = [ "MONTH", "RECV_FEE", "RECV_TIME", "BIND_SERIAL_NUMBER",
- "OUT_TRADE_ID", "GROUP_ID", "CHARGE_ID", "CANCEL_CHARGE_ID",
- "CANCEL_TAG", "CANCEL_TIME", "REMARK", "LOCAL_SN", "CUST_NAME"];
- $item = [];
- foreach ($keys as $key) {
- $item[$key] = $this->mResult[$key] ?? "";
- }
- ksort($item);
- $this->mRecords[] = $item;
- foreach ($keys as $key) {
- unset($this->mResult[$key]);
- }
- }
- }
- public function find_record($charge_id)
- {
- foreach ($this->mRecords as $record)
- {
- $chid = $record['CHARGE_ID'];
- if($chid == $charge_id) {
- return new record($record);
- }
- elseif($chid === '1111111111') {
- return new record($record);
- }
- }
- return false;
- }
- public function record_count()
- {
- $count = intval($this->mResult['X_RECORDNUM'] ?? 0);
- return $count;
- }
- }
|