소스 검색

oil xinsj

xiaoyu 3 년 전
부모
커밋
c2e7732634
3개의 변경된 파일261개의 추가작업 그리고 0개의 파일을 삭제
  1. 68 0
      helper/refill/api/xyz/xinsj/RefillCallBack.php
  2. 118 0
      helper/refill/api/xyz/xinsj/RefillOil.php
  3. 75 0
      helper/refill/api/xyz/xinsj/config.php

+ 68 - 0
helper/refill/api/xyz/xinsj/RefillCallBack.php

@@ -0,0 +1,68 @@
+<?php
+
+
+namespace refill\xinsj;
+
+require_once(BASE_HELPER_RAPI_PATH . '/xinsj/config.php');
+
+use refill;
+
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $input = $params;
+        unset($input['signature']);
+        $sign = $this->sign($input);
+        if ($params['appid'] == config::APPID && $params['signature'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    protected function check_empty($value)
+    {
+        if (!isset($value))
+            return true;
+        if ($value === null)
+            return true;
+        if (trim($value) === "")
+            return true;
+
+        return false;
+    }
+
+    private function sign($input)
+    {
+        $key = config::APPKEY;
+        $body = config::body($input);
+        $body .= "&token={$key}";
+
+        return strtolower(md5($body));
+    }
+
+    //[$order_id, $success, $can_try, $need_handle]
+    public function notify($params)
+    {
+        $status = intval($params['status']);
+        $order_sn = $params['morder'];
+        $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
+        if (empty($order_info)) {
+            return [false, false, false,false];
+        }
+        $order_id = $order_info['order_id'];
+
+        if ($status === 2) {
+            $data['official_sn'] = strtolower($params['vnum']) == 'null' ? '' : $params['vnum'];
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false,true];
+        }
+        elseif ($status === 3) {
+            return [$order_id, false, true,true];
+        }
+        else {
+            return [$order_id, false, false,false];
+        }
+    }
+}

+ 118 - 0
helper/refill/api/xyz/xinsj/RefillOil.php

@@ -0,0 +1,118 @@
+<?php
+namespace refill\xinsj;
+
+require_once(BASE_HELPER_RAPI_PATH . '/xinsj/config.php');
+
+use refill;
+use Log;
+
+class RefillOil extends refill\IRefillPhone
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    private function req_params(int $card_no, int $card_type, int $amount, string $order_sn)
+    {
+        $params['fuelCardNumber'] = $card_no;
+        $params['outOrderNumber'] = $order_sn;
+        $params['productId'] = config::getProduct($card_type, $amount);
+        $params['actualAmount'] = $amount;
+
+        return $params;
+    }
+
+    private function req_headers($sign)
+    {
+        $appId = config::APPID;
+        $time = time();
+        return [
+            'Content-Type: application/json',
+            "appId: {$appId}",
+            "requestTime: {$time}",
+            "signature: {$sign}",
+        ];
+    }
+
+
+    public function add($card_no, $card_type,$amount,$input,&$net_errno = 0)
+    {
+        $order_sn = $input['order_sn'];
+        $params = $this->req_params($card_no,$card_type,$amount,$order_sn);
+        if(empty($params['productId'])) {
+            return [false,"上游{$this->name()}产品不支持:{$card_type}-{$amount}",true];
+        }
+
+        $sign = $this->sign($params);
+        $header = $this->req_headers($sign);
+
+        $data['data'] = $params;
+        $post_data = json_encode($data);
+        $resp = http_post_data(config::ORDER_URL,$post_data,$header,$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'] == 1005) {
+                return [true, $resp['orderNumber'], false];
+            } else {
+                return [false, $resp['message'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['appid'] = config::APPID;
+        $params['morder'] = $refill_info['order_sn'];
+        $sign = $this->sign($params);
+        $params['signature'] = $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, '返回值错误'];
+            }
+
+            $code = intval($resp['code']);
+            $status = intval($resp['data']['status']);
+
+            if ($code != 1) {
+                return [false, $resp['info']];
+            } elseif ($status == 2) {
+                $order_state = ORDER_STATE_SUCCESS;
+                $data['official_sn'] = strtolower($params['vnum']) == 'null' ? '' : $params['vnum'];
+                Model('refill_order')->edit($refill_info['order_id'], $data);
+            } elseif ($status == 3) {
+                $order_state = ORDER_STATE_CANCEL;
+            } else {
+                $order_state = ORDER_STATE_SEND;
+            }
+
+            return [true, $order_state];
+        }
+    }
+
+    private function sign($input)
+    {
+        $key = config::APPKEY;
+        $body = config::body($input);
+        $body .= $key;
+
+        return strtolower(md5($body));
+    }
+}

+ 75 - 0
helper/refill/api/xyz/xinsj/config.php

@@ -0,0 +1,75 @@
+<?php
+
+
+namespace refill\xinsj;
+
+use mtopcard;
+class config
+{
+    const CHANNEL_HOST = 'http://122.114.168.35';
+    const ORDER_URL = config::CHANNEL_HOST . '/gateway/api.run/submit';
+    const QUERY_URL = config::CHANNEL_HOST . '/gateway/api.run/order';
+    const BALANCE_URL = config::CHANNEL_HOST . '/gateway/api.run/account';
+
+    const APPID = 'CZ30533982';
+    const APPKEY = 'lvrg4xoqvrozuq2irjza2a6dlenrsv';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_xinsj.php";
+
+    static function getProduct($card_type,$amount)
+    {
+        if ($card_type == mtopcard\PetroChinaCard)
+        {
+            switch ($amount) {
+                case 100: return 1;
+                case 200: return 2;
+                case 500: return 3;
+                case 1000: return 4;
+                default: return false;
+            }
+        }
+        elseif ($card_type == mtopcard\SinopecCard) {
+            switch ($amount) {
+                case 100: return 5;
+                case 200: return 6;
+                case 500: return 7;
+                case 1000: return 8;
+                default: return false;
+            }
+        }
+        else {
+            return false;
+        }
+    }
+
+    public static function body($params)
+    {
+        ksort($params);
+        $body = "";
+        $i = 0;
+        foreach ($params as $k => $v)
+        {
+            if (false === self::check_empty($v) && "@" != substr($v, 0, 1))
+            {
+                if ($i == 0) {
+                    $body .= "{$k}" . "=" . urlencode($v);
+                } else {
+                    $body .= "&" . "{$k}" . "=" . urlencode($v);
+                }
+                $i++;
+            }
+        }
+        return $body;
+    }
+
+    private static function check_empty($value)
+    {
+        if (!isset($value))
+            return true;
+        if ($value === null)
+            return true;
+        if (trim($value) === "")
+            return true;
+
+        return false;
+    }
+}