浏览代码

add refill provider bdt

ayHaru 4 年之前
父节点
当前提交
9e1f5250ac

+ 75 - 0
helper/refill/bdt/RefillCallBack.php

@@ -0,0 +1,75 @@
+<?php
+
+
+namespace refill\bdt;
+
+use refill;
+
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $input = $params;
+        unset($input['sign']);
+
+        $sign = $this->sign($input);
+        if ($params['sign'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private function check_empty($value)
+    {
+        if (!isset($value))
+            return true;
+        if ($value === null)
+            return true;
+        if (trim($value) === "")
+            return true;
+
+        return false;
+    }
+
+    private function sign($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}" . "=" . urldecode($v);
+                } else {
+                    $body .= "&" . "{$k}" . "=" . urldecode($v);
+                }
+                $i++;
+            }
+        }
+
+        $body .= "&key=" . config::KEY;
+        return strtoupper(md5($body));
+    }
+
+    public function notify($params)
+    {
+        $status = intval($params['orderStatus']);
+        $order_sn = $params['cardOwnerOrderNo'];
+
+        $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
+        if (empty($order_info)) {
+            return [false, false, false];
+        }
+        $order_id = $order_info['order_id'];
+        $data['ch_trade_no'] = $params['orderNo'];
+        Model('refill_order')->edit($order_id, $data);
+        if ($status === 1) {
+            return [$order_id, true, false];
+        } else {
+            //速汇充反馈此时可以提交多次.
+            return [$order_id, false, true];
+        }
+    }
+}

+ 78 - 0
helper/refill/bdt/RefillOil.php

@@ -0,0 +1,78 @@
+<?php
+
+
+namespace refill\bdt;
+
+require_once(BASE_HELPER_PATH . '/refill/bdt/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['cardNo'] = $card_no;
+
+        if($card_type == mtopcard\PetroChinaCard) {
+            $params['payType'] = 1001;
+        }
+        elseif($card_type == mtopcard\SinopecCard) {
+            $params['payType'] = 1002;
+        }
+        else {
+            Log::record("RefillOil req_params err params",Log::DEBUG);
+        }
+
+        $params['amount'] = $amount;
+        $params['cardOwnerOrderNo'] = $other['order_sn'];
+        $params['notifyUrl'] = config::NOTIFY_URL;
+        $params['cardOwnerAccount'] = config::CardOwnerAccount;
+        $params['date'] = date("Y-m-d H:i:s");
+        $params['ip'] = config::API_IP;
+
+        return $params;
+    }
+
+    private function sign($params)
+    {
+        $content = '';
+        ksort($params);
+        foreach ($params as $key => $val){
+            $content .= "{$key}={$val}&";
+        }
+        $content .= "key=".config::KEY;
+
+        return strtoupper(md5($content));
+    }
+
+    public function add($card_no,$card_type,$amount,$input)
+    {
+        $params = $this->req_params($card_no,$card_type,$amount,$input);
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+
+        $resp = http_request(config::ORDER_URL,$params,'POST',false, config::ExtHeaders);
+        if($resp === false) {
+            return [false,'系统错误'];
+        }
+        else
+        {
+            Log::record($resp,Log::DEBUG);
+            $resp = json_decode($resp,true);
+            if($resp['code'] == 200) {
+                return [true,$resp['msg']];
+            }
+            else {
+                return [false,$resp['msg']];
+            }
+        }
+    }
+}

+ 24 - 0
helper/refill/bdt/RefillPhone.php

@@ -0,0 +1,24 @@
+<?php
+
+
+namespace refill\bdt;
+
+
+use refill\IRefillPhone;
+
+class RefillPhone extends IRefillPhone
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    public function add($card_no,$card_type,$amount,$input)
+    {
+        return [false,'No Implement'];
+    }
+    public function query($refill_info)
+    {
+        return [false,'No Implement'];
+    }
+}

+ 17 - 0
helper/refill/bdt/config.php

@@ -0,0 +1,17 @@
+<?php
+
+
+namespace refill\bdt;
+
+
+class config
+{
+    const ORDER_URL = 'http://137.220.129.53/backend/pay/api/order/createApi';
+
+    const KEY = 'CAL9MNU0819HAB7RL6X5ASK0D32G4018';
+    const CardOwnerAccount = 'stanley';
+
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/refill_bdt.php";
+    const ExtHeaders = ['Content-Type: application/x-www-form-urlencoded'];
+    const API_IP = NET_IP;
+}

+ 7 - 0
mobile/refill_bdt.php

@@ -0,0 +1,7 @@
+<?php
+
+require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
+
+refill\RefillFactory::instance()->notify('bdt',$_POST);
+
+echo ('success');