|
@@ -0,0 +1,141 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+
|
|
|
+namespace refill\gftd;
|
|
|
+
|
|
|
+require_once(BASE_HELPER_PATH . '/refill/gftd/config.php');
|
|
|
+
|
|
|
+
|
|
|
+use refill;
|
|
|
+use mtopcard;
|
|
|
+use Log;
|
|
|
+
|
|
|
+class RefillOil extends refill\IRefillOil
|
|
|
+{
|
|
|
+ public function __construct($cfgs)
|
|
|
+ {
|
|
|
+ parent::__construct($cfgs);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function req_params(string $card_no,int $card_type,int $amount,array $other)
|
|
|
+ {
|
|
|
+ $params['appid'] = config::APP_ID;
|
|
|
+ $params['ts'] = time();
|
|
|
+
|
|
|
+ $params['productId'] = $this->product_id($amount,$card_type);
|
|
|
+ $params['outOrderNumber'] = $other['order_sn'];
|
|
|
+ $params['fuelCardNumber'] = $card_no;
|
|
|
+
|
|
|
+ $params['fuelCardUserName'] = "";
|
|
|
+ $params['fuelCardUserID'] = "";
|
|
|
+
|
|
|
+ $mobile = $this->make_mobile();
|
|
|
+ $params['telephone'] = $mobile;
|
|
|
+ $params['phoneNumber'] = $mobile;
|
|
|
+
|
|
|
+ return $params;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function make_mobile()
|
|
|
+ {
|
|
|
+ $no = "1" . mt_rand(3000000000, 9999999999);
|
|
|
+ return $no;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 = $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)
|
|
|
+ {
|
|
|
+ $data = $resp['data'];
|
|
|
+ return [true,$data['orderNumber']];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return [false,$resp['message']];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function query($refill_info)
|
|
|
+ {
|
|
|
+ return [false,'未实现查询接口'];
|
|
|
+ }
|
|
|
+}
|