Browse Source

榜样新增通道-BYQ:仁跃(权益)

zhaoming 1 year ago
parent
commit
f4a1db9251

+ 7 - 0
data/config/zy/refill.ini.php

@@ -2927,6 +2927,12 @@ $baibaoquanyi = ['name' => 'baibaoquanyi', 'store_id' => 111, 'qualitys' => '1',
     ],
     ],
     'official_sn' => true, 'refill_type' => 'api'];
     'official_sn' => true, 'refill_type' => 'api'];
 
 
+$Ryuequanyi = ['name' => 'Ryuequanyi', 'store_id' => 114, 'qualitys' => '1',
+    'amount' => [
+        100 => [['goods_id' => 7217, 'price' => 100, 'quality' => 1, 'card_type' => 'third']],
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $third_providers = [
 $third_providers = [
     ['name' => 'byq_tianrui', 'cfg' => $byq_tianrui],
     ['name' => 'byq_tianrui', 'cfg' => $byq_tianrui],
     ['name' => 'youlaicomeqy', 'cfg' => $youlaicomeqy],
     ['name' => 'youlaicomeqy', 'cfg' => $youlaicomeqy],
@@ -2944,6 +2950,7 @@ $third_providers = [
     ['name' => 'xinde_qy', 'cfg' => $xinde_qy],
     ['name' => 'xinde_qy', 'cfg' => $xinde_qy],
     ['name' => 'weibian_qy', 'cfg' => $weibian_qy],
     ['name' => 'weibian_qy', 'cfg' => $weibian_qy],
     ['name' => 'baibaoquanyi', 'cfg' => $baibaoquanyi],
     ['name' => 'baibaoquanyi', 'cfg' => $baibaoquanyi],
+    ['name' => 'Ryuequanyi', 'cfg' => $Ryuequanyi],
 ];
 ];
 $config['third_providers'] = $third_providers;
 $config['third_providers'] = $third_providers;
 
 

+ 77 - 0
helper/refill/api/zy/Ryuequanyi/RefillCallBack.php

@@ -0,0 +1,77 @@
+<?php
+namespace refill\Ryuequanyi;
+
+require_once(BASE_HELPER_RAPI_PATH . '/Ryuequanyi/config.php');
+
+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)
+    {
+        ksort($params);
+
+        $body = "";
+        $i = 0;
+        foreach ($params as $k => $v) {
+            if (false === $this->check_empty($v) && "@" != substr($v, 0, 1)) {
+                if ($i == 0) {
+                    $body .= "{$k}" . "=" . urlencode($v);
+                } else {
+                    $body .= "&" . "{$k}" . "=" . urlencode($v);
+                }
+                $i++;
+            }
+        }
+
+        $body .= "&key=".config::KEY;
+        return md5($body);
+    }
+
+    public function notify($params)
+    {
+        $status = $params['state'];
+        $order_sn = $params['order_sn'];
+        $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 === 'SUCCESS') {
+            $data['ch_trade_no'] = $params['trade_no'];
+            $data['official_sn'] = strtolower($params['official_sn']) == 'null' ? '' : $params['official_sn'];
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false,true];
+        }
+        elseif ($status === 'CANCEL') {
+            Model('refill_order')->edit($order_id, ['ch_trade_no' => $params['trade_no']]);
+            return [$order_id, false, true,true];
+        }
+        else {
+            return [$order_id, false, false,false];
+        }
+    }
+}

+ 176 - 0
helper/refill/api/zy/Ryuequanyi/RefillPhone.php

@@ -0,0 +1,176 @@
+<?php
+
+namespace refill\Ryuequanyi;
+
+require_once(BASE_HELPER_RAPI_PATH . '/Ryuequanyi/config.php');
+
+use refill;
+use Log;
+
+class RefillPhone extends refill\IRefillThird
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    private function req_params($phone, string $order_sn, $product_code)
+    {
+        $params['act'] = 'refill';
+        $params['op'] = 'add_third';
+        $params['product_code'] = $product_code;
+        $params['mchid'] = config::MCH_ID;
+        $params['cardno'] = $phone;
+        $params['order_sn'] = $order_sn;
+        $params['quantity'] = 1;
+        $params['notifyurl'] = config::NOTIFY_URL;
+        return $params;
+    }
+
+    private function getProductCode($goods_id, $sys_pcode)
+    {
+        $thrid_refill = Model('thrid_refill');
+        $product = $thrid_refill->getProviderProduct($this->mStoreID,$goods_id,$sys_pcode);
+        if (empty($product)) {
+            return false;
+        } else {
+            return $product['channel_code'];
+        }
+    }
+
+    public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
+    {
+        $goods_id = intval($params['goods_id']);
+        $product_code = $this->getProductCode($goods_id, $params['product_code']);
+
+        $params = $this->req_params($card_no, $params['order_sn'], $product_code);
+        $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 = json_decode($resp ,true);
+            if (empty($resp)) {
+                return [false, '系统错误', true];
+            } elseif ($resp['code'] === 200) {
+                return [true, '', false];
+            } else {
+                return [false, $resp['message'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['act'] = 'refill';
+        $params['op'] = 'query';
+        $params['mchid'] = config::MCH_ID;
+        $params['order_sn'] = $refill_info['order_sn'];
+        $params['sign'] = $this->sign($params);
+
+        $resp = http_request(config::ORDER_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['code'] === 200)
+            {
+                $data = $resp['datas'];
+                if ($data['order_state'] == '40') {
+                    $save['ch_trade_no'] = $data['trade_no'];
+                    $save['official_sn'] = strtolower($resp['official_sn']) == 'null' ? '' : $resp['official_sn'];
+                    Model('refill_order')->edit($refill_info['order_id'], $save);
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($data['order_state'] === '0') {
+                    Model('refill_order')->edit($refill_info['order_id'], ['ch_trade_no' => $data['trade_no']]);
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif (in_array($data['order_state'], ['10', '20', '30', '50'], true)) {
+                    $order_state = ORDER_STATE_SEND;
+                } else {
+                    return [false, $resp['message']];
+                }
+                return [true, $order_state];
+            }
+            elseif ($resp['code'] === 202 && (time() - $refill_info['commit_time'] >= 600))
+            {
+                return [true, ORDER_STATE_NOEXIST];
+            }
+            else
+            {
+                return [false, $resp['message']];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $params['act'] = 'refill';
+        $params['op'] = 'balance';
+        $params['mchid'] = config::MCH_ID;
+        $params['sign'] = $this->sign($params);
+
+        $resp = http_request(config::ORDER_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['code'] === 200) {
+                return [true, $resp['datas']['balance']];
+            } else {
+                return [false, $resp['message']];
+            }
+        }
+    }
+
+    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)
+    {
+        ksort($params);
+
+        $body = "";
+        $i = 0;
+        foreach ($params as $k => $v) {
+            if (false === $this->check_empty($v) && "@" != substr($v, 0, 1)) {
+                if ($i == 0) {
+                    $body .= "{$k}" . "=" . urlencode($v);
+                } else {
+                    $body .= "&" . "{$k}" . "=" . urlencode($v);
+                }
+                $i++;
+            }
+        }
+
+        $body .= "&key=".config::KEY;
+
+        return md5($body);
+    }
+}

+ 7 - 0
helper/refill/api/zy/Ryuequanyi/api.txt

@@ -0,0 +1,7 @@
+https://admin.xyzshops.cn/merchant/#/login
+
+Ryuequanyi
+erc_342d
+
+10476
+cbae165ae6dc5c45219c6bf65d7e9ed9

+ 13 - 0
helper/refill/api/zy/Ryuequanyi/config.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace refill\Ryuequanyi;
+
+# 百保(权益)
+class config
+{
+    const MCH_ID = 10476;
+    const KEY = 'cbae165ae6dc5c45219c6bf65d7e9ed9';
+
+    const ORDER_URL  =  'https://www.xyzshops.cn/mobile/index.php';
+    const NOTIFY_URL = BASE_SITE_URL . '/mobile/callback/refill_Ryuequanyi.php';
+}

+ 4 - 0
mobile/callback/refill_Ryuequanyi.php

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

+ 6 - 0
test/TestRefill.php

@@ -5301,6 +5301,12 @@ class TestRefill extends TestCase
         $provider = $this->getProvider('youlaicomet');
         $provider = $this->getProvider('youlaicomet');
         [$succ, $val] = $provider->balance();
         [$succ, $val] = $provider->balance();
     }
     }
+
+    public function testRyuequanyi_Balance()
+    {
+        $provider = $this->getProvider('Ryuequanyi');
+        [$succ, $val] = $provider->balance();
+    }
 }
 }
 
 
 //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testLoadBlack)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test
 //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testLoadBlack)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test