getMillisecond(); $params['notifyUrl'] = config::NOTIFY_URL; return $params; } public function add($card_no, $card_type, $amount, $input,&$net_errno = 0) { refill\util::send_test($params['order_sn']); return [true , '',false]; } public function query($refill_info) { $params['orderNumber'] = $refill_info['order_sn']; $params['username'] = config::USERNAME; $content = $params['username'] . $params['orderNumber'] . config::KEY; $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, '网络错误']; } $oper_status = intval($resp['code']['status']); if ($oper_status == 100000) { $obj = $resp['obj']; $code = $obj['resultCode']; $order_id = $refill_info['order_id']; if ($code == 2) { //充值成功 $order_state = ORDER_STATE_SUCCESS; $updata['official_sn'] = strtolower($obj['rechargeVoucher']) == 'null' ? '' : $obj['rechargeVoucher']; Model('refill_order')->edit($refill_info['order_id'], $updata); cards_helper::assign($order_id, ''); } elseif ($code == 3) { //充值失败 $order_state = ORDER_STATE_CANCEL; $this->onError($order_id, $obj['rechargeDesc']); } elseif($code == 4) { //订单存疑,需要人工确认 return [false, $resp['code']['desc']]; } else { $order_state = ORDER_STATE_SEND; } return [true, $order_state]; } else { return [false, $resp['code']['desc']]; } } } private function onError($order_id, $desc) { $desc = json_decode($desc, true); $status = $desc['rechargeStatus']; $desc = $desc['rechargeDesc']; if (in_array($status, [600400, 600401, 600402, 600403, 600404, 600405])) { cards_helper::freeze($order_id,$desc); } else { cards_helper::reuse($order_id); } } private function sign($params) { $key = config::KEY; $content = $params['username'] . $params['orderNumber'] . $params['cardNumber'] . $params['cardExt'] . $params['rechargeNum'] . $params['rechargePwd'] . $params['productNo']; $content .= $params['timestamp'] . $key; return md5($content); } /** * 获取毫秒级别的时间戳 */ private function getMillisecond() { $cur = microtime (true); $cur = intval($cur * 1000); return $cur; } private function encryptWithOpenssl($data = '') { $key = substr(config::KEY , 0 ,16); $iv = substr(config::KEY , -16); return base64_encode(openssl_encrypt($data, "AES-128-CBC", $key, OPENSSL_RAW_DATA, $iv)); } }