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) { [$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); if($resp === false) { return [false,'系统错误']; } else { Log::record($resp,Log::DEBUG); $resp = json_decode($resp,true); if($resp['code'] == 0) { refill\util::inc_card($card_no,$card_info); $data = $resp['data']; return [true,$data['orderNumber']]; } else { return [false,$resp['message']]; } } } public function query($refill_info) { return [false,'未实现查询接口']; } }