product_id($amount,$card_type); $params['outOrderNumber'] = $other['order_sn']; $params['fuelCardNumber'] = $card_no; $params['fuelCardUserName'] = ""; $params['fuelCardUserID'] = ""; $card_info = refill\util::read_card($card_no,$card_type); $params['telephone'] = $card_info['bind_phone']; $params['phoneNumber'] = $card_info['bind_phone']; return [$params, $card_info]; } private function product_id(int $amount,int $cart_type) { if($cart_type === mtopcard\PetroChinaCard) { switch ($amount) { case 100: return 1; case 200: return 2; case 500: return 3; case 1000: return 4; } } else { switch ($amount) { case 100: return 5; case 200: return 6; case 500: return 7; case 1000: return 8; } } return false; } private function sign($params) { $body = $this->body($params); $body .= config::APP_SECRET; return md5($body); } protected function check_empty($value) { if (!isset($value)) return true; if ($value === null) return true; if (trim($value) === "") return true; return false; } private function body($params) { ksort($params); $body = ""; $i = 0; foreach ($params as $k => $v) { if (false === $this->check_empty($v) && "@" != substr($v, 0, 1)) { if ($i == 0) { $body .= "{$k}" . "=" . $v; } else { $body .= "&" . "{$k}" . "=" . $v; } $i++; } } return $body; } public function add($card_no,$card_type,$amount,$input,&$net_errno = 0) { [$params,$card_info] = $this->req_params($card_no,$card_type,$amount,$input); $sign = $this->sign($params); $params['signature'] = $sign; $uri = config::ORDER_URL . "/fuelRecharge/create"; $resp = http_post_data($uri,json_encode($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) { refill\util::inc_card($card_no,$card_info); $data = $resp['data']; return [true,$data['orderNumber'], false]; } else { return [false,$resp['message'], false]; } } } private function query_params($order_sn) { $params['appid'] = config::APP_ID; $params['ts'] = time(); $params['outOrderNumber'] = $order_sn; return $params; } public function query($refill_info) { $order_sn = $refill_info['order_sn']; $order_id = $refill_info['order_id']; $params = $this->query_params($order_sn); $sign = $this->sign($params); $params['signature'] = $sign; $uri = config::ORDER_URL . "/fuelRecharge/order/detail"; $resp = http_post_data($uri,json_encode($params), config::ExtHeaders); Log::record("query resp={$resp}",Log::DEBUG); if(empty($resp)) { return [false,'网络错误']; } Log::record($resp,Log::DEBUG); $resp = json_decode($resp,true); if(empty($resp)) { return [false,'网络错误']; } elseif($resp['code'] == 0) { $data = $resp['data']; $status = intval($data['orderStatus']); if ($status === 101) { $updata['official_sn'] = $data['voucher']; $updata['ch_trade_no'] = $data['orderNumber']; $updata['err_msg'] = $resp['message']; Model('refill_order')->edit($order_id, $updata); return [true, ORDER_STATE_SUCCESS]; } elseif ($status === 102) { $updata['official_sn'] = $data['voucher']; $updata['ch_trade_no'] = $data['orderNumber']; $updata['err_msg'] = $resp['message']; Model('refill_order')->edit($order_id, $updata); $this->onError($resp['message'],$order_id); return [true, ORDER_STATE_CANCEL]; } elseif($status === 100 || $status === 106) { return [true, ORDER_STATE_SEND]; } else { return [false, $resp['message']]; } } else { return [false,$resp['message']]; } } public function onError($msg,$order_id) { if(in_array($msg,config::BlackMsgs)) { $refill = Model('refill_order'); $order = $refill->getOrderInfo(['order_id' => $order_id]); if(empty($order)) return false; $card_no = $order['card_no']; if(!empty($card_no)) { refill\util::set_black($card_no); return true; } } return false; } public function balance() { return [false, '暂无余额接口']; } }