Explorar o código

速狐沃支付渠道

zb727 hai 1 ano
pai
achega
11c7cb72f1

+ 53 - 1
data/config/mh/refill.ini.php

@@ -122,9 +122,61 @@ $suhu_normal = ['name' => 'suhu_normal', 'store_id' => 379,'qualitys' => '1',
 
 
 
+$suhu_wozhifu = ['name' => 'suhu_wozhifu', 'store_id' => 380,'qualitys' => '1',
+    'amount' => [
+//        10 => [
+//            ['goods_id' => 8948, 'price' => 10.065, 'quality' => 1, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 8948, 'price' => 10.02, 'quality' => 1, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 8948, 'price' => 10, 'quality' => 1, 'card_type' => 'chinatelecom']
+//        ],
+//
+//        20 => [
+//            ['goods_id' => 8949, 'price' => 20.13, 'quality' => 1, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 8949, 'price' => 19.896, 'quality' => 1, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 8949, 'price' => 20, 'quality' => 1, 'card_type' => 'chinatelecom']
+//        ],
+//
+//        30 => [
+//            ['goods_id' => 8950, 'price' => 30.09, 'quality' => 1, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 8950, 'price' => 29.844, 'quality' => 1, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 8950, 'price' => 30.009, 'quality' => 1, 'card_type' => 'chinatelecom']
+//        ],
+
+        50 => [
+//            ['goods_id' => 8951, 'price' => 50.15,'quality' => 1, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8951, 'price' => 49.94, 'quality' => 1, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 8951, 'price' => 50.15,   'quality' => 1, 'card_type' => 'chinatelecom']
+        ],
+        100 => [
+//            ['goods_id' => 8952, 'price' => 100.1, 'quality' => 1, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8952, 'price' => 99.88, 'quality' => 1, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 8952, 'price' => 100.3, 'quality' => 1, 'card_type' => 'chinatelecom']
+        ],
+        200 => [
+//            ['goods_id' => 8953, 'price' => 191.0, 'quality' => 1, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8953, 'price' => 199.76, 'quality' => 1, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 8953, 'price' => 193.0, 'quality' => 1, 'card_type' => 'chinatelecom']
+        ],
+
+        300 => [
+//            ['goods_id' => 8955, 'price' => 299.85, 'quality' => 1, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8955, 'price' => 299.64, 'quality' => 1, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 8955, 'price' => 300, 'quality' => 1, 'card_type' => 'chinatelecom']
+        ],
+//
+//        500 => [
+//            ['goods_id' => 8954, 'price' => 499.75, 'quality' => 1, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 8954, 'price' => 501, 'quality' => 1, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 8954, 'price' => 500, 'quality' => 1, 'card_type' => 'chinatelecom']
+//        ]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
+
 $phone_providers = [
     ['name' => 'dixin_normal', 'cfg' => $dixin_normal],
-    ['name' => 'suhu_normal' , 'cfg' => $suhu_normal]
+    ['name' => 'suhu_normal' , 'cfg' => $suhu_normal],
+    ['name' => 'suhu_wozhifu' , 'cfg' => $suhu_wozhifu]
 ];
 
 $config['phone_providers'] = $phone_providers;

+ 23 - 0
helper/refill/api/mh/suhu_wozhifu/ReadMe.MD

@@ -0,0 +1,23 @@
+后台地址:http://merchant.sujiaofei.com:92
+用户编号:31899
+登录账号:13911220681
+登录密码:kwgfi6fm9e
+签名密钥:dvv0atra7egmbcji8wy07ba3dt0h7609
+
+
+沃支付产品编码:
+
+
+全国联通话费50元的商品编号是: 10131
+全国联通话费100元的商品编号是:10132
+全国联通话费200元的商品编号是:10133
+全国联通话费300元的商品编号是:10134
+
+
+
+沃支付:费率99.88%
+全国联通50元(沃支付)10131
+全国联通100元(沃支付)10132
+全国联通200元(沃支付)10133
+全国联通300元(沃支付)10134
+

+ 54 - 0
helper/refill/api/mh/suhu_wozhifu/RefillCallBack.php

@@ -0,0 +1,54 @@
+<?php
+namespace refill\suhu_wozhifu;
+
+require_once(BASE_HELPER_RAPI_PATH . '/suhu_wozhifu/config.php');
+use refill;
+
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $signer = function ($params) {
+            $body = "code={$params['memberId']}rechargeOrderId={$params['rechargeOrderId']}memberOrderId={$params['memberOrderId']}rechargeAccount={$params['rechargeAccount']}productId={$params['productId']}faceValue={$params['faceValue']}signkey=";
+            $body .= config::KEY;
+
+            return md5($body);
+        };
+
+        $sign = $signer($params);
+        if ($params['sign'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    //[$order_id, $success, $can_try, $need_handle, $official_sn]
+    public function notify($params): array
+    {
+        $order_sn = $params['memberOrderId'];
+        $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
+
+        if (empty($order_info)) {
+            return [false, false, false, false, ''];
+        }
+
+        $official_sn = trim($params['supplyCert'] ?? '');
+        $order_id = $order_info['order_id'];
+
+        $code = intval($params['code']);
+        if ($code === 201) {
+            $data['ch_trade_no'] = $params['order_no'];
+            $data['official_sn'] = $official_sn;
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false, true, $official_sn];
+        }
+        elseif (in_array($code, [202, 203, 204])) {
+            Model('refill_order')->edit($order_id, ['ch_trade_no' => $params['order_no']]);
+            return [$order_id, false, true, true, ''];
+        }
+        else {
+            return [$order_id, false, false, false, ''];
+        }
+    }
+}

+ 191 - 0
helper/refill/api/mh/suhu_wozhifu/RefillPhone.php

@@ -0,0 +1,191 @@
+<?php
+
+namespace refill\suhu_wozhifu;
+
+require_once(BASE_HELPER_RAPI_PATH . '/suhu_wozhifu/config.php');
+
+use refill;
+use Log;
+
+class RefillPhone extends refill\IRefillPhone
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    private function add_params(int $phone, int $amount, string $order_sn, int $card_type): array
+    {
+        $signer = function ($params)
+        {
+            $body = "memberId={$params['memberId']}productId={$params['productId']}memberOrderId={$params['memberOrderId']}rechargeAccount={$params['rechargeAccount']}faceValue={$params['faceValue']}signkey=";
+            $body .= config::KEY;
+
+            return md5($body);
+        };
+
+        $sku_code = config::sku_code($card_type,$amount);
+        if(empty($sku_code)) {
+            return [];
+        }
+
+        $params = [
+            "memberId" => config::MEMBER_ID,
+            'productId' => $sku_code,
+            'memberOrderId' => $order_sn,
+            'rechargeAccount' => "$phone",
+            'faceValue' => "$amount"
+        ];
+
+        $params['sign'] = $signer($params);
+        return $params;
+    }
+    public function add($card_no, $card_type, $amount, $params, &$net_errno = 0): array
+    {
+        $params = $this->add_params($card_no, $amount, $params['order_sn'],$card_type);
+        if(empty($params)) {
+            return [false, '提单参数不符合', false];
+        }
+
+        $resp = http_request(config::ORDER_URL, $params , 'POST' , false , [] , $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];
+            }
+
+            $code = $resp['code'];
+            if ($code === 100) {
+                return [true, $resp['rechargeOrderId'], false];
+            } elseif (in_array($code, config::ERRCODES, true)) {
+                return [false, $resp['msg'], false];
+            } elseif ($code === 999) {
+                $net_errno = "HTTP-$code";
+                return [false, $resp['msg'], true];
+            } else {
+                $net_errno = "HTTP-998";
+                return [false, $resp['msg'], true];
+            }
+        }
+    }
+
+    private function query_params($refill_info)
+    {
+        $params = [
+            'memberId' => config::MEMBER_ID,
+            'memberOrderId' => $refill_info['order_sn'],
+            'requestDate' => date("Y-m-d H:i:s",time())
+        ];
+
+        $signer = function ($params)
+        {
+            $body = "memberId={$params['memberId']}rechargeOrderId=memberOrderId={$params['memberOrderId']}requestDate={$params['requestDate']}signkey=";
+            $body .= config::KEY;
+
+            return md5($body);
+        };
+
+        $params['sign'] = $signer($params);
+        return $params;
+    }
+
+    public function query($refill_info): array
+    {
+        $params = $this->query_params($refill_info);
+        $resp = http_request(config::QUERY_URL, $params , 'POST');
+
+        if (empty($resp)) {
+            return [false, '系统错误', ''];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '系统错误', ''];
+            }
+
+            $official_sn = '';
+
+            $status = intval($resp['status']);
+            if($status === 1)
+            {
+                if(empty($resp['result'])) {
+                    return [false, '系统错误', ''];
+                }
+
+                $item = $resp['result'][0];
+
+                $code = $item['code'];
+                if($code == 200) {
+                    $order_state = ORDER_STATE_SEND;
+                }
+                elseif($code == 201) {
+                    $updata['official_sn'] = $item['supplyCert'];
+                    Model('refill_order')->edit($refill_info['order_id'], $updata);
+                    $official_sn = $item['supplyCert'];
+                    $order_state = ORDER_STATE_SUCCESS;
+                }
+                elseif(in_array($code,[202,203,204])) {
+                    $order_state = ORDER_STATE_CANCEL;
+                }
+            }
+            elseif($status === 2 and (time() - $refill_info['commit_time'] >= 600))
+            {
+                $order_state = ORDER_STATE_NOEXIST;
+            }
+            else {
+                return [false, $resp['msg']];
+
+            }
+
+            return [true, $order_state, $official_sn];
+        }
+    }
+
+    private function balance_params()
+    {
+        $params = [
+            'memberId' => config::MEMBER_ID,
+            'requestDate' => date("Y-m-d H:i:s", time())
+        ];
+
+        $signer = function ($params)
+        {
+            $body = "memberId={$params['memberId']}requestDate={$params['requestDate']}signkey=";
+            $body .= config::KEY;
+
+            return md5($body);
+        };
+
+        $params['sign'] = $signer($params);
+        return $params;
+    }
+    public function balance(): array
+    {
+        $params = $this->balance_params();
+        $resp = http_request(config::BALANCE_URL, $params , 'POST');
+
+        if (empty($resp)) {
+            return [false, '系统错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '系统错误'];
+            } elseif ($resp['status'] === 1) {
+                return [true, ncPriceFormat($resp['result']['money'])];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+}

+ 60 - 0
helper/refill/api/mh/suhu_wozhifu/config.php

@@ -0,0 +1,60 @@
+<?php
+
+namespace refill\suhu_wozhifu;
+
+use mtopcard;
+
+class config
+{
+    const MEMBER_ID = '31899';
+    const KEY = 'dvv0atra7egmbcji8wy07ba3dt0h7609';
+
+    const ORDER_URL = 'http://api2.sujiaofei.com/submitRechargeOrder';
+    const QUERY_URL = 'http://api2.sujiaofei.com/queryRechargeOrder';
+    const BALANCE_URL = 'http://api2.sujiaofei.com/queryRechargeMember';
+
+    //需要速交费技术记录地址
+    const NOTIFY_URL = BASE_SITE_URL . "/racc/callback/mh/suhu_wozhifu.php";
+
+    const ERRCODES = [101, 102, 103, 104, 105, 106, 107, 108, 109];
+
+    private static $stStoreProducts = [
+        50  => [ 5 => '10011'],
+        100 => [ 5 => '10012'],
+        200 => [ 5 => '10013'],
+        300 => [ 5 => '10014']
+    ];
+
+    public static function sign($params)
+    {
+        if (is_object($params)) { //对象转数组
+            $params = json_decode(json_encode($params), true);
+        }
+
+        $params['sign_key'] = config::KEY;
+        ksort($params);
+
+        $formatData = [];
+        foreach ($params as $k => $v) {
+            if (is_array($v) || is_object($v)) {
+                $v = json_encode($v, JSON_UNESCAPED_UNICODE);
+            }
+            if ((!empty($v) || (string)$v === '0') && $k != 'sign') {
+                $formatData[] = "$k=$v";
+            }
+        }
+        $signStr = implode('&', $formatData);
+
+        return md5($signStr);
+    }
+
+    public static function sku_code($card_type, $amount)
+    {
+        if (array_key_exists($amount, self::$stStoreProducts)) {
+            if (array_key_exists($card_type, self::$stStoreProducts[$amount])) {
+                return self::$stStoreProducts[$amount][$card_type];
+            }
+        }
+        return false;
+    }
+}

+ 4 - 0
racc/callback/mh/suhu_wozhifu.php

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

+ 17 - 0
test/mh/TestRefill.php

@@ -58,6 +58,23 @@ class TestRefill extends TestCase
         $provider->notify($content);
     }
 
+    public function testSuhuWozhifu()
+    {
+//        $provider = $this->getProvider('suhu_wozhifu');
+//        $order_sn = $this->make_sn();
+//        $resp = $provider->add(13911129867, 5, 30, ['order_sn' => $order_sn, 'regin_no' => 1]);
+//        $resp = $provider->query(['order_sn' => $order_sn]);
+//        $resp = $provider->balance();
+    }
+    public function testSuhuWozhifuCB()
+    {
+//        $content = '{"order_no":"OD40636475187360296","merchant_no":"0059570753462761433314","recharge_account":"13911129867","recharge_status":4,"complete_time":"2023-11-16 15:12:42","settlement_price":"47.30","total_amount":"50.00","actual_amount":"0.00","create_time":"2023-11-16 15:12:41","custom_tag":"123456","sign":"49b7f9f32a34f1c83dcb0d976f28d061"}';
+//        $provider = $this->getProvider('suhu_wozhifu','RefillCallBack');
+//        $content = json_decode($content,true);
+//        $provider->verify($content);
+//        $provider->notify($content);
+    }
+
 
     public function testJson()
     {