xiaoyu 3 years atrás
parent
commit
cead0a8a74

+ 48 - 0
helper/refill/api/xyz/dongyefs/RefillCallBack.php

@@ -0,0 +1,48 @@
+<?php
+namespace refill\dongyefs;
+
+require_once(BASE_HELPER_RAPI_PATH . '/dongyefs/config.php');
+
+use refill;
+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)
+    {
+        $userid = config::USER_ID;
+        $key = config::KEY;
+        $content = "userid={$userid}&orderid={$params['orderid']}&sporderid={$params['sporderid']}&merchantsubmittime={$params['merchantsubmittime']}";
+        $content .= "&resultno={$params['resultno']}&key={$key}";
+        return strtoupper(md5($content));
+    }
+
+    public function notify($params)
+    {
+        $status = intval($params['resultno']);
+        $order_sn = $params['sporderid'];
+        $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 === 1) {
+            $data['official_sn'] = strtolower($params['remark1']) == 'null' ? '' : $params['remark1'];
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false, true];
+        } elseif ($status === 9) {
+            return [$order_id, false, true, true];
+        } else {
+            return [$order_id, false, false, false];
+        }
+    }
+}

+ 174 - 0
helper/refill/api/xyz/dongyefs/RefillPhone.php

@@ -0,0 +1,174 @@
+<?php
+
+namespace refill\dongyefs;
+
+require_once(BASE_HELPER_RAPI_PATH . '/dongyefs/config.php');
+
+use refill;
+use Log;
+
+class RefillPhone extends refill\IRefillPhone
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    public function goods($quality,int $amount,int $card_type,$regin_no,$other)
+    {
+        [$goods_id, $price] = parent::goods($quality,$amount,$card_type,$regin_no,$other);
+        if($goods_id <= 0) return [0,0];
+        $key = "{$amount}-{$regin_no}";
+        $price = config::Price[$key];
+        if(empty($price)) {
+            Log::record("channel cannot find price where name={$this->mName}, goods_id = {$goods_id} card_type={$card_type} amount={$amount} regin_no={$regin_no}",Log::ERR);
+            return [0,0];
+        } else {
+            return [$goods_id,ncPriceFormat($price)];
+        }
+    }
+
+    private function req_params(int $phone, int $amount, $card_type, string $order_sn, $regin_no)
+    {
+        $params['userid'] = config::USER_ID;
+        $params['productid'] = config::product_id[$card_type][$regin_no][$amount];
+        $params['price'] = $amount;
+        $params['num'] = 1;
+        $params['mobile'] = $phone;
+        $params['spordertime'] = date("YmdHis");
+        $params['sporderid'] = $order_sn;
+        $params['back_url'] = config::NOTIFY_URL;
+        $params['paytype'] = config::operator[$card_type];
+
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
+    {
+        $order_sn = $params['order_sn'];
+        $regin_no = $input['regin_no'] ?? -1;
+        if($regin_no <= 0) {
+            return [false, '省份获取错误', false];
+        }
+        $params = $this->req_params($card_no, $amount, $card_type, $order_sn, $regin_no);
+        if(empty($params['productid'])) {
+            return [false, '商品编号错误', false];
+        }
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+
+        $resp = http_request(config::ORDER_URL, $params, 'POST', false, config::ExtHeaders, $net_errno);
+        if (empty($resp)) {
+            return [false, '网络错误', true];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = $this->xmlToArray($resp);
+
+            if (empty($resp) || !isset($resp['resultno'])) {
+                return [false, '网络错误', true];
+            }
+
+            $resultno = $resp['resultno'];
+            if (in_array($resultno, ['0', '2'], true)) {
+                return [true, $resp['orderid'], false];
+            } elseif (in_array($resultno, config::ERR_NOS, true)) {
+                return [false, $resultno, false];
+            } elseif ($resultno === '9999' || $resultno === '5006') {
+                $net_errno = "HTTP-{$resultno}";
+                return [false, $resultno, true];
+            } else {
+                //未知结果码
+                $err = 998;
+                $net_errno = "HTTP-{$err}";
+                return [false, $resultno, true];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['userid'] = config::USER_ID;
+        $params['sporderid'] = $refill_info['order_sn'];
+        $key = config::KEY;
+        $content = "userid={$params['userid']}&sporderid={$params['sporderid']}&key={$key}";
+        $params['sign'] = md5($content);
+
+        $resp = http_request(config::QUERY_URL, $params, 'POST', false, config::ExtHeaders);
+
+        if (empty($resp)) {
+            return [false, '网络错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = $this->xmlToArray($resp);
+            if (empty($resp))
+            {
+                return [false, '网络错误'];
+            }
+            else
+            {
+                $resultno = $resp['resultno'];
+                if ($resultno === '1') {
+                    $updata['official_sn'] = $resp['remark1'];
+                    Model('refill_order')->edit($refill_info['order_id'], $updata);
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($resultno === '9') {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif (in_array($resultno, ['0','2'], true)) {
+                    $order_state = ORDER_STATE_SEND;
+                } elseif ($resultno === '5007' && (time() - $refill_info['commit_time'] > 600)) {
+                    $order_state = ORDER_STATE_NOEXIST;
+                } else {
+                    return [false, $resultno];
+                }
+
+                return [true, $order_state];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $params['userid'] = config::USER_ID;
+        $key = config::KEY;
+        $content = "userid={$params['userid']}&key={$key}";
+        $params['sign'] = md5($content);
+
+        $resp = http_request(config::BALANCE_URL, $params, 'POST', false, config::ExtHeaders);
+
+        if (empty($resp)) {
+            return [false, '网络错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = $this->xmlToArray($resp);
+            if (empty($resp)) {
+                return [false, '网络错误'];
+            } elseif ($resp['resultno'] === '1') {
+                return [true, $resp['balance']];
+            } else {
+                return [false, $resp['resultno']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $userid = config::USER_ID;
+        $key = config::KEY;
+        $content = "userid={$userid}&productid={$params['productid']}&price={$params['price']}&num={$params['num']}&mobile={$params['mobile']}&spordertime={$params['spordertime']}";
+        $content .= "&sporderid={$params['sporderid']}&key={$key}";
+        return md5($content);
+    }
+
+    public function xmlToArray($xml)
+    {
+        $xml = mb_convert_encoding($xml,"UTF-8","gb2312");
+        $xml = str_replace('encoding="gb2312"', "encoding='UTF-8'", $xml);
+        return refill\util::xmlToArray($xml);
+    }
+}

+ 8 - 0
helper/refill/api/xyz/dongyefs/api.txt

@@ -0,0 +1,8 @@
+用户编号:10003125
+账户:bjgyfs
+密码:sup123456
+秘钥:82dkkhEaR6GhchQkhS5SiffF2w8yX4wQ
+下单地址 :http://8.134.53.93:9086/onlinepay.do
+查单地址 :http://8.134.53.93:9086/searchpay.do
+查询余额地址 :http://8.134.53.93:9086/searchbalance.do
+后台地址:http://8.134.53.93:7080

+ 80 - 0
helper/refill/api/xyz/dongyefs/config.php

@@ -0,0 +1,80 @@
+<?php
+namespace refill\dongyefs;
+
+use mtopcard;
+class config
+{
+    const ORDER_URL = 'http://8.134.53.93:9086/onlinepay.do';
+    const QUERY_URL= 'http://8.134.53.93:9086/searchpay.do';
+    const BALANCE_URL = 'http://8.134.53.93:9086/searchbalance.do';
+
+    const USER_ID= '10003125';
+    const KEY = '82dkkhEaR6GhchQkhS5SiffF2w8yX4wQ';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_dongyefs.php";
+    const operator = [
+        mtopcard\ChinaMobileCard  => 'yd',
+        mtopcard\ChinaUnicomCard  => 'lt',
+        mtopcard\ChinaTelecomCard => 'dx'
+    ];
+    const ERR_NOS = [
+        '5001','5002','5003','5004','5005','5008','5009','5010','5011','5012'
+    ];
+    const ExtHeaders = ['Content-Type:application/x-www-form-urlencoded;'];
+    const product_id = [
+        mtopcard\ChinaMobileCard => [
+            6 => [
+                10 => '30000005109', 20 => '30000005110', 30 => '30000005111', 50 => '30000005112',
+                100 => '30000005113', 200 => '30000005114', 300 => '30000005115', 500 => '30000005116'
+            ],//辽宁
+            7 => [
+                30 => '30000005408', 50 => '30000005409',
+                100 => '30000005410', 200 => '30000005411', 300 => '30000005412', 500 => '30000005413'
+            ],//吉林
+            9 => [
+                10 => '30000005318', 20 => '30000005319', 30 => '30000005320', 50 => '30000005321',
+                100 => '30000005322', 200 => '30000005323', 300 => '30000005324', 500 => '30000005325'
+            ],//上海
+            13 => [
+                10 => '30000005710', 20 => '30000005711', 30 => '30000005712', 50 => '30000005713',
+                100 => '30000005714', 200 => '30000005715', 300 => '30000005716', 500 => '30000005717'
+            ],//福建
+            19 => [
+                10 => '30000005117', 20 => '30000005118', 30 => '30000005119', 50 => '30000005120',
+                100 => '30000005121', 200 => '30000005122', 300 => '30000005123', 500 => '30000005124'
+            ],//广东
+            29 => [
+                10 => '30000005326', 20 => '30000005327', 30 => '30000005328', 50 => '30000005329',
+                100 => '30000005330', 200 => '30000005331', 300 => '30000005332', 500 => '30000005333'
+            ],//青海
+        ],
+        mtopcard\ChinaTelecomCard => [
+            12 => [
+                10 => '30000005747', 20 => '30000005748', 30 => '30000005749', 50 => '30000005750',
+                100 => '30000005751', 200 => '30000005752', 300 => '30000005753', 500 => '30000005754'
+            ],//安徽
+            16 => [
+                10 => '30000005763', 20 => '30000005764', 30 => '30000005765', 50 => '30000005766',
+                100 => '30000005767', 200 => '30000005768', 300 => '30000005769', 500 => '30000005770'
+            ],//河南
+            18 => [
+                10 => '30000005755', 20 => '30000005756', 30 => '30000005757', 50 => '30000005758',
+                100 => '30000005759', 200 => '30000005760', 300 => '30000005761', 500 => '30000005762'
+            ],//湖南
+        ]
+    ];
+    //key格式 卡类型-面值-regin_no
+    const Price = [
+        //移动
+        "4-10-6" => 9.7, "4-20-6" => 19.4, "4-30-6" => 29.1, "4-50-6" => 48.5, "4-100-6" => 97, "4-200-6" => 194, "4-300-6" => 291, "4-500-6" => 485,//辽宁 6
+        "4-30-7" => 29.73, "4-50-7" => 49.55, "4-100-7" => 99.1, "4-200-7" => 198.2, "4-300-7" => 297.3, "4-500-7" => 495.5,//吉林 7
+        "4-10-9" => 9.91, "4-20-9" => 19.82, "4-30-9" => 29.73, "4-50-9" => 49.55, "4-100-9" => 99.1, "4-200-9" => 198.2, "4-300-9" => 297.3, "4-500-9" => 495.5,//上海 9
+        "4-10-13" => 9.9, "4-20-13" => 19.8, "4-30-13" => 29.7, "4-50-13" => 49.5, "4-100-13" => 99, "4-200-13" => 198, "4-300-13" => 297, "4-500-13" => 495,//福建 13
+        "4-10-19" => 9.95, "4-20-19" => 19.9, "4-30-19" => 29.85, "4-50-19" => 49.75, "4-100-19" => 99.5, "4-200-19" => 199, "4-300-19" => 298.5, "4-500-19" => 497.5,//广东 19
+        "4-10-29" => 9.8, "4-20-29" => 19.6, "4-30-29" => 29.4, "4-50-29" => 49, "4-100-29" => 98, "4-200-29" => 196, "4-300-29" => 294, "4-500-29" => 490,//青海 29
+
+        //电信
+        "6-10-12" => 10.065, "6-20-12" => 20.13, "6-30-12" => 30.195, "6-50-12" => 50.225, "6-100-12" => 100.45, "6-200-12" => 200.9, "6-300-12" => 301.35, "6-500-12" => 502.25,//安徽 12
+        "6-10-16" => 10.065, "6-20-16" => 20.13, "6-30-16" => 30.195, "6-50-16" => 50.225, "6-100-16" => 100.45, "6-200-16" => 200.9, "6-300-16" => 301.35, "6-500-16" => 502.25,//河南 16
+        "6-10-18" => 10.065, "6-20-18" => 20.13, "6-30-18" => 30.195, "6-50-18" => 50.225, "6-100-18" => 100.45, "6-200-18" => 200.9, "6-300-18" => 301.35, "6-500-18" => 502.25,//湖南 18
+    ];
+}

BIN
helper/refill/api/xyz/dongyefs/商品编码.xls


BIN
helper/refill/api/xyz/dongyefs/通信充值接口.doc


+ 4 - 0
mobile/callback/refill_dongyefs.php

@@ -0,0 +1,4 @@
+<?php
+
+refill\util::push_notify('dongyefs',$_POST);
+echo ('OK');