stanley-king vor 1 Jahr
Ursprung
Commit
75d5bf4f16

+ 52 - 1
admin/control/merchant.php

@@ -267,7 +267,7 @@ class merchantControl extends SystemControl
             }
 
             $query_add_times = intval($_POST['query_add_times'] ?? 0);
-            $query_reduce_amount = ncPriceFormat($_POST['query_reduce_amount'] ?? 0);
+            $this->add_query_times($mchid, $query_add_times);
 
             $member_id = $merchant['admin_id'];
             $model_merchant = Model('merchant');
@@ -305,6 +305,57 @@ class merchantControl extends SystemControl
         Tpl::showpage('merchant.edit');
     }
 
+    private function add_query_times($mchid, $query_times)
+    {
+        $pcode_getter = function ($times)
+        {
+            $pcodetimes = [
+                10000000 => 'XYZ_QUERY_001',
+                1000000 => 'XYZ_QUERY_002',
+                100000 => 'XYZ_QUERY_003',
+                10000 => 'XYZ_QUERY_004',
+                1000 => 'XYZ_QUERY_005',
+                100 => 'XYZ_QUERY_006'
+            ];
+
+            $ret = $pcodetimes[$times] ?? '';
+
+            return $ret;
+        };
+
+        $make_sn = function () {
+            return mt_rand(1000, 9999)
+                . sprintf('%010d', time())
+                . sprintf('%06d', (float)microtime() * 1000000);
+        };
+
+        $req_params = function ($mchid, $phone, $order_sn, $product_code)
+        {
+            $params['act'] = 'refill';
+            $params['op'] = 'add_third';
+            $params['product_code'] = $product_code;
+            $params['mchid'] = $mchid;
+            $params['cardno'] = $phone;
+            $params['order_sn'] = $order_sn;
+            $params['quantity'] = 1;
+            $params['notifyurl'] = 'http://192.168.3.104:8300/mobile/callback/card_query.php';
+            return $params;
+        };
+
+        $pcode = $pcode_getter($query_times);
+        if(empty($pcode)) {
+            return false;
+        }
+
+        $proxy = new refill_proxy("9a24e56d79a3653f99895e0e3af4dea9");
+        $order_sn = $make_sn();
+        $params = $req_params($mchid, '13911129867', $order_sn, $pcode);
+        $resp = $proxy->send('http://192.168.3.104:8300/mobile/index.php', $params);
+        if(empty($resp)) {
+            $x = 1;
+        }
+    }
+
     public function priceOp()
     {
         $quality = $_GET['quality'] ?? 1;

+ 5 - 5
crontab/control/minutes.php

@@ -29,12 +29,12 @@ class minutesControl extends BaseCronControl
     {
         Log::record(__FUNCTION__ . " start",Log::DEBUG);
         //未付款订单超期自动关闭
-//        $this->_order_timeout_cancel();
+        //$this->_order_timeout_cancel();
         $this->_cron_common([1,2,3,4,5,6,7]);
         $this->_fetch_order_unavaliable();
         $this->_check_merchant_alarm_amount();
 
-        Log::record(__FUNCTION__ . " end",Log::DEBUG);
+        Log::record(__FUNCTION__ . " end", Log::DEBUG);
 
 //        $this->_web_index_update();
 //        $this->_check_merchant_alarm_amount();
@@ -674,7 +674,7 @@ class minutesControl extends BaseCronControl
 
         $count = count($cron);
         if ($count <= 0) return false;
-        Log::record("match cron count={$count}",Log::DEBUG);
+        Log::record("match cron count=$count",Log::DEBUG);
 
         $cron_array = [];
         $cronid = [];
@@ -702,14 +702,14 @@ class minutesControl extends BaseCronControl
             }
 
             $method = '_cron_'.$k;
-            Log::record("crontab minutest:{$method}",Log::DEBUG);
+            Log::record("crontab minutest:$method",Log::DEBUG);
 
             $result = call_user_func_array([$this, '_cron_' . $k], [$v]);
             if (is_array($result)) {
                 $cronid = array_merge($cronid, $result);
             } else {
                 $method = '_cron_' . $k;
-                Log::record("crontab minutest err:{$method}", Log::ERR);
+                Log::record("crontab minutest err:$method", Log::ERR);
             }
         }
 

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

@@ -6576,6 +6576,12 @@ $duiba_fetch = ['name' => 'duiba_fetch', 'store_id' => 348, 'qualitys' => '1',
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$rsanfang_fetch = ['name' => 'rsanfang', 'store_id' => 396, 'qualitys' => '1',
+    'amount' => [
+        100 => [['goods_id' => 9107, 'price' => 99, 'quality' => 1, 'card_type' => 'third']],
+    ],
+    'official_sn' => false, 'refill_type' => 'fetch'];
+
 $third_providers = [
 //    ['name' => 'lingzhthird', 'cfg' => $lingzhthird],
 //    ['name' => 'jumithird', 'cfg' => $jumithird],
@@ -6585,6 +6591,7 @@ $third_providers = [
 //    ['name' => 'jiyemei_doubi', 'cfg' => $jiyemei_doubi]
     ['name' => 'yzdb', 'cfg' => $yzdb],
     ['name' => 'yanhao', 'cfg' => $yanhao],
+    ['name' => 'rsanfang', 'cfg' => $rsanfang_fetch],
 ];
 $config['third_providers'] = $third_providers;
 

+ 1 - 1
docker/compose/homecuda/master/docker-compose.yml

@@ -9,7 +9,7 @@ services:
     volumes:
       - ../../../../:${SHOP_ROOT_PATH}
       - ../conf/etc/localtime:/etc/localtime:ro
-      - ../conf/php/php.ini:/usr/local/etc/php/php.ini
+      - ../conf/php/php-ibaobei.ini:/usr/local/etc/php/php.ini
       - ../conf/crontab/master_root:/var/spool/cron/crontabs/root
       - ${SHOP_UPLOAD_PATH}:${SHOP_ROOT_PATH}/data/upload
       - ${SHOP_LOG_PATH}:${SHOP_ROOT_PATH}/data/log

+ 159 - 0
helper/query_proxy.php

@@ -0,0 +1,159 @@
+<?php
+
+
+class query_proxy
+{
+    private $mKey;
+
+    public function __construct($key)
+    {
+        $this->mKey = $key;
+    }
+
+    public function send($url,$params)
+    {
+        $body = $this->body($params);
+        $body .= "&key={$this->mKey}";
+        $params['sign'] = md5($body);
+
+        $resp = $this->http_request($url,$params,'POST');
+        Log::record("resp={$resp}",Log::DEBUG);
+
+        if(empty($resp)) {
+            return [false,'网络错误'];
+        }
+
+        $resp = json_decode($resp,true);
+        $code = $resp['code'];
+
+        if(empty($resp)) {
+            return [false,'网络错误'];
+        }
+        elseif($code == 200) {
+            return [$code,$resp['data']];
+        }
+        else {
+            return [$code,$resp['msg']];
+        }
+    }
+
+    public function notify($params)
+    {
+        unset($params['mchname']);
+
+        if(!$this->verify($this->mKey,$params)) {
+            return [false,'签名错误'];
+        }
+        else {
+            return [true,$params];
+        }
+    }
+
+    private function verify($key,$input)
+    {
+        $sign = $input['sign'];
+        unset($input['sign']);
+
+        $body = $this->body($input);
+        $body .= "&key={$key}";
+
+        return ($sign == md5($body));
+    }
+
+    protected function check_empty($value)
+    {
+        if (!isset($value))
+            return true;
+        if ($value === null)
+            return true;
+        if (trim($value) === "")
+            return true;
+
+        return false;
+    }
+
+    private function body($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++;
+            }
+        }
+        return $body;
+    }
+
+    private function http_request($url, $params = array(), $method = 'GET', $multi = false, $extheaders = array())
+    {
+        if (!function_exists('curl_init')) {
+            return false;
+        }
+
+        $method = strtoupper($method);
+        $ci = curl_init();
+        curl_setopt($ci, CURLOPT_USERAGENT, 'PHP-SDK OAuth2.0');
+        curl_setopt($ci, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, false);
+        curl_setopt($ci, CURLOPT_SSL_VERIFYHOST, false);
+        curl_setopt($ci, CURLOPT_HEADER, false);
+        curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 60);
+        curl_setopt($ci, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
+        curl_setopt($ci, CURLOPT_FOLLOWLOCATION, true);
+
+
+        $headers = (array) $extheaders;
+        switch ($method)
+        {
+            case 'POST':
+                curl_setopt($ci, CURLOPT_POST, TRUE);
+                if (!empty($params))
+                {
+                    if ($multi)
+                    {
+                        foreach ($multi as $key => $file) {
+                            $params[$key] = '@' . $file;
+                        }
+                        curl_setopt($ci, CURLOPT_POSTFIELDS, $params);
+                        $headers[] = 'Expect: ';
+                    }
+                    else {
+                        curl_setopt($ci, CURLOPT_POSTFIELDS, http_build_query($params));
+                    }
+                }
+                break;
+            case 'DELETE':
+            case 'GET':
+                if($method == 'DELETE') {
+                    curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
+                }
+                if (!empty($params)) {
+                    $url = $url . (strpos($url, '?') ? '&' : '?') . (is_array($params) ? http_build_query($params) : $params);
+                }
+                break;
+        }
+        curl_setopt($ci, CURLINFO_HEADER_OUT, TRUE);
+        curl_setopt($ci, CURLOPT_URL, $url);
+        if ($headers) {
+            curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);
+        }
+
+        $response = curl_exec($ci);
+        if($response == false) {
+            $err = curl_error($ci);
+            Log::record("http_request err=$err",Log::ERR);
+        }
+
+        curl_close($ci);
+
+        return $response;
+    }
+}

+ 4 - 1
helper/refill/RefillBase.php

@@ -555,10 +555,12 @@ class RefillBase
                 $refill_type = $provider->refill_type();
                 $vr_part = util::part_vr_order_time($order_time);
 
+                //api回调模式
                 if ($refill_type == 'api') {
                     $logic_vr_order = Logic("vr_order");
                     $logic_vr_order->changeOrderStateSend($order_id, true, $vr_part);
                 }
+                //抢单子模式
                 elseif($refill_type == 'fetch') {
                     $logic_vr_order = Logic("vr_order");
                     $logic_vr_order->changeOrderStateSend($order_id, true, $vr_part);
@@ -576,7 +578,8 @@ class RefillBase
 
                 $data = ['commit_time' => $commit_time, 'ch_trade_no' => $trade_no];
                 $mod_refill->partition(util::part_refill($order_time))->edit($order_id, $data);
-                //如果对方没有回调能力,则启动主动查询.
+
+                //主动查询模式。如果对方没有回调能力,则启动主动查询.
                 if($provider->callback() === false) {
                     QueueClient::async_push("QueryAutoRefillState",['order_id' => $order_id,'query_times' => 0],3);
                 }

+ 0 - 31
helper/refill/api/xyz/rsanfang/RefillCallBack.php

@@ -1,31 +0,0 @@
-<?php
-namespace refill\rsanfang;
-
-require_once(BASE_HELPER_RAPI_PATH . '/rsanfang/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): string
-    {
-        $content = "";
-        return strtoupper(md5($content));
-    }
-
-    public function notify($params): array
-    {
-        $order_id = '';
-        $official_sn = '';
-        return [$order_id, true, false, true, $official_sn];
-    }
-}

+ 24 - 63
helper/refill/api/xyz/rsanfang/RefillPhone.php

@@ -5,8 +5,6 @@ namespace refill\rsanfang;
 require_once(BASE_HELPER_RAPI_PATH . '/rsanfang/config.php');
 
 use refill;
-use Log;
-use mtopcard;
 
 class RefillPhone extends refill\IRefillThird
 {
@@ -27,9 +25,9 @@ class RefillPhone extends refill\IRefillThird
         }
     }
 
-    private function req_params(int $phone, int $amount, $card_type, string $order_sn, $channel_code): array
-    {
-        return [];
+    //启用主动查询功能
+    public function callback() {
+        return false;
     }
 
     public function add($card_no, $card_type, $amount, $params, &$net_errno = 0): array
@@ -41,77 +39,40 @@ class RefillPhone extends refill\IRefillThird
             return [false, '产品有误', false];
         }
 
-        [$validate, $card_type, $regin_no, $isTransfer, $card_state, $black] = mtopcard\valid_phone($card_no);
-        $params = $this->req_params($card_no, $amount, $card_type, $order_sn, $channel_code);
-        if (empty($params)) {
-            return [false, '产品面值有误', false];
+        $mchid = $params['mchid'];
+        $times = config::getTimes($channel_code);
+        if($times <= 0) {
+            return [false, '产品有误', false];
         }
 
-        $resp = http_request(config::ORDER_URL, $params, 'POST', false, config::ExtHeaders, $net_errno);
-
-        if (empty($resp))
-        {
-            return [false, '网络错误', true];
-        }
-        else
-        {
-            $resp = json_decode($resp, true);
-            if (empty($resp))
-            {
-                return [false, '网络错误', true];
-            }
-            else
-            {
-                return [true, '', false];
-            }
+        $model_merchant = Model('merchant');
+        $data = [
+            'query_total_times' => ['exp', "query_total_times+$times"],
+            'query_left_times' => ['exp', "query_left_times+$times"]
+        ];
+        $ret = $model_merchant->editMerchant($data, ['mchid' => $mchid]);
 
+        if($ret) {
+            return [true, $order_sn, false];
+        } else {
+            return [true, '更新数据库出错', false];
         }
     }
 
     public function query($refill_info): array
     {
-        $params = [];
-
-        $resp = http_request(config::QUERY_URL, $params, 'POST', false, config::ExtHeaders);
+        $order_sn = $refill_info['order_sn'];
+        $ch_trade_no = $refill_info['ch_trade_no'];
 
-        if (empty($resp))
-        {
-            return [false, '网络错误', ''];
-        }
-        else
-        {
-            Log::record($resp, Log::DEBUG);
-            $resp = json_decode($resp, true);
-            if (empty($resp))
-            {
-                return [false, '网络错误', ''];
-            }
-            else
-            {
-                return [true, ORDER_STATE_SUCCESS, ''];
-            }
+        if ($order_sn == $ch_trade_no) {
+            return [true, ORDER_STATE_SUCCESS, ''];
+        } else {
+            return [true, ORDER_STATE_SEND, ''];
         }
     }
 
     public function balance(): array
     {
-        $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, '系统错误'];
-            } else {
-                return [true, 0];
-            }
-        }
+        return [true, 0];
     }
-
 }

+ 12 - 8
helper/refill/api/xyz/rsanfang/config.php

@@ -3,15 +3,19 @@
 
 namespace refill\rsanfang;
 
-use mtopcard;
 class config
 {
-    const ORDER_URL = '';
-    const QUERY_URL= '';
-    const BALANCE_URL = '';
-
-    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_rsanfang.php";
-
-    const ExtHeaders = ['Content-Type:application/x-www-form-urlencoded;'];
+    const Pcode_Times = [
+        'XYZ_QUERY_001' => 10000000,
+        'XYZ_QUERY_002' => 1000000,
+        'XYZ_QUERY_003' => 100000,
+        'XYZ_QUERY_004' => 10000,
+        'XYZ_QUERY_005' => 1000,
+        'XYZ_QUERY_006' => 100,
+        ];
 
+    public static function getTimes($pcode)
+    {
+        return config::Pcode_Times[$pcode] ?? 0;
+    }
 }

+ 1 - 1
helper/refill_proxy.php

@@ -149,7 +149,7 @@ class refill_proxy
         $response = curl_exec($ci);
         if($response == false) {
             $err = curl_error($ci);
-            Log::record("http_request err={$err}",Log::ERR);
+            Log::record("http_request err=$err",Log::ERR);
         }
 
         curl_close($ci);

+ 11 - 0
mobile/callback/card_query.php

@@ -0,0 +1,11 @@
+<?php
+/**
+ *   query_callback.php
+ *   stanley-king
+ *   2024/4/10
+ *   PhpStorm
+ *   PHPProject
+ */
+
+
+echo ('SUCCESS');

+ 1 - 1
rdispatcher/codispatcher.php

@@ -38,7 +38,7 @@ function strbool($value) {
 function handle_error($level, $message, $file, $line)
 {
     if($level == E_NOTICE) return;
-    $trace = "handle_error: level={$level},msg={$message} file={$file},line={$line}\n";
+    $trace = "handle_error: level=$level msg=$message file=$file,line=$line\n";
     $backtrace = debug_backtrace();
     foreach ($backtrace as $item) {
         $trace .= "{$item['file']}\t{$item['line']}\t{$item['function']}\n";

+ 0 - 1
test/TestRefill.php

@@ -37,7 +37,6 @@ class TestRefill extends TestCase
             $this->mKey = '1ff02223b771c0414468c8892151c602';
         } else {
             $this->mReqHost = 'https://www.xyzshops.cn';
-//            $this->mReqHost = 'http://121.89.196.45';
             $this->mMchid = 1092;
             $this->mKey = '210fe406954220f56085997d6a4c5b80';
         }

+ 70 - 0
test/refill/TestQueryCard.php

@@ -0,0 +1,70 @@
+<?php
+/**
+ *   TestQueryCard.php
+ *   stanley-king
+ *   2024/4/11
+ *   PhpStorm
+ *   PHPProject
+ */
+
+use PHPUnit\Framework\TestCase;
+
+define('APP_ID', 'test');
+define('BASE_ROOT_PATH', str_replace('/test/refill', '', dirname(__FILE__)));
+require_once(BASE_ROOT_PATH . '/global.php');
+require_once(BASE_CORE_PATH . '/lrlz.php');
+require_once(BASE_ROOT_PATH . '/fooder.php');
+
+require_once(BASE_HELPER_PATH . '/refill/XYZRefillFactory.php');
+require_once(BASE_HELPER_PATH . '/query_proxy.php');
+
+class TestQueryCard extends TestCase
+{
+    public static function setUpBeforeClass(): void
+    {
+        Base::run_util();
+    }
+
+
+    public function testMerchantQuery()
+    {
+        $req_params = function ($phone)
+        {
+            $params['mchid'] = 10165;
+            $params['cardno'] = $phone;
+
+            return $params;
+        };
+
+        $url = 'http://192.168.3.104:8080/api.php/CardInfo/query';
+
+        $proxy = new query_proxy("9a24e56d79a3653f99895e0e3af4dea9");
+
+        $params = $req_params('13911129867');
+        $resp = $proxy->send($url, $params);
+        if(empty($resp)) {
+            $x = 1;
+        }
+    }
+    public function testAppQuery()
+    {
+        $req_params = function ($phone)
+        {
+            $params['appid'] = 'ea97586b4aa0c141e4456912f3325f7f';
+            $params['cardno'] = $phone;
+
+            return $params;
+        };
+
+        $url = 'http://192.168.3.104:8080/api.php/CardInfo/query';
+
+        $proxy = new query_proxy("92c51d28e3405c923decf1b333cec3ce");
+
+        $params = $req_params('13911129867');
+        $resp = $proxy->send($url, $params);
+        if(empty($resp)) {
+            $x = 1;
+        }
+    }
+
+}

+ 108 - 0
test/refill/TestRefill.php

@@ -0,0 +1,108 @@
+<?php
+/**
+ *   TestRefill.php
+ *   stanley-king
+ *   2024/4/9
+ *   PhpStorm
+ *   PHPProject
+ */
+
+use PHPUnit\Framework\TestCase;
+
+define('APP_ID', 'test');
+define('BASE_ROOT_PATH', str_replace('/test/refill', '', dirname(__FILE__)));
+require_once(BASE_ROOT_PATH . '/global.php');
+require_once(BASE_CORE_PATH . '/lrlz.php');
+require_once(BASE_ROOT_PATH . '/fooder.php');
+
+require_once(BASE_HELPER_PATH . '/refill/XYZRefillFactory.php');
+require_once(BASE_HELPER_PATH . '/refill_proxy.php');
+
+
+class TestRefill extends TestCase
+{
+    public static function setUpBeforeClass(): void
+    {
+        Base::run_util();
+    }
+
+    private function getProvider($name, $type = 'RefillPhone',$cfgs = [])
+    {
+        $file = BASE_HELPER_RAPI_PATH . "/$name/{$type}.php";
+        if (!file_exists($file)) {
+            Log::record("provider api file=$file not exist.", Log::DEBUG);
+            return false;
+        } else {
+            require_once($file);
+            Log::record("file=$file load success.", Log::DEBUG);
+        }
+
+        $class_name = "refill\\{$name}\\{$type}";
+        if (class_exists($class_name, false)) {
+            $caller = new $class_name($cfgs);
+            return $caller;
+        } else {
+            $error = "Base Error: class $class_name isn't exists!";
+            Log::record($error, Log::ERR);
+            return false;
+        }
+    }
+
+    private function make_sn()
+    {
+        return mt_rand(1000, 9999)
+            . sprintf('%010d', time())
+            . sprintf('%06d', (float)microtime() * 1000000);
+    }
+
+    public function testRsanfang()
+    {
+        $provider = $this->getProvider('rsanfang','RefillPhone' ,['store_id' => 396]);
+        $resp = $provider->add(13911129867, 7, 100, [
+            'order_sn' => $this->make_sn(),
+            'goods_id' => 9107,
+            'product_code' => 'XYZ_QUERY_001'
+        ]);
+    }
+
+    public function testAddQueryTimes()
+    {
+        $times = 10000000;
+        $mchid = 10165;
+
+        $model_merchant = Model('merchant');
+        $data = [
+            'query_total_times' => ['exp', "query_total_times+$times"],
+            'query_left_times'  => ['exp', "query_left_times+$times"]
+        ];
+        $ret = $model_merchant->editMerchant($data, ['mchid' => $mchid]);
+        Log::record("ret=$ret",Log::DEBUG);
+    }
+
+    public function testAddThird()
+    {
+        $req_params = function ($phone, string $order_sn, $product_code)
+        {
+            $params['act'] = 'refill';
+            $params['op'] = 'add_third';
+            $params['product_code'] = $product_code;
+            $params['mchid'] = 10165;
+            $params['cardno'] = $phone;
+            $params['order_sn'] = $order_sn;
+            $params['quantity'] = 1;
+            $params['notifyurl'] = 'http://192.168.3.104:8300/mobile/callback/card_query.php';
+            return $params;
+        };
+
+        $proxy = new refill_proxy("9a24e56d79a3653f99895e0e3af4dea9");
+
+        $order_sn = $this->make_sn();
+        $params = $req_params('13911129867', $order_sn,'XYZ_QUERY_001');
+        $resp = $proxy->send('http://192.168.3.104:8300/mobile/index.php', $params);
+        if(empty($resp)) {
+            $x = 1;
+        }
+    }
+
+
+}