浏览代码

yuanmai wei ceshi

xiaoyu 3 年之前
父节点
当前提交
54b077c9f3

+ 51 - 0
helper/refill/api/xyz/yuanmai/RefillCallBack.php

@@ -0,0 +1,51 @@
+<?php
+
+
+namespace refill\yuanmai;
+
+require_once(BASE_HELPER_RAPI_PATH . '/yuanmai/config.php');
+
+
+use refill;
+use Log;
+
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $sign = $this->sign($params);
+        if ($params['sign'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private function sign($params)
+    {
+        $key = config::KEY;
+        $content = "orderid={$params['orderid']}&status={$params['status']}&ordermoney={$params['ordermoney']}&dealerkey={$key}";
+        return md5($content);
+    }
+
+    public function notify($params)
+    {
+        $status = intval($params['status']);
+        $order_sn = $params['orderid'];
+        $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['spsno']) == 'null' ? '' : $params['spsno'];
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false, true];
+        } elseif ($status === 4) {
+            return [$order_id, false, true, true];
+        } else {
+            return [$order_id, false, false, false];
+        }
+    }
+}

+ 110 - 0
helper/refill/api/xyz/yuanmai/RefillPhone.php

@@ -0,0 +1,110 @@
+<?php
+
+namespace refill\yuanmai;
+
+require_once(BASE_HELPER_RAPI_PATH . '/yuanmai/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 $card_type, int $amount, string $order_sn)
+    {
+        $params['ispid'] = config::operator[$card_type];
+        $params['amount'] = $amount;
+        $params['dealerid'] = config::USER_ID;
+        $params['orderid'] = $order_sn;
+        $params['photonum'] = $phone;
+        $params['backurl'] = config::NOTIFY_URL;
+        $params['ordertime'] = date("YmdHis");
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
+    {
+        $order_sn = $params['order_sn'];
+        $params = $this->req_params($card_no, $card_type, $amount, $order_sn);
+
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+
+        $resp = http_request(config::ORDER_URL, $params, 'POST', false, [], $net_errno);
+
+        if (empty($resp)) {
+            return [false, '网络错误', true];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = $this->xmlToArray($resp);
+            if (empty($resp)) {
+                return [false, '网络错误', true];
+            }
+            $resultno = $resp['resultno'];
+            if ($resultno === '0000') {
+                return [true, $resp['serialid'], false];
+            } else {
+                return [false, $resultno, false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['dealerid'] = config::USER_ID;
+        $params['orderid'] = $refill_info['order_sn'];
+        $content = "dealerid={$params['dealerid']}&orderid={$params['orderid']}&dealerkey=".config::KEY;
+        $params['sign'] = md5($content);
+        $resp = http_request(config::QUERY_URL, $params, 'POST');
+
+        if (empty($resp)) {
+            return [false, '网络错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = $this->xmlToArray($resp);
+            if (empty($resp)) {
+                return [false, '网络错误'];
+            }
+            $resultno = intval($resp['resultno']);
+            if ($resultno === 2) {
+                $order_state = ORDER_STATE_SUCCESS;
+                $updata['official_sn'] = $resp['spsno'];
+                Model('refill_order')->edit($refill_info['order_id'], $updata);
+            } elseif ($resultno === 4) {
+                $order_state = ORDER_STATE_CANCEL;
+            } elseif ($resultno === 1) {
+                $order_state = ORDER_STATE_SEND;
+            } else {
+                return [false, $resultno];
+            }
+            return [true, $order_state];
+        }
+    }
+
+    private function sign($params)
+    {
+        $userid = config::USER_ID;
+        $key = config::KEY;
+        $content = "ispid={$params['ispid']}&amount={$params['amount']}&dealerid={$userid}&orderid={$params['orderid']}&photonum={$params['photonum']}&";
+        $content .= "ordertime={$params['ordertime']}&mark=&dealerkey={$key}";
+        return md5($content);
+    }
+
+    public 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;
+    }
+}

+ 20 - 0
helper/refill/api/xyz/yuanmai/config.php

@@ -0,0 +1,20 @@
+<?php
+
+
+namespace refill\yuanmai;
+
+use mtopcard;
+class config
+{
+    //985 2
+    const ORDER_URL = 'http://121.89.243.74:9086/onlinepay.do';
+    const QUERY_URL= 'http://121.89.243.74:9086/searchpay.do';
+    const USER_ID= '10002504';
+    const KEY = 'HdxxWScBF6aYykbB33r8S5CQcS5myYZZ';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/refill_yuanmai.php";
+    const operator = [
+        mtopcard\ChinaMobileCard  => 1,
+        mtopcard\ChinaUnicomCard  => 0,
+        mtopcard\ChinaTelecomCard => 2
+    ];
+}

二进制
helper/refill/api/xyz/yuanmai/杭州元迈话费充值接口说明_v2.4.doc