aes_encrypt($data); return $params; } public function add($card_no, $card_type, $amount, $params,&$net_errno = 0) { $params = $this->req_params($card_no, $card_type, $amount, $params['order_sn']); $resp = http_request(config::ORDER_URL, $params, 'POST', false, config::ExtHeaders, $net_errno); if (empty($resp)) { return [false, '系统错误', true]; } else { Log::record($resp, Log::DEBUG); $resp = json_decode($resp, true); if (empty($resp)) { return [false, '系统错误', true]; } elseif ($resp['code'] === 'success') { return [true, $resp['data']['trans_sn'], false]; } else { return [false, $resp['msg'], false]; } } } public function query($refill_info) { $params['mchid'] = config::MCH_ID; $params['order_id'] = $refill_info['order_sn']; $params['time'] = time(); $content = "{$params['mchid']}{$params['order_id']}{$params['time']}".config::UserKey; $params['sign'] =md5($content) ; $resp = http_request(config::QUERY_URL, $params, 'POST', false, config::ExtHeaders); if (empty($resp)) { return [false, '系统错误']; } else { Log::record($resp, Log::DEBUG); $resp = json_decode($resp, true); if (empty($resp)) { return [false, '系统错误']; } elseif ($resp['code'] === '3') { $status = $resp['data']['status']; if ($status === 3) { Model('refill_order')->edit($refill_info['order_id'], ['official_sn' => $resp['data']['certificate']]); $order_state = ORDER_STATE_SUCCESS; } elseif (in_array($status, [0, 2], true)) { $order_state = ORDER_STATE_CANCEL; } elseif ($status === 1) { $order_state = ORDER_STATE_SEND; } else { return [false, $status]; } return [true, $order_state]; } elseif ($resp['code'] === '2' && time() - $refill_info['commit_time'] > 600) { return [true, ORDER_STATE_NOEXIST]; } else { return [false, $resp['msg']]; } } } public function balance() { $params['mchid'] = config::MCH_ID; $params['time'] = time(); $content = "{$params['mchid']}{$params['time']}".config::UserKey; $params['sign'] =md5($content) ; $resp = http_request(config::BALANCE_URL, $params, 'POST', false, config::ExtHeaders); Log::record($resp, Log::DEBUG); $resp = json_decode($resp, true); if (empty($resp)) { return [false, '系统错误']; } elseif ($resp['code'] === '3') { return [true, $resp['data']['money']]; } else { return [false, $resp['msg']]; } } private function aes_encrypt($params): string { $encrypt = json_encode($params); return base64_encode(openssl_encrypt($encrypt, 'AES-128-CBC', config::UserKey, OPENSSL_RAW_DATA, config::aesIV)); } }