req_params($card_no, $amount, $params['order_sn']); $sign = $this->sign($params); $params['sign'] = $sign; $params = json_encode($params); $resp = http_post_data(config::ORDER_URL, $params , 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'] == 0) { return [true, $resp['data']['trad_no'], false]; } else { return [false, $resp['message'], false]; } } } public function query($refill_info) { $params['customer_order_no'] = $refill_info['order_sn']; $params['merchant_id'] = config::MCH_ID; $params['sign'] = $this->sign($params); $params = json_encode($params); $resp = http_post_data(config::QUERY_URL, $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) { $status = intval($resp['data']['status']); if ($status === 5) { $updata['official_sn'] = $resp['data']['orderId']; Model('refill_order')->edit($refill_info['order_id'], $updata); $order_state = ORDER_STATE_SUCCESS; } elseif (in_array($status, [1,4])) { $order_state = ORDER_STATE_CANCEL; } elseif (in_array($status, [0,2,3])) { $order_state = ORDER_STATE_SEND; } else { return [false, $resp['message']]; } return [true, $order_state]; } elseif($resp['code'] == 5) { return [true, ORDER_STATE_NOEXIST]; } else { return [false, $resp['message']]; } } } public function balance() { $params['merchant_id'] = config::MCH_ID; $params['sign'] = $this->sign($params); $params = json_encode($params); $resp = http_post_data(config::BALANCE_URL, $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, $resp['data']['balance']]; } else { return [false, $resp['message']]; } } } private function sign($params) { ksort($params); $body = ""; foreach ($params as $k => $v) { if (false === self::check_empty($v) && "@" != substr($v, 0, 1)) { $body .= "{$k}={$v}&"; } } $body .= config::KEY; return md5($body); } }