pack_params($params); $resp = http_post_data(config::API_URL, $body, config::ExtHeaders, $net_errno); $resp = iconv('GB2312', 'UTF-8', $resp); 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['errorCode'] === 1) { return [true, $resp['chargeId'], false]; } elseif (in_array($resp['errorCode'], [-992, -993, -994, -995, -996, -997, -998], true)) { $net_errno = "HTTP-{$resp['errorCode']}"; return [false, $net_errno, true]; } else { return [false, $resp['errorDesc'], false]; } } } public function query($refill_info) { $params_getter = function ($order_sn) { $params = []; $params['orderId'] = $order_sn; $params['action'] = 'CX'; return $params; }; $params = $params_getter($refill_info['order_sn']); $body = $this->pack_params($params); $resp = http_post_data(config::API_URL, $body, config::ExtHeaders, $net_errno); $resp = iconv('GB2312', 'UTF-8', $resp); if (empty($resp)) { return [false, '系统错误']; } else { Log::record($resp, Log::DEBUG); $resp = json_decode($resp, true); if (empty($resp)) { return [false, '系统错误']; } elseif ($resp['errorCode'] === 1) { $status = $resp['orderStatuInt']; if (in_array($status, ['11', '16'], true)) { $order_state = ORDER_STATE_SUCCESS; } elseif (in_array($status, ['20', '21', '26'], true)) { $order_state = ORDER_STATE_CANCEL; } elseif (in_array($status, ['0', '1', '2', '6'], true)) { $order_state = ORDER_STATE_SEND; } else { return [false, $resp['errorDesc']]; } return [true, $order_state]; } elseif ($resp['errorCode'] === -201 && (time() - $refill_info['commit_time'] >= 180)) { return [true, ORDER_STATE_NOEXIST]; } else { return [false, $resp['errorDesc']]; } } } public function balance() { $params_getter = function () { $params['action'] = 'YE'; return $params; }; $params = $params_getter(); $body = $this->pack_params($params); $resp = http_post_data(config::API_URL, $body, config::ExtHeaders, $net_errno); $resp = iconv('GB2312', 'UTF-8', $resp); if (empty($resp)) { return [false, '系统错误']; } else { Log::record($resp, Log::DEBUG); $resp = json_decode($resp, true); if (empty($resp)) { return [false, '系统错误']; } elseif ($resp['errorCode'] === 1) { return [true, $resp['agentBalance']]; } else { return [false, $resp['errorDesc']]; } } } }