Quellcode durchsuchen

处理test/TestRefill.php文件冲突

zhaoming vor 1 Jahr
Ursprung
Commit
97c5812fde

+ 72 - 47
admin/control/arw_monitor.php

@@ -13,60 +13,85 @@ class arw_monitorControl extends SystemControl
         $servers = $config['server'];
         $ins = Cache::getInstance('cacheredis');
         $name = 'disk_monitor';
-        $hash_data = $ins->hget($name, '');
-        $result = [];
-        $cur_time = time();
+        $monitoring_data = $ins->hget($name, '');
         $ago_time = 0;
 
-        $time_check = function($stat_str, $cur_time) {
-            $value = explode('-', $stat_str);
-            $value = "$value[0]-$value[1]-$value[2] $value[3]:$value[4]:$value[5]";
-            $stat_time = strtotime($value);
-            if($stat_time == false) return false;
+        $convert_time = function ($stime)
+        {
+            $val = explode('-', $stime);
+            $val = "$val[0]-$val[1]-$val[2] $val[3]:$val[4]:$val[5]";
+            $time = strtotime($val);
+            return date("Y-m-d H:i:s", $time);
+        };
+
+        $calc_bytes = function ($str_capacity)
+        {
+            $total = strtolower(trim($str_capacity));
+            $last = $total[-1];
 
-            $check_seconds = 1800;
-            $diff_time = $cur_time - $stat_time;
-            if($diff_time > $check_seconds) {
-                return false;
-            }else{
-                return $diff_time;
+            $total = intval($total);
+            if($last == 't') {
+                $per = 1024 * 1024 * 1024 * 1024;
+            }
+            elseif($last == 'g') {
+                $per = 1024 * 1024 * 1024;
+            }
+            elseif($last == 'm') {
+                $per = 1024 * 1024;
+            }
+            elseif($last == 'k') {
+                $per = 1024;
             }
+            else {
+                $per = 1;
+            }
+
+            return $total * $per;
         };
-        foreach ($servers as $ip => $server_name) {
-            $hash_str = $hash_data[$ip];
-            $item = [];
-            if (!empty($hash_str)) {
-                $hash_str = str_replace('\t', "", $hash_str);
-                $hash_str = ltrim($hash_str, '#');
-                $arrs = explode('#', $hash_str);
-                foreach ($arrs as $arr) {
-                    $data = explode(':', $arr);
-                    $key = ltrim($data[0], '_');
-                    $value = $data[1];
-                    if ($key == 'cur_time') {
-                        $diff_time = $time_check($value, $cur_time);
-                        if ($diff_time == false) {
-                            $value = '定时更新未正常工作';
-                        } else {
-                            $ago_time = $diff_time;
-                        }
-                    } elseif (strpos($key, 'dev') !== false) {
-                        $key = str_replace('_', "/", $key);
-                        $value = explode(',', $value);
-                        if(strpos($value[0], 'T') !== false) $value[0] = $value[0] * 1024 . 'G';
-                        if(strpos($value[1], 'T') !== false) $value[1] = $value[1] * 1024 . 'G';
-                        $percent = $value[1]/$value[0]*100;
-                        $value = "{$value[1]}/{$value[0]} (" . round($percent,2). "%)";
-                    } else {
-                        $key = str_replace('_', "/", $key);
-                        $value = rtrim($value, '.');
-                    }
-                    $item[$key] = $value;
-                    ksort($item);
+
+        $format_detail = function ($detail) use ($calc_bytes)
+        {
+            $detail = trim($detail);
+            $items = explode(',',$detail);
+            if(count($items) < 2) {
+                return $detail;
+            }
+
+            $total = strtolower(trim($items[0]));
+            $avaliable = strtolower(trim($items[1]));
+
+            $ratio = $calc_bytes($avaliable) / $calc_bytes($total);
+
+            $ratio = number_format($ratio * 100,2);
+
+            return "$avaliable / $total = $ratio%";
+        };
+
+        $disk_monitoring_data = function ($str)  use ($convert_time,$format_detail)
+        {
+            $result = [];
+            $details = preg_split("/[\s#]+/", $str, 0, PREG_SPLIT_DELIM_CAPTURE);
+            foreach ($details as $item)
+            {
+                $data = explode(':', $item);
+                if(count($data) != 2) continue;
+                $dir = trim($data[0]);
+                if($dir == 'cur_time') {
+                    $val = $convert_time(trim($data[1]));
+                } else {
+                    $val = $format_detail($data[1]);
                 }
+
+                $result[$dir] =  $val;
             }
-            $item["server_name"] = $server_name;
-            $result[$ip] = $item;
+            return $result;
+        };
+
+        foreach ($servers as $ip => $server_name) {
+            $hash_str = $monitoring_data[$ip];
+            $details = $disk_monitoring_data($hash_str);
+            $details["server_name"] = $server_name;
+            $result[$ip] = $details;
         }
         Tpl::output('data', $result);
         Tpl::output('ago_time', $this->elapse_time($ago_time));

+ 13 - 7
admin/templates/default/arw.monitor.php

@@ -3,6 +3,12 @@
     th {
         width: 10px;
     }
+    .width-ten {
+        width: 10%;
+    }
+    .width-fifteen{
+        width: 15%;
+    }
 </style>
 
 <?php defined('InShopNC') or exit('Access Invalid!'); ?>
@@ -34,14 +40,14 @@
         <thead>
         <tr class="thead">
             <th class="align-left">ip</th>
-            <th class="align-center">类型</th>
-            <th class="align-center" style="width: 15%">更新时间</th>
-            <th class="align-center">/mnt</th>
-            <th class="align-center">/data</th>
-            <th class="align-center">logs</th>
+            <th class="align-center width-ten">类型</th>
+            <th class="align-center width-fifteen">更新时间</th>
+            <th class="align-center width-fifteen">/mnt</th>
+            <th class="align-center width-fifteen">/data</th>
+            <th class="align-center width-fifteen">logs</th>
             <th class="align-center">/stdata</th>
-            <th class="align-center">data/mysqlundo</th>
-            <th class="align-center">mysql/xyzshop</th>
+            <th class="align-center width-fifteen">data/mysqlundo</th>
+            <th class="align-center width-fifteen">mysql/xyzshop</th>
         </thead>
         <tbody id="tbody">
         <?php if (count($output['data']) > 0) { ?>

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

@@ -2676,6 +2676,36 @@ $wangcxdzjfeiy_phone = ['name' => 'wangcxdzjfeiy', 'store_id' => 109, 'qualitys'
     'official_sn' => true, 'refill_type' => 'api'];
 
 
+$fulunoy_phone = ['name' => 'fulunoy', 'store_id' => 110, 'qualitys' => '2',
+    'amount' => [
+        10 => [
+            ['goods_id' => 7193, 'price' => 10, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom'],
+        ],
+        20 => [
+            ['goods_id' => 7194, 'price' => 20, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom'],
+        ],
+        30 => [
+            ['goods_id' => 7195, 'price' => 30, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom'],
+        ],
+        50 => [
+            ['goods_id' => 7196, 'price' => 50, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom'],
+        ],
+        100 => [
+            ['goods_id' => 7197, 'price' => 100, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom'],
+        ],
+        200 => [
+            ['goods_id' => 7198, 'price' => 200, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom'],
+        ],
+        300 => [
+            ['goods_id' => 7199, 'price' => 300, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom'],
+        ],
+        500 => [
+            ['goods_id' => 7200, 'price' => 500, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom'],
+        ]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
+
 $phone_providers = [
     ['name' => 'yezi_hf', 'cfg' => $yezi_hf_phone],
     ['name' => 'yezia', 'cfg' => $yezia_phone],
@@ -2763,6 +2793,7 @@ $phone_providers = [
     ['name' => 'wogoudianzijuan_fy', 'cfg' => $wogoudianzijuan_fy_phone],
     ['name' => 'wogoukongcfeiy', 'cfg' => $wogoukongcfeiy_phone],
     ['name' => 'wangcxdzjfeiy', 'cfg' => $wangcxdzjfeiy_phone],
+    ['name' => 'fulunoy', 'cfg' => $fulunoy_phone],
 ];
 
 $config['phone_providers'] = $phone_providers;

+ 21 - 2
helper/refill/RefillBase.php

@@ -90,11 +90,30 @@ class RefillBase
         return true;
     }
 
-    private function risksn_check($refill_info,$org_official_sn)
+    private function risksn_check($refill_info, $order_info, $org_official_sn)
     {
+        $in_exclude = function ($store_id)
+        {
+            $store_id = intval($store_id);
+            if($store_id <= 0) {
+                return false;
+            }
+
+            global $config;
+            $risk_official_sn = $config['risk_official_sn'] ?? [];
+            $exclude_stores = $risk_official_sn['exclude_stores'] ?? [];
+
+            return in_array($store_id,$exclude_stores);
+        };
+
         $card_type = intval($refill_info['card_type']);
         $chk_types = [mtopcard\ChinaMobileCard , mtopcard\ChinaUnicomCard , mtopcard\ChinaTelecomCard];
 
+        $store_id = intval($order_info['store_id']);
+        if($in_exclude($store_id)) {
+            return false;
+        }
+
         if(!in_array($card_type,$chk_types)) {
             return false;
         }
@@ -191,7 +210,7 @@ class RefillBase
                     'order_id' => $refill_info['order_id'],
                     'official_sn' => $refill_info['official_sn']];
 
-                if ($this->risksn_check($refill_info, $official_sn)) {
+                if ($this->risksn_check($refill_info, $order_info, $official_sn)) {
                     $tran->commit();
                     QueueClient::async_push("OnRiskSN", $params, 1);
                     return false;

+ 76 - 0
helper/refill/api/zy/fulunoy/RefillCallBack.php

@@ -0,0 +1,76 @@
+<?php
+namespace refill\fulunoy;
+
+require_once(BASE_HELPER_RAPI_PATH . '/fulunoy/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];
+        }
+    }
+}

+ 161 - 0
helper/refill/api/zy/fulunoy/RefillPhone.php

@@ -0,0 +1,161 @@
+<?php
+
+namespace refill\fulunoy;
+
+require_once(BASE_HELPER_RAPI_PATH . '/fulunoy/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, string $order_sn)
+    {
+        $params['act'] = 'refill';
+        $params['op'] = 'add';
+        $params['mchid'] = config::MCH_ID;
+        $params['cardno'] = $phone;
+        $params['amount'] = $amount;
+        $params['order_sn'] = $order_sn;
+        $params['notifyurl'] = config::NOTIFY_URL;
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
+    {
+        $params = $this->req_params($card_no, $amount, $params['order_sn']);
+        $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, ncPriceFormat($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/fulunoy/api.txt

@@ -0,0 +1,7 @@
+https://admin.xyzshops.cn/merchant/#/login
+
+fulunoy
+de2_io3ty
+
+10472
+b639c0d10c6d55c809ed8fe02837c024

+ 11 - 0
helper/refill/api/zy/fulunoy/config.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace refill\fulunoy;
+
+class config
+{
+    const ORDER_URL = 'https://www.xyzshops.cn/mobile/index.php';
+    const MCH_ID = 10472;
+    const KEY = 'b639c0d10c6d55c809ed8fe02837c024';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_fulunoy.php";
+}

+ 4 - 0
mobile/callback/refill_fulunoy.php

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

+ 129 - 0
test/TestArwMonitor.php

@@ -0,0 +1,129 @@
+<?php
+use PHPUnit\Framework\TestCase;
+
+define('APP_ID', 'test');
+define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
+
+require_once(BASE_ROOT_PATH . '/global.php');
+require_once(BASE_CORE_PATH . '/lrlz.php');
+require_once(BASE_ROOT_PATH . '/fooder.php');
+
+class TestArwMonitor extends TestCase
+{
+    public static function setUpBeforeClass(): void
+    {
+        Base::run_util();
+    }
+
+
+    public function testMonitor()
+    {
+        $str = '/mnt:7.3T,5.7T#/dev/shm:28G,28G#/run/lock:5.0M,5.0M#cur_time:2023-08-24-16-08-02#/home/dongpeng:687M      .#/data:7.3T,6.8T';
+        $convert_time = function ($stime)
+        {
+            $val = explode('-', $stime);
+            $val = "$val[0]-$val[1]-$val[2] $val[3]:$val[4]:$val[5]";
+            $time = strtotime($val);
+            return $time;
+        };
+
+        $calc_bytes = function ($str_capacity)
+        {
+            $total = strtolower(trim($str_capacity));
+            $last = $total[-1];
+
+            $total = intval($total);
+            if($last == 't') {
+                $per = 1024 * 1024 * 1024 * 1024;
+            }
+            elseif($last == 'g') {
+                $per = 1024 * 1024 * 1024;
+            }
+            elseif($last == 'm') {
+                $per = 1024 * 1024;
+            }
+            elseif($last == 'k') {
+                $per = 1024;
+            }
+            else {
+                $per = 1;
+            }
+
+            return $total * $per;
+        };
+
+        $format_detail = function ($detail) use ($calc_bytes)
+        {
+            $detail = trim($detail);
+            $items = explode(',',$detail);
+            if(count($items) < 2) {
+                return $detail;
+            }
+
+            $total = strtolower(trim($items[0]));
+            $avaliable = strtolower(trim($items[1]));
+
+            $ratio = $calc_bytes($avaliable) / $calc_bytes($total);
+
+            $ratio = number_format($ratio * 100,2);
+
+            return "$avaliable / $total = $ratio%";
+        };
+
+        $disk_monitoring_data = function ($str)  use ($convert_time,$format_detail)
+        {
+            $result = [];
+            $details = preg_split("/[\s#]+/", $str, 0, PREG_SPLIT_DELIM_CAPTURE);
+            foreach ($details as $item)
+            {
+                $data = explode(':', $item);
+                if(count($data) != 2) continue;
+                $dir = trim($data[0]);
+                if($dir == 'cur_time') {
+                    $val = $convert_time(trim($data[1]));
+                } else {
+                    $val = $format_detail($data[1]);
+                }
+
+                $result[$dir] =  $val;
+            }
+            return $result;
+        };
+
+        $details = $disk_monitoring_data($str);
+
+
+
+        $cur_time = $convert_time('2023-08-24-16-08-02');
+
+
+
+
+        $arr = "/mnt:7.3T,5.7T";
+        $data = preg_split("/[\s:]+/", $arr, 0, PREG_SPLIT_DELIM_CAPTURE);
+        $key = ltrim($data[0], '/');
+        $value = $data[1];
+
+//        global $config;
+//        $servers = $config['server'];
+//        $ins = Cache::getInstance('cacheredis');
+//        $name = 'disk_monitor';
+//        $disk_monitoring_data = $ins->hget($name, '');
+//        $result = [];
+//        $cur_time = time();
+//        $ago_time = 0;
+//
+//        array_map(function ($ip, $server_name) use($disk_monitoring_data) {
+//            $hash_str = $disk_monitoring_data[$ip];
+//            $item = [];
+//            if(!empty($hash_str)){
+//                $hash_str = str_replace('\t', "", $hash_str);
+//                $arrs = explode('#', $hash_str);
+//            }
+//        }, $servers);
+    }
+
+
+
+}
+//docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestAccount::testLog)( .*)?$/" --test-suffix TestAccount.php /var/www/html/test

+ 11 - 0
test/TestRefill.php

@@ -5252,6 +5252,17 @@ class TestRefill extends TestCase
         [$succ, $val] = $provider->balance();
     }
 
+    public function testFulunoy_Balance()
+    {
+        $provider = $this->getProvider('fulunoy');
+        [$succ, $val] = $provider->balance();
+    }
+
+    public function testFulunoy_Add()
+    {
+        $provider = $this->getProvider("fulunoy");
+        $resp = $provider->add(13911129867, 4, 10, ['order_sn' => $this->make_sn()]);
+    }
 }
 
 //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testLoadBlack)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test

+ 16 - 8
util/arw_monitor.sh

@@ -13,9 +13,11 @@ function df_check() {
   # shellcheck disable=SC2068
   for dir in ${df_dirs[@]}
   do
-    ret=$(df -h | grep $dir | awk 'BEGIN{OFS=","}{print $2,$4}')
-    key=${dir////_}
-    reports[$key]=$ret
+    if [ -d "$dir" ]; then
+      ret=$(df -h | grep $dir | awk 'BEGIN{OFS=","}{print $2,$4}')
+      key=${dir}
+      reports[$key]=$ret
+    fi
   done
 }
 
@@ -23,10 +25,12 @@ function du_check() {
   # shellcheck disable=SC2068
   for dir in ${du_dirs[@]}
   do
-    cd $dir
-    ret=$(du -h -d 0)
-    key=${dir////_}
-    reports[$key]=$ret
+    if [ -d "$dir" ]; then
+      cd $dir
+      ret=$(du -h -d 0)
+      key=${dir}
+      reports[$key]=$ret
+    fi
   done
 }
 
@@ -36,7 +40,11 @@ du_check
 str_report=''
 for key in $(echo ${!reports[*]})
 do
-    str_report="$str_report#$key:${reports[$key]}"
+    if [ ! -n "$str_report" ]; then
+      str_report="$key:${reports[$key]}"
+    else
+      str_report="$str_report#$key:${reports[$key]}"
+    fi
 done
 
 redis_host=$XYZ_REDIS_HOST