getMillisecond(); $params['notifyUrl'] = config::NOTIFY_URL; return $params; } public function add($card_no, $card_type, $amount, $params,&$net_errno = 0) { $params = $this->req_params($card_no, $card_type, $params['order_sn'], $amount); $sign = $this->sign($params); $params['sign'] = $sign; $resp = http_request(config::ORDER_URL, $params, 'POST', false, config::ExtHeaders, $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'] === 200) { return [true, '', false]; } else { return [false, $resp['msg'], false]; } } } public function query($refill_info) { $params['type'] = 'query'; $params['merchantId'] = config::MCH_ID; $params['outTradeNo'] = $refill_info['order_sn']; $sign = $this->sign($params); $params['sign'] = $sign; $resp = http_request(config::QUERY_URL, $params); if (empty($resp)) { return [false, '系统错误']; } else { Log::record($resp, Log::DEBUG); $resp = json_decode($resp, true); if (empty($resp)) { return [false, '系统错误']; } elseif ($resp['code'] === 200) { $update['ch_trade_no'] = $resp['data']['orderNo']; $status = $resp['data']['state']; if ($status === 'SUCCESS') { $update['official_sn'] = $resp['data']['proof']; $order_state = ORDER_STATE_SUCCESS; } elseif ($status === 'FAIL') { $order_state = ORDER_STATE_CANCEL; } elseif ($status === 'PENDING') { $order_state = ORDER_STATE_SEND; } else { return [false, $status]; } Model('refill_order')->edit($refill_info['order_id'], $update); return [true, $order_state]; } elseif ($resp['code'] === 207 && (time() - $refill_info['commit_time'] >= 300)) { $order_state = ORDER_STATE_NOEXIST; return [true, $order_state]; } else { return [false, $resp['msg']]; } } } public function balance() { $params['type'] = 'balance'; $params['merchantId'] = config::MCH_ID; $sign = $this->sign($params); $params['sign'] = $sign; $resp = http_request(config::BALANCE_URL, $params); if (empty($resp)) { return [false, '网络错误']; } else { Log::record($resp, Log::DEBUG); $resp = json_decode($resp, true); if ($resp['code'] === 200) { return [true, $resp['data']['balance']]; } else { return [false, $resp['msg']]; } } } private function sign($params) { $content = ''; ksort($params); foreach ($params as $key => $val){ $content .= "{$key}=". urlencode($val) ."&"; } $content .= "key=".config::KEY; return md5($content); } private function getMillisecond() { $cur = microtime (true); return intval($cur * 1000); } }