config::szAgentId, 'szOrderId' => $order_sn, 'szPhoneNum'=> "$phone", 'nMoney' => $amount, 'nSortType' => $nSortType, 'nProductClass' => 1, 'nProductType' =>"1", 'szTimeStamp'=> date("Y-m-d H:i:s"), 'szNotifyUrl' => config::NOTIFY_URL ]; $params['szVerifyString'] = config::sign($params,config::add_keys); return $params; } //[$state, $errmsg, $neterr] public function add($card_no, $card_type, $amount, $params, &$net_errno = 0): array { $params = $this->add_params($card_no, $amount, $params['order_sn'], $card_type); if(empty($params)) { return [false, '提单参数不符合', false]; } $resp = http_request(config::ORDER_URL, $params , 'POST' , false , [] , $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]; } $nRtn = $resp['nRtn']; if ($nRtn === 0) { //下单成功 return [true, '', false]; } elseif (in_array($nRtn, config::ERRCODES, true)) { return [false, config::ERRMSG[$nRtn], false]; } elseif (in_array($nRtn, [2050, 999])) { $net_errno = "HTTP-$nRtn"; return [false, $net_errno, true]; } else { $net_errno = "HTTP-998"; return [false, $net_errno, true]; } } } private function query_params($refill_info) { $params = [ 'szAgentId' => config::szAgentId, 'szOrderId' => $refill_info['order_sn'], 'szFormat' => 'JSON', ]; $params['szVerifyString'] = config::sign($params, config::query_keys); return $params; } public function query($refill_info): array { $params = $this->query_params($refill_info); $resp = http_request(config::QUERY_URL, $params , 'POST'); if (empty($resp)) { return [false, '系统错误', '']; } else { Log::record($resp, Log::DEBUG); $resp = json_decode($resp, true); if (empty($resp)) { return [false, '系统错误', '']; } $official_sn = ''; $nRtn = intval($resp['nRtn']); if ($nRtn === 5012) { $official_sn = config::get_osn($resp['szRtnMsg'] ?? ''); Model('refill_order')->edit($refill_info['order_id'], ['official_sn' => $official_sn]); $order_state = ORDER_STATE_SUCCESS; } elseif($nRtn === 5013) { $order_state = ORDER_STATE_CANCEL; } elseif (in_array($nRtn, [999, 5001, 5002, 5003, 5004, 5011, 5019])) { $order_state = ORDER_STATE_SEND; } elseif($nRtn === 5005 and (time() - $refill_info['commit_time'] >= 300)) { $order_state = ORDER_STATE_NOEXIST; } else { return [false, '其他,或网络错误', '']; } return [true, $order_state, $official_sn]; } } private function balance_params() { $params = [ 'szAgentId' => config::szAgentId ]; $params['szVerifyString'] = config::sign($params, config::balance_keys); return $params; } public function balance(): array { $params = $this->balance_params(); $resp = http_request(config::BALANCE_URL, $params , 'POST'); if (empty($resp)) { return [false, '系统错误']; } else { Log::record($resp, Log::DEBUG); $resp = json_decode($resp, true); if (empty($resp)) { return [false, '系统错误']; } elseif ($resp['nRtn'] === 0) { return [true, ncPriceFormat($resp['fBalance'] + $resp['fCredit'])]; } else { return [false, '其它,失败']; } } } }