Selaa lähdekoodia

add provider bjbnew

ayHaru 4 vuotta sitten
vanhempi
commit
a0ecfe1706

+ 53 - 0
helper/refill/bjbnew/RefillCallBack.php

@@ -0,0 +1,53 @@
+<?php
+
+
+namespace refill\bjbnew;
+
+require_once(BASE_HELPER_PATH . '/refill/bjbnew/config.php');
+
+
+use refill;
+
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $sign = $this->sign($params);
+        if ($params['verifystring'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private function sign($params)
+    {
+        $agentid = config::AGENT_ID;
+        $key = config::MerchantKey;
+        $content = "agentid={$agentid}&orderno={$params['orderno']}&orderstatus={$params['orderstatus']}&merchantKey={$key}";
+        return md5($content);
+    }
+
+    public function notify($params)
+    {
+        $status = intval($params['orderstatus']);
+        $order_sn = $params['orderno'];
+        $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'];
+        $data['official_sn'] = $params['supplierOrderNo'];
+        Model('refill_order')->edit($order_id, $data);
+
+        if ($status === 0014) {
+            return [$order_id, true, false,true];
+        }
+        elseif ($status === 0015) {
+            return [$order_id, false, true,true];
+        }
+        else {
+            return [$order_id, false, false,false];
+        }
+    }
+}

+ 101 - 0
helper/refill/bjbnew/RefillPhone.php

@@ -0,0 +1,101 @@
+<?php
+namespace refill\bjbnew;
+
+require_once(BASE_HELPER_PATH . '/refill/bjbnew/config.php');
+
+use refill;
+use Log;
+
+class RefillPhone extends refill\IRefillPhone
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    private function req_params(int $phone, int $amount ,string $order_sn)
+    {
+        $params['chargenumbertype'] = 1;
+        $params['agentid'] = config::AGENT_ID;
+        $params['returntype'] = 2;
+        $params['orderid'] = $order_sn;
+        $params['chargenumber'] = $phone;
+        $params['amountmoney'] = $amount;
+        $params['source'] = 2;
+        return $params;
+    }
+
+    public function add($card_no, $card_type,$amount,$params)
+    {
+        $order_sn = $params['order_sn'];
+        $params = $this->req_params($card_no,$amount,$order_sn);
+        $sign = $this->sign($params);
+        $params['verifystring'] = $sign;
+        $resp = http_request(config::PAY_PHONE_URL,$params,'GET');
+        if($resp === false) {
+            return [false,'系统错误'];
+        }
+        else
+        {
+            Log::record($resp,Log::DEBUG);
+            $resp = $this->xmlToArray($resp);
+            if($resp['resultno'] == 0000) {
+                return [true,$resp['orderno']];
+            }
+            else {
+                return [false,$resp['resultmessage']];
+            }
+        }
+    }
+    public function query($refill_info)
+    {
+        $params['orderid'] = $refill_info['order_sn'];
+        $params['agentid'] = config::AGENT_ID;
+        $params['returntype'] = 2;
+        $key = config::MerchantKey;
+        $content = "agentid={$params['agentid']}&returntype={$params['returntype']}&orderid={$params['orderid']}&merchantKey={$key}";
+        $params['verifystring'] = md5($content);
+        $resp = http_request(config::QUERY_URL,$params);
+        if($resp === false) {
+            return [false,'系统错误'];
+        }
+        else
+        {
+            Log::record($resp,Log::DEBUG);
+            $resp = $this->xmlToArray($resp);
+            $order_state = '';
+            if ($resp['resultno'] == 0014) {
+                $order_state = ORDER_STATE_SUCCESS;
+            } elseif ($resp['resultno'] == 0015) {
+                $order_state = ORDER_STATE_CANCEL;
+            } elseif ($resp['resultno'] == 0016){
+                $order_state = ORDER_STATE_SEND;
+            }
+            if (empty($order_state)) {
+                return [false, $resp['resultmessage']];
+            }
+            return [true, $order_state];
+        }
+    }
+
+    private function sign($params)
+    {
+        $key = config::MerchantKey;
+        $content = "chargenumbertype={$params['chargenumbertype ']}&agentid={$params['agentid']}&returntype={$params['returntype']}&orderid={$params['orderid']}";
+        $content .= "chargenumber={$params['chargenumber']}&amountmoney={$params['amountmoney']}&ispname={$params['ispname']}&source={$params['source']}&merchantKey={$key}";
+        return md5($content);
+    }
+
+    private function xmlToArray($xml)
+    {
+        //禁止引用外部xml实体
+        libxml_disable_entity_loader(true);
+
+        $xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
+
+        $val = json_decode(json_encode($xmlstring), true);
+
+        return $val;
+
+    }
+}

+ 14 - 0
helper/refill/bjbnew/config.php

@@ -0,0 +1,14 @@
+<?php
+
+
+namespace refill\bjbnew;
+
+
+class config
+{
+    const PAY_PHONE_URL = 'http://ip:8107/ MainServiceBusiness/SendPhoneChargeInfo';
+    const QUERY_URL= 'http:// ip:8107/MainServiceBusiness/GetOrderInfo';
+    const AGENT_ID= '13699279618';
+    const MerchantKey = 'bb2f4aa72e1181bd9c4cf2951b890f5b';
+    const API_IP = NET_IP;
+}