config::AppKey, 'timestamp' => time(), 'product_id' => config::PRODUCT_ID, 'third_id' => $order_sn, 'call_back_url' => config::NOTIFY_URL, 'datas' => [ 'target' => "$phone", 'amount' => $amount, 'operator_id' => $operator_id ] ]; if (!empty($region)) { $params['datas']['prov_code'] = $region; } $params['sign'] = config::sign($params); 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, $params['regin_no'] ?? -1); if (empty($params)) { return [false, '提单参数不符合', false]; } $resp = http_post_data(config::ORDER_URL, json_encode($params), config::ExtHeaders); if (empty($resp)) { return [false, '网络错误', true]; } else { Log::record($resp, Log::DEBUG); $resp = json_decode($resp, true); if (empty($resp)) { return [false, '网络错误', true]; } $code = $resp['code']; if ($code === 0) { return [true, $resp['data']['order_id'], false]; } elseif (in_array($code, [10010, 10015])) { $net_errno = "HTTP-$code"; $errmsg = config::ERRMSG[$code] ?? ''; return [false, $errmsg, true]; } else { $errmsg = config::ERRMSG[$code] ?? ''; return [false, $errmsg, false]; } } } private function query_params($refill_info) { $params = [ 'app_key' => config::AppKey, 'timestamp' => time(), 'third_id' => $refill_info['order_sn'], 'time' => $refill_info['commit_time'] ]; $params['sign'] = config::sign($params); return $params; } public function query($refill_info): array { $params = $this->query_params($refill_info); $resp = http_post_data(config::QUERY_URL, json_encode($params), config::ExtHeaders); if (empty($resp)) { return [false, '系统错误', '']; } else { Log::record($resp, Log::DEBUG); $resp = json_decode($resp, true); if (empty($resp)) { return [false, '系统错误', '']; } $official_sn = ''; $code = intval($resp['code']); if ($code === 0) { $order_id = $refill_info['order_id']; $data = $resp['data']; $state = $data['state']; if ($state === 3) { $official_sn = $data['voucher'] ?? ''; $ch_trade_no = $data['order_id'] ?? ''; Model('refill_order')->edit($order_id, ['ch_trade_no' => $ch_trade_no,'official_sn' => $official_sn]); $order_state = ORDER_STATE_SUCCESS; } elseif(in_array($state, [4,6])) { $ch_trade_no = $data['order_id'] ?? ''; Model('refill_order')->edit($order_id, ['ch_trade_no' => $ch_trade_no]); $order_state = ORDER_STATE_CANCEL; } else { $order_state = ORDER_STATE_SEND; } } else { return [false, '其他,或网络错误', '']; } return [true, $order_state, $official_sn]; } } private function balance_params() { $params = [ 'app_key' => config::AppKey, 'timestamp' => time(), ]; $params['sign'] = config::sign($params); return $params; } public function balance(): array { $params = $this->balance_params(); $resp = http_post_data(config::BALANCE_URL, json_encode($params), 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'] === 0) { return [true, ncPriceFormat($resp['data']['amount'])]; } else { return [false, '其它,失败']; } } } }