Browse Source

douxun_copy

xiaoyu 2 years ago
parent
commit
4369879b8e

+ 46 - 0
data/config/xyz/refill.ini.php

@@ -7649,6 +7649,51 @@ $miaoxt_tax_copy_phone = ['name' => 'miaoxt_tax_copy', 'store_id' => 283, 'quali
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$douxun_copy_phone = ['name' => 'douxun_copy', 'store_id' => 284, 'qualitys' => '2',
+    'amount' => [
+//        10 => [
+//            ['goods_id' => 8357, 'price' => 10.01, 'quality' => 2, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 8357, 'price' => 10.01, 'quality' => 2, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 8357, 'price' => 10.01, 'quality' => 2, 'card_type' => 'chinatelecom']
+//        ],
+//        20 => [
+//            ['goods_id' => 8358, 'price' => 20.02, 'quality' => 2, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 8358, 'price' => 20.02, 'quality' => 2, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 8358, 'price' => 20.02, 'quality' => 2, 'card_type' => 'chinatelecom']
+//        ],
+//        30 => [
+//            ['goods_id' => 8359, 'price' => 30.03, 'quality' => 2, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 8359, 'price' => 30.03, 'quality' => 2, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 8359, 'price' => 30.03, 'quality' => 2, 'card_type' => 'chinatelecom']
+//        ],
+        50 => [
+            ['goods_id' => 8360, 'price' => 51.75, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8360, 'price' => 51.45, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 8360, 'price' => 51.5, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        100 => [
+            ['goods_id' => 8361, 'price' => 102.85, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8361, 'price' => 102.9, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 8361, 'price' => 103.7, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        200 => [
+            ['goods_id' => 8362, 'price' => 205.7, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8362, 'price' => 205.8, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 8362, 'price' => 206, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        300 => [
+            ['goods_id' => 8363, 'price' => 308.55, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8363, 'price' => 308.7, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 8363, 'price' => 309, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        500 => [
+            ['goods_id' => 8364, 'price' => 514.25, 'quality' => 2, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 8364, 'price' => 500.5, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 8364, 'price' => 515, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -7888,6 +7933,7 @@ $phone_providers = [
     ['name' => 'yuewen_fs_gd', 'cfg' => $yuewen_fs_gd_phone],
     ['name' => 'douxun_sec', 'cfg' => $douxun_sec_phone],
     ['name' => 'miaoxt_tax_copy', 'cfg' => $miaoxt_tax_copy_phone],
+    ['name' => 'douxun_copy', 'cfg' => $douxun_copy_phone],
 
 ];
 $config['phone_providers'] = $phone_providers;

+ 45 - 0
helper/refill/api/xyz/douxun_copy/RefillCallBack.php

@@ -0,0 +1,45 @@
+<?php
+namespace refill\douxun_copy;
+
+require_once(BASE_HELPER_RAPI_PATH . '/douxun_copy/config.php');
+
+use refill;
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $sign = $this->sign($params);
+        if ($params['head']['chargeSign'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private function sign($params)
+    {
+        $content = config::custInteId . $params['head']['echo'] . config::KEY . $params['head']['timestamp'];
+        return base64_encode(md5($content, true));
+    }
+
+    public function notify($params)
+    {
+        $item = $params['body']['item'];
+        $status = $item['result'];
+        $order_sn = $item['orderId'];
+        $order_info = Model('vr_order')->getOrderInfoForNotify(['order_sn' => $order_sn]);
+        if (empty($order_info)) {
+            return [false, false, false,false];
+        }
+
+        $order_id = $order_info['order_id'];
+        if ($status === '0000') {
+            $data['official_sn'] = strtolower($item['operatorNo']) == 'null' ? '' : $item['operatorNo'];
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false,true];
+        }
+        else {
+            return [$order_id, false, true,true];
+        }
+    }
+}

+ 188 - 0
helper/refill/api/xyz/douxun_copy/RefillPhone.php

@@ -0,0 +1,188 @@
+<?php
+namespace refill\douxun_copy;
+
+require_once(BASE_HELPER_RAPI_PATH . '/douxun_copy/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)
+    {
+        $head['custInteId'] = config::custInteId;
+        $head['orderId'] = $order_sn;
+        $head['orderType'] = 1;
+        $head['echo'] = rand(100000,999999);
+        $head['timestamp'] = date("YmdHis");
+        $head['version'] = 1;
+
+        $params['packCode'] = config::PRODUCT[$card_type][$amount];
+        $params['mobile'] = $phone;
+        $params['effectType'] = 1;
+        $params['mobileOper'] = config::operator[$card_type];
+        return [$head,$params];
+    }
+
+    public function add($card_no, $card_type, $amount, $params, &$net_errno = 0)
+    {
+        $order_sn = $params['order_sn'];
+        [$head,$params] = $this->req_params($card_no, $card_type, $amount, $order_sn);
+        $sign = $this->sign($head);
+        $head['chargeSign'] = $sign;
+
+        $data = [
+            'head' => $head,
+            'body' => [
+                'item' => $params
+            ]
+        ];
+        $xmlData = $this->toXmlData($data);
+
+        $resp = http_post_data(config::ORDER_URL, $xmlData, config::ExtHeaders, $net_errno);
+
+        if (empty($resp)) {
+            return [false, '网络错误', true];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = refill\util::xmlToArray($resp);
+            if (empty($resp)) {
+                return [false, '网络错误', true];
+            } elseif ($resp['result'] === '0000') {
+                return [true, '', false];
+            } else {
+                return [false, $resp['desc'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        if (time() - $refill_info['commit_time'] > 86400*30) {
+            return [false, '时效已过'];
+        }
+        $head['custInteId'] = config::custInteId;
+        $head['echo'] = rand(100000,999999);
+        $head['timestamp'] = date("YmdHis");
+        $head['version'] = 1;
+        $content = $head['custInteId'] . config::KEY . $head['echo'] . $head['timestamp'];
+        $head['chargeSign'] = base64_encode(md5($content, true));
+
+        $params['orderIds'] = $refill_info['order_sn'];
+        $data = [
+            'head' => $head,
+            'body' => [
+                'item' => $params
+            ]
+        ];
+        $xmlData = $this->toXmlData($data);
+        $resp = http_post_data(config::QUERY_URL, $xmlData, config::ExtHeaders);
+
+        if (empty($resp)) {
+            return [false, '网络错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = refill\util::xmlToArray($resp);
+            if (empty($resp)) {
+                return [false, '网络错误'];
+            }
+            elseif ($resp['head']['result'] === '0000')
+            {
+                $item = $resp['body']['item'];
+                $status = $item['state'];
+
+                if ($status === '1') {
+                    $order_state = ORDER_STATE_SUCCESS;
+                    $updata['official_sn'] = $item['operatorNo'];
+                    Model('refill_order')->edit($refill_info['order_id'], $updata);
+                } elseif ($status === '2') {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif ($status === '0') {
+                    $order_state = ORDER_STATE_SEND;
+                } elseif ($status === '-1' && (time() - $refill_info['commit_time'] > 600)) {
+                    $order_state = ORDER_STATE_NOEXIST;
+                } else {
+                    return [false, $item['desc']];
+                }
+
+                return [true, $order_state];
+            }
+            else {
+                return [false, $resp['head']['desc']];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $head['custInteId'] = config::custInteId;
+        $head['echo'] = rand(100000,999999);
+        $head['timestamp'] = date("YmdHis");
+        $head['version'] = 1;
+
+        $content = $head['custInteId'] . config::KEY . $head['echo'] . $head['timestamp'];
+        $head['chargeSign'] = base64_encode(md5($content, true));
+
+        $data = [
+            'head' => $head,
+        ];
+        $xmlData = $this->toXmlData($data);
+        $resp = http_post_data(config::BALANCE_URL, $xmlData, config::ExtHeaders);
+
+        if (empty($resp)) {
+            return [false, '网络错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = refill\util::xmlToArray($resp);
+            if (empty($resp)) {
+                return [false, '网络错误', true];
+            } elseif ($resp['result'] === '0000') {
+                return [true, $resp['balance'], false];
+            } else {
+                return [false, $resp['desc'], false];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $content = $params['custInteId'] . $params['orderId'] . config::KEY. $params['echo'] . $params['timestamp'];
+        return base64_encode(md5($content, true));
+    }
+
+    private function toXmlData($data)
+    {
+        return $this->xml_encode($data);
+    }
+
+    private function xml_encode($data, $encoding='utf-8') {
+        $xml = '<?xml version="1.0" encoding="' . $encoding . '"?>';
+        $xml .= '<request>';
+        $xml .= $this->data_to_xml($data);
+        $xml .= '</request>';
+        return $xml;
+    }
+
+    private function data_to_xml($data) {
+
+        $xml = '';
+        foreach ($data as $key => $val) {
+            is_numeric($key) && $key = "item id=\"$key\"";
+            $xml    .=  "<$key>";
+            $xml    .=  ( is_array($val) || is_object($val)) ? $this->data_to_xml($val) : $val;
+            list($key, ) = explode(' ', $key);
+            $xml    .=  "</$key>";
+        }
+        return $xml;
+    }
+}

+ 6 - 0
helper/refill/api/xyz/douxun_copy/api.txt

@@ -0,0 +1,6 @@
+北京趣带娃:
+后台地址:http://b.juhemall.cn/
+账户:BJQDWTC
+密码:12345678
+ID:BJQDWTC
+密钥:JK-BJQDWTC

+ 54 - 0
helper/refill/api/xyz/douxun_copy/config.php

@@ -0,0 +1,54 @@
+<?php
+namespace refill\douxun_copy;
+
+use mtopcard;
+class config
+{
+    const ORDER_URL = 'http://bapi.juhemall.cn/order.action';
+    const QUERY_URL= 'http://bapi.juhemall.cn/queryOrder.action';
+    const BALANCE_URL = 'http://bapi.juhemall.cn/balance.action';
+
+    const custInteId = 'BJQDWTC';
+    const KEY = 'JK-BJQDWTC';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_douxun.php";
+    const ExtHeaders = ['Content-Type:text/xml; charset=utf-8'];
+
+    const operator = [
+        mtopcard\ChinaMobileCard  => 1,
+        mtopcard\ChinaUnicomCard  => 2,
+        mtopcard\ChinaTelecomCard => 3
+    ];
+    const PRODUCT = [
+        mtopcard\ChinaMobileCard => [
+            10  => 400010,
+            20  => 400020,
+            30  => 400030,
+            50  => 400050,
+            100 => 400100,
+            200 => 400200,
+            300 => 400300,
+            500 => 400500
+        ],
+        mtopcard\ChinaUnicomCard => [
+            10  => 100010,
+            20  => 100020,
+            30  => 100030,
+            50  => 100050,
+            100 => 100100,
+            200 => 100200,
+            300 => 100300,
+            500 => 100500
+        ],
+        mtopcard\ChinaTelecomCard => [
+            10  => 400010,
+            20  => 400020,
+            30  => 400030,
+            50  => 400050,
+            100 => 400100,
+            200 => 400200,
+            300 => 400300,
+            500 => 400500
+        ],
+    ];
+}
+

BIN
helper/refill/api/xyz/douxun_copy/新豆讯话费网关平台接口文档V2.1.doc


BIN
helper/refill/api/xyz/douxun_copy/话费产品编码.xls