getMillisecond(); $card_info = refill\util::read_card($card_no,$card_type); $params['cardPhone'] = $card_info['bind_phone']; return [$params, $card_info]; } public function add($card_no, $card_type, $amount, $params,&$net_errno = 0) { [$params, $card_info] = $this->req_params($card_no, $amount, $card_type, $params['order_sn']); $sign = $this->sign($params); $params['sign'] = $sign; $app_key = config::APP_KEY; $header = [ "App-Channel: {$app_key}" ]; $resp = http_request(config::ORDER_URL, $params, 'POST', false, $header, $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'] == 0 && $resp['data']['status'] == 'SUBMIT') { refill\util::inc_card($card_no,$card_info); return [true, $resp['data']['id'], false]; } elseif ($resp['code'] == -1){ //未知错误,需人工确认。 $net_errno = "HTTP-999"; return [false, $resp['msg'], false]; } else { $msg = "{$resp['msg']}-{$resp['data']['status']}"; return [false, $msg, false]; } } } public function query($refill_info) { $params['orderNo'] = $refill_info['order_sn']; $params['timestamp'] = $this->getMillisecond(); $content = "orderNo={$params['orderNo']}" . config::APP_SECRET . $params['timestamp']; $params['sign'] = md5($content); $app_key = config::APP_KEY; $header = [ "App-Channel: {$app_key}" ]; $resp = http_request(config::QUERY_URL, $params, 'GET', false, $header); 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) { $status = $resp['data']['status']; if ($status == 'SUCCESS') { //流水号格式为json,实例:["2421071918070053"] $official_sn = json_decode($resp['data']['vouchers'], true); $updata['official_sn'] = $official_sn[0]; Model('refill_order')->edit($refill_info['order_id'], $updata); $order_state = ORDER_STATE_SUCCESS; } elseif (in_array($status, ['SUBMIT_FAIL', 'FAIL'])) { $order_state = ORDER_STATE_CANCEL; } elseif (in_array($status, ['CREATED', 'SUBMIT', 'CB_WAITING'])) { $order_state = ORDER_STATE_SEND; } else { return [false, $status]; } return [true, $order_state]; } else { return [false, $resp['msg']]; } } } public function balance() { return [false, '暂无余额接口']; } private function sign($params) { $timestamp = $params['timestamp']; unset($params['timestamp']); $content = ''; ksort($params); foreach ($params as $key => $val){ if(false === $this->check_empty($val)) { $content .= "{$key}={$val}&"; } } $content = rtrim($content,'&'); $content .= config::APP_SECRET; $content .= $timestamp; Log::record($content, Log::DEBUG); return md5($content); } /** * 获取毫秒级别的时间戳 */ private function getMillisecond() { $cur = microtime (true); $cur = intval($cur * 1000); return $cur; } }