Browse Source

xiaoniu_hf

xiaoyu 3 years ago
parent
commit
6b9e733c86

+ 16 - 1
data/config/win/refill.ini.php

@@ -2828,6 +2828,20 @@ $dinghui_phone = ['name' => 'dinghui', 'store_id' => 140, 'qualitys' => '5',
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$xiaoniu_hf_phone = ['name' => 'xiaoniu_hf', 'store_id' => 141, 'qualitys' => '2',
+    'amount' => [
+        10 => [['goods_id' => 7211, 'price' => 9.7,  'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        20 => [['goods_id' => 7212, 'price' => 19.4, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        30 => [['goods_id' => 7213, 'price' => 29.1, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        50 => [['goods_id' => 7214, 'price' => 48.5, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        100 => [['goods_id' => 7215, 'price' => 97, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        200 => [['goods_id' => 7216, 'price' => 194, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        300 => [['goods_id' => 7217, 'price' => 291, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        500 => [['goods_id' => 7218, 'price' => 485, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -2934,7 +2948,8 @@ $phone_providers = [
     ['name' => 'xingzy_normal', 'cfg' => $xingzy_normal_phone],
     ['name' => 'pushang', 'cfg' => $pushang_phone],
     ['name' => 'huafutong', 'cfg' => $huafutong_phone],
-    ['name' => 'dinghui', 'cfg' => $dinghui_phone]
+    ['name' => 'dinghui', 'cfg' => $dinghui_phone],
+    ['name' => 'xiaoniu_hf', 'cfg' => $xiaoniu_hf_phone]
 ];
 $config['phone_providers'] = $phone_providers;
 

+ 16 - 1
data/config/xyz/refill.ini.php

@@ -2828,6 +2828,20 @@ $dinghui_phone = ['name' => 'dinghui', 'store_id' => 140, 'qualitys' => '5',
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$xiaoniu_hf_phone = ['name' => 'xiaoniu_hf', 'store_id' => 141, 'qualitys' => '2',
+    'amount' => [
+        10 => [['goods_id' => 7211, 'price' => 9.7,  'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        20 => [['goods_id' => 7212, 'price' => 19.4, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        30 => [['goods_id' => 7213, 'price' => 29.1, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        50 => [['goods_id' => 7214, 'price' => 48.5, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        100 => [['goods_id' => 7215, 'price' => 97, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        200 => [['goods_id' => 7216, 'price' => 194, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        300 => [['goods_id' => 7217, 'price' => 291, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        500 => [['goods_id' => 7218, 'price' => 485, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -2934,7 +2948,8 @@ $phone_providers = [
     ['name' => 'xingzy_normal', 'cfg' => $xingzy_normal_phone],
     ['name' => 'pushang', 'cfg' => $pushang_phone],
     ['name' => 'huafutong', 'cfg' => $huafutong_phone],
-    ['name' => 'dinghui', 'cfg' => $dinghui_phone]
+    ['name' => 'dinghui', 'cfg' => $dinghui_phone],
+    ['name' => 'xiaoniu_hf', 'cfg' => $xiaoniu_hf_phone]
 ];
 $config['phone_providers'] = $phone_providers;
 

+ 16 - 1
data/config/xyzadm/refill.ini.php

@@ -2828,6 +2828,20 @@ $dinghui_phone = ['name' => 'dinghui', 'store_id' => 140, 'qualitys' => '5',
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$xiaoniu_hf_phone = ['name' => 'xiaoniu_hf', 'store_id' => 141, 'qualitys' => '2',
+    'amount' => [
+        10 => [['goods_id' => 7211, 'price' => 9.7,  'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        20 => [['goods_id' => 7212, 'price' => 19.4, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        30 => [['goods_id' => 7213, 'price' => 29.1, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        50 => [['goods_id' => 7214, 'price' => 48.5, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        100 => [['goods_id' => 7215, 'price' => 97, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        200 => [['goods_id' => 7216, 'price' => 194, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        300 => [['goods_id' => 7217, 'price' => 291, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        500 => [['goods_id' => 7218, 'price' => 485, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -2934,7 +2948,8 @@ $phone_providers = [
     ['name' => 'xingzy_normal', 'cfg' => $xingzy_normal_phone],
     ['name' => 'pushang', 'cfg' => $pushang_phone],
     ['name' => 'huafutong', 'cfg' => $huafutong_phone],
-    ['name' => 'dinghui', 'cfg' => $dinghui_phone]
+    ['name' => 'dinghui', 'cfg' => $dinghui_phone],
+    ['name' => 'xiaoniu_hf', 'cfg' => $xiaoniu_hf_phone]
 ];
 $config['phone_providers'] = $phone_providers;
 

+ 2 - 2
helper/refill/api/xyz/xiaoniu/RefillOil.php

@@ -73,7 +73,7 @@ class RefillOil extends refill\IRefillOil
             if (empty($resp)) {
                 return [false, '系统错误'];
             }
-            elseif ($resp['code'] == '0')
+            elseif ($resp['code'] === '0')
             {
                 $status = intval($resp['status']);
                 if ($status === 1) {
@@ -113,7 +113,7 @@ class RefillOil extends refill\IRefillOil
             if (empty($resp)) {
                 return [false, '系统错误'];
             }
-            elseif ($resp['code'] == '0')
+            elseif ($resp['code'] === '0')
             {
                 return [true, $resp['balance']];
             }

+ 69 - 0
helper/refill/api/xyz/xiaoniu_hf/RefillCallBack.php

@@ -0,0 +1,69 @@
+<?php
+namespace refill\xiaoniu_hf;
+require_once(BASE_HELPER_RAPI_PATH . '/xiaoniu_hf/config.php');
+
+use Log;
+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;
+        }
+    }
+
+    protected 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)
+    {
+        $content = '';
+        ksort($params);
+        foreach ($params as $key => $val){
+            if(false === $this->check_empty($val)) {
+                $content .= "{$key}={$val}&";
+            }
+        }
+        $content .= "key=".config::Key;
+
+        return md5($content);
+    }
+
+    //[$order_id, $success, $can_try, $need_handle]
+    public function notify($params)
+    {
+        $status = intval($params['status']);
+        $order_sn = $params['mOrderNo'];
+        $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) {
+            Model('refill_order')->edit($order_id, ['official_sn' => $params['content']]);
+            return [$order_id, true, false,true];
+        }
+        elseif ($status === 2) {
+            return [$order_id, false, true,true];
+        }
+        else {
+            return [$order_id, false, false,false];
+        }
+    }
+}

+ 136 - 0
helper/refill/api/xyz/xiaoniu_hf/RefillPhone.php

@@ -0,0 +1,136 @@
+<?php
+
+namespace refill\xiaoniu_hf;
+
+require_once(BASE_HELPER_RAPI_PATH . '/xiaoniu_hf/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, int $card_type, string $order_sn)
+    {
+        $params['mId'] = config::MCH_ID;
+        $params['mOrderNo'] = $order_sn;
+        $params['account'] = $phone;
+        $params['subclassType'] = 'QWT';
+        $params['faceAmount'] = $amount;
+        $params['notifyUrl'] = config::NOTIFY_URL;
+        $params['timestamp'] = date("YmdHis");
+
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
+    {
+        $params = $this->req_params($card_no, $amount, $card_type, $params['order_sn']);
+        $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 = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '系统错误', true];
+            } elseif ($resp['code'] === '0') {
+                return [true, $resp['orderNo'], false];
+            } else {
+                return [false, $resp['msg'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['mId'] = config::MCH_ID;
+        $params['mOrderNo'] = $refill_info['order_sn'];
+        $params['sign'] = $this->sign($params);
+
+        $resp = http_request(config::QUERY_URL, $params, 'POST', false, config::ExtHeaders);
+
+        if (empty($resp)) {
+            return [false, '系统错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '系统错误'];
+            }
+            elseif ($resp['code'] === '0')
+            {
+                $status = intval($resp['status']);
+                if ($status === 1) {
+                    $updata['official_sn'] = $resp['content'];
+                    Model('refill_order')->edit($refill_info['order_id'], $updata);
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($status === 2) {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif ($status === 3) {
+                    $order_state = ORDER_STATE_SEND;
+                } else {
+                    return [false, $status];
+                }
+                return [true, $order_state];
+            }
+            else {
+                return [false, $resp['msg']];
+            }
+
+        }
+    }
+
+    public function balance()
+    {
+        $params['mId'] = config::MCH_ID;
+        $params['sign'] = $this->sign($params);
+
+        $resp = http_request(config::BALANCE_URL, $params, 'POST', false, config::ExtHeaders);
+
+        if (empty($resp)) {
+            return [false, '系统错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '系统错误'];
+            }
+            elseif ($resp['code'] === '0')
+            {
+                return [true, $resp['balance']];
+            }
+            else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $content = '';
+        ksort($params);
+        foreach ($params as $key => $val){
+            if(false === $this->check_empty($val)) {
+                $content .= "{$key}={$val}&";
+            }
+        }
+        $content .= "key=".config::Key;
+
+        return md5($content);
+    }
+}

+ 14 - 0
helper/refill/api/xyz/xiaoniu_hf/config.php

@@ -0,0 +1,14 @@
+<?php
+namespace refill\xiaoniu_hf;
+
+class config
+{
+    const ORDER_URL = 'http://59.110.215.199/api/order/recharge';
+    const QUERY_URL = 'http://59.110.215.199/api/order/query';
+    const BALANCE_URL = 'http://59.110.215.199/api/merchant/query';
+
+    const MCH_ID = 'xn211018049';
+    const Key = 'db8b1fefa9b24317acb1972789616e10';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_xiaoniu_hf.php";
+    const ExtHeaders = ['Content-Type:application/x-www-form-urlencoded;charset=utf-8'];
+}

BIN
helper/refill/api/xyz/xiaoniu_hf/小牛对接文档.docx


+ 6 - 0
helper/refill/api/xyz/xiaoniu_hf/账号.txt

@@ -0,0 +1,6 @@
+http://59.110.215.199:9092
+账号:15811535608
+密码:123456
+
+商户号:xn211018049
+密钥:db8b1fefa9b24317acb1972789616e10

+ 4 - 0
mobile/callback/refill_xiaoniu_hf.php

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

+ 22 - 4
test/TestRefill.php

@@ -999,11 +999,15 @@ class TestRefill extends TestCase
 //        $resp = $providers->add(13699279618, 4, 100, ['order_sn' => $this->make_sn()]);
 //        $resp = $providers->query(['order_sn' => '68221631775122967358']);
 
-        $body = '{"phone":"13699279618","orderNo":"F2109161452121045530","status":"success","otherNo":"68221631775122967358","msg":"提交/充值成功","ext":"524501553021467113"}';
-        $params = json_decode($body, true);
+//        $body = '{"phone":"13699279618","orderNo":"F2109161452121045530","status":"success","otherNo":"68221631775122967358","msg":"提交/充值成功","ext":"524501553021467113"}';
+//        $params = json_decode($body, true);
         $providers = $this->getProvider('hangtong','RefillCallBack');
-        $ret = $providers->verify($params);
-        $resp = $providers->notify($params);
+//        $ret = $providers->verify($params);
+//        $resp = $providers->notify($params);
+
+        $body = '{"phone":"18651376439","orderNo":"F2110181020213141546","status":"fail","otherNo":"4185270687867621074422","msg":"提交/充值失败","ext":null}';
+        $inputs = json_decode($body,true) ?? [];
+            $resp = $providers->notify($inputs);
     }
 
     public function testJinfeng()
@@ -1191,6 +1195,20 @@ class TestRefill extends TestCase
         $data = $providers->notify($params);
     }
 
+    public function testXiaoniu_hf()
+    {
+//        $providers = $this->getProvider('xiaoniu_hf');
+//        $resp = $providers->balance();
+//        $resp = $providers->add(18500608333, 5, 30, ['order_sn' => $this->make_sn()]);
+//        $resp = $providers->query(['order_sn' => '64601634527198572270']);
+
+        $body = '{"content":"","realAmt":"0","status":"2","timestamp":"20211018112328","sign":"b69b420b0bfe950ea9f1d92fa1ed3b53","orderNo":"XN20211018112005318283580","mOrderNo":"64601634527198572270"}';
+        $params = json_decode($body, true);
+        $providers = $this->getProvider('xiaoniu_hf','RefillCallBack');
+        $ret = $providers->verify($params);
+        $data = $providers->notify($params);
+    }
+
     public function testAmingjd()
     {
 //        $providers = new refill\amingjd\RefillPhone([]);