xiaoyu 3 年 前
コミット
dee7a2dd28

+ 40 - 10
data/config/win/refill.ini.php

@@ -1028,31 +1028,60 @@ $moxj_fs_phone = ['name' => 'moxj_fs', 'store_id' => 65, 'qualitys' => '1',
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
-$zanzanquick_phone = ['name' => 'zanzanquick', 'store_id' => 65, 'qualitys' => '2',
+$zanzanquick_phone = ['name' => 'zanzanquick', 'store_id' => 66, 'qualitys' => '1',
     'amount' => [
         10 => [
-            ['goods_id' => 6652, 'price' => 9.4, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
+            ['goods_id' => 6652, 'price' => 9.4, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
         ],
         20 => [
-            ['goods_id' => 6653, 'price' => 18.8, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
+            ['goods_id' => 6653, 'price' => 18.8, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
         ],
         30 => [
-            ['goods_id' => 6654, 'price' => 28.2, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
+            ['goods_id' => 6654, 'price' => 28.2, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
         ],
         50 => [
-            ['goods_id' => 6655, 'price' => 47, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
+            ['goods_id' => 6655, 'price' => 47, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
         ],
         100 => [
-            ['goods_id' => 6656, 'price' => 94, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
+            ['goods_id' => 6656, 'price' => 94, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
         ],
         200 => [
-            ['goods_id' => 6657, 'price' => 188, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
+            ['goods_id' => 6657, 'price' => 188, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
         ],
         300 => [
-            ['goods_id' => 6658, 'price' => 282, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
+            ['goods_id' => 6658, 'price' => 282, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
         ],
         500 => [
-            ['goods_id' => 6659, 'price' => 470, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
+            ['goods_id' => 6659, 'price' => 470, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
+        ],
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
+$fengyeman_phone = ['name' => 'fengyeman', 'store_id' => 67, 'qualitys' => '5',
+    'amount' => [
+        10 => [
+            ['goods_id' => 6660, 'price' => 8.9, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
+        ],
+        20 => [
+            ['goods_id' => 6661, 'price' => 17.8, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
+        ],
+        30 => [
+            ['goods_id' => 6662, 'price' => 26.7, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
+        ],
+        50 => [
+            ['goods_id' => 6663, 'price' => 44.5, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
+        ],
+        100 => [
+            ['goods_id' => 6664, 'price' => 89, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
+        ],
+        200 => [
+            ['goods_id' => 6665, 'price' => 178, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
+        ],
+        300 => [
+            ['goods_id' => 6666, 'price' => 267, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
+        ],
+        500 => [
+            ['goods_id' => 6667, 'price' => 445, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
         ],
     ],
     'official_sn' => true, 'refill_type' => 'api'];
@@ -1098,7 +1127,8 @@ $phone_providers = [
     ['name' => 'yinteng', 'cfg' => $yinteng_phone],
     ['name' => 'moxj', 'cfg' => $moxj_phone],
     ['name' => 'moxj_fs', 'cfg' => $moxj_fs_phone],
-    ['name' => 'zanzanquick', 'cfg' => $zanzanquick_phone]
+    ['name' => 'zanzanquick', 'cfg' => $zanzanquick_phone],
+    ['name' => 'fengyeman', 'cfg' => $fengyeman_phone]
 ];
 $config['phone_providers'] = $phone_providers;
 

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

@@ -1057,6 +1057,35 @@ $zanzanquick_phone = ['name' => 'zanzanquick', 'store_id' => 66, 'qualitys' => '
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$fengyeman_phone = ['name' => 'fengyeman', 'store_id' => 67, 'qualitys' => '6',
+    'amount' => [
+        10 => [
+            ['goods_id' => 6660, 'price' => 8.9, 'quality' => 6, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
+        ],
+        20 => [
+            ['goods_id' => 6661, 'price' => 17.8, 'quality' => 6, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
+        ],
+        30 => [
+            ['goods_id' => 6662, 'price' => 26.7, 'quality' => 6, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
+        ],
+        50 => [
+            ['goods_id' => 6663, 'price' => 44.5, 'quality' => 6, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
+        ],
+        100 => [
+            ['goods_id' => 6664, 'price' => 89, 'quality' => 6, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
+        ],
+        200 => [
+            ['goods_id' => 6665, 'price' => 178, 'quality' => 6, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
+        ],
+        300 => [
+            ['goods_id' => 6666, 'price' => 267, 'quality' => 6, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
+        ],
+        500 => [
+            ['goods_id' => 6667, 'price' => 445, 'quality' => 6, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']
+        ],
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -1098,7 +1127,8 @@ $phone_providers = [
     ['name' => 'yinteng', 'cfg' => $yinteng_phone],
     ['name' => 'moxj', 'cfg' => $moxj_phone],
     ['name' => 'moxj_fs', 'cfg' => $moxj_fs_phone],
-    ['name' => 'zanzanquick', 'cfg' => $zanzanquick_phone]
+    ['name' => 'zanzanquick', 'cfg' => $zanzanquick_phone],
+    ['name' => 'fengyeman', 'cfg' => $fengyeman_phone]
 ];
 $config['phone_providers'] = $phone_providers;
 

+ 51 - 0
helper/refill/api/xyz/fengyeman/RefillCallBack.php

@@ -0,0 +1,51 @@
+<?php
+namespace refill\fengyeman;
+
+require_once(BASE_HELPER_RAPI_PATH . '/fengyeman/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)
+    {
+        $content  = $params['order_id'] . $params['out_order_id'] . config::MCHID . $params['tel'] . $params['price'];
+        $content .= $params['status'] . config::KEY;
+        return md5($content);
+    }
+
+    //[$order_id, $success, $can_try, $need_handle]
+    public function notify($params)
+    {
+        $status = intval($params['status']);
+        $order_sn = $params['order_id'];
+        $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'];
+        
+        $data['official_sn'] = strtolower($params['out_order_id']) == 'null' ? '' : $params['out_order_id'];
+
+        if ($status === 1) {
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false,true];
+        }
+        elseif (in_array($status, [2,3])) {
+            return [$order_id, false, true,true];
+        }
+        else {
+            return [$order_id, false, false,false];
+        }
+    }
+}

+ 103 - 0
helper/refill/api/xyz/fengyeman/RefillPhone.php

@@ -0,0 +1,103 @@
+<?php
+
+namespace refill\fengyeman;
+
+require_once(BASE_HELPER_RAPI_PATH . '/fengyeman/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['mchid'] = config::MCHID;
+        $params['tel'] = $phone;
+        $params['orderid'] = $order_sn;
+        $params['price'] = $amount;
+        $params['teltype'] = config::operator[$card_type];
+        $params['timeout'] = config::TIMEOUT;
+        $params['notify'] = config::NOTIFY_URL;
+        $params['time'] = time();
+        $params['rand'] = rand(100000,999999);
+
+        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['order_id'], false];
+            } else {
+                return [false, $resp['msg'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['mchid'] = config::MCHID;
+        $params['orderid'] = $refill_info['order_sn'];
+        $content = $params['mchid'] . $params['orderid'] . config::KEY;
+        $params['sign'] = md5($content);
+
+        $resp = http_request(config::QUERY_URL, $params , 'POST' , false);
+        if (empty($resp)) {
+            return [false, '系统错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '系统错误'];
+            }
+            elseif ($resp['code'] == 100)
+            {
+                if ($resp['status'] == 3 && $resp['arrival'] == 2) {
+                    $order_state = ORDER_STATE_SUCCESS;
+                    $save['official_sn'] = strtolower($resp['out_order_id']) == 'null' ? '' : $resp['out_order_id'];
+                    Model('refill_order')->edit($refill_info['order_id'], $save);
+                } elseif ($resp['status'] == 4) {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif (in_array($resp['status'] , [1 , 2])) {
+                    $order_state = ORDER_STATE_SEND;
+                } else {
+                    return [false, "msg:{$resp['msg']},status:{$resp['status']},arrival:{$resp['arrival']}"];
+                }
+
+                return [true, $order_state];
+            }
+            else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $content  = $params['mchid'] . $params['tel'] . $params['price'] . $params['orderid'] . $params['teltype'] . $params['timeout'] . $params['notify'];
+        $content .= $params['time'] . $params['rand'] . config::KEY;
+        return md5($content);
+    }
+}

+ 7 - 0
helper/refill/api/xyz/fengyeman/api.txt

@@ -0,0 +1,7 @@
+话费慢充系统 对接资料:
+登录地址:http://103.66.58.75:9998/dist/   
+网关地址:http://103.66.58.75:9998/api/pay/telpay
+商户名称:椰子电子
+商户ID:HF67a65_10008
+商户密码:a12345678
+商户密钥:8dd6f67a65b806fbfb74dde74c5f1550

+ 20 - 0
helper/refill/api/xyz/fengyeman/config.php

@@ -0,0 +1,20 @@
+<?php
+namespace refill\fengyeman;
+
+use mtopcard;
+class config
+{
+    const ORDER_URL = 'http://103.66.58.75:9998/api/pay/telpay';
+    const QUERY_URL = 'http://103.66.58.75:9998/api/pay/telpay/query';
+
+    const MCHID = 'HF67a65_10008';
+    const KEY = '8dd6f67a65b806fbfb74dde74c5f1550';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_fengyeman.php";
+    const ExtHeaders = ['Content-Type: application/x-www-form-urlencoded'];
+    const TIMEOUT = 21600;
+    const operator = [
+        mtopcard\ChinaMobileCard  => 0,
+        mtopcard\ChinaUnicomCard  => 1,
+        mtopcard\ChinaTelecomCard => 2
+    ];
+}

BIN
helper/refill/api/xyz/fengyeman/tel.pdf


+ 1 - 1
helper/refill/api/xyz/moxj_fs/account.txt

@@ -1,6 +1,6 @@
 http://150.107.3.58/index.html
 账号密码
 yezi
-123456yezi
+123456
 秘钥a287ccee4bb064445b8fb7ca743d1dad
 ID58

+ 4 - 0
mobile/callback/refill_fengyeman.php

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

+ 442 - 442
test/TestAddData.php

@@ -1,442 +1,442 @@
-<?php
-declare(strict_types=0);
-
-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');
-
-require_once(BASE_HELPER_PATH . '/mcard/mcard.php');
-require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
-require_once(BASE_HELPER_PATH . '/util_helper.php');
-require_once(BASE_HELPER_PATH . '/order_helper.php');
-require_once(BASE_HELPER_PATH . '/bonus_helper.php');
-require_once(BASE_HELPER_PATH . '/vrorder_helper.php');
-require_once(BASE_HELPER_PATH . '/PHPExcel/PHPExcel.php');
-require_once (BASE_CORE_PATH . '/framework/function/http.php');
-
-use PHPUnit\Framework\TestCase;
-use function mtopcard\formatProvince;
-use const mtopcard\ProvinceList;
-
-class TestAddData extends TestCase
-{
-    const CardNoLength  = 16;
-    const CardKeyLength = 12;
-
-    public static function setUpBeforeClass(): void
-    {
-        Base::run_util();
-    }
-
-    private function addCard($mod_card,$car_no,$card_key,$card_type,$amount)
-    {
-        $mod_card->addCard(['card_no' => $car_no,'card_key' => $card_key,'card_type' => $card_type,'amount' => $amount]);
-    }
-
-    public function testRegin()
-    {
-        $card_type = mtopcard\card_type('13911129867',$regin);
-    }
-
-    public function testCardtype()
-    {
-        $url = "https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=13911129867";
-        $resp = http_request($url);  //获取API返回 的数据
-        if(empty($resp)) return false;
-
-        $resp = mb_convert_encoding($resp, 'UTF-8', 'UTF-8,GBK,GB2312,BIG5'); //解决中文乱码
-        $datas = explode('=', $resp);
-        if(count($datas) == 2)
-        {
-            $body = trim($datas[1]);
-            if(preg_match_all("/(\w+):'([^']+)/", $body, $m)) {
-                $res = array_combine($m[1], $m[2]);
-
-                $province = formatProvince($res['province']);
-                $region = array_search($province,ProvinceList);
-                return $res;
-            }
-        }
-    }
-
-    public function testFSheng()
-    {
-        $data = 'a:3:{i:4;s:17:"10,11,15,16,25,28";i:5;i:-1;i:6;i:-1;}';
-        $regins = [];
-        $tmp = unserialize($data);
-        if(!empty($tmp))
-        {
-            foreach ($tmp as $card_type => $sregions)
-            {
-                $regins = explode(',',$sregions);
-                if(!empty($regins)) {
-                    $regins[$card_type] = $regins;
-                }
-            }
-        }
-    }
-
-    public function testReadCSVFile()
-    {
-        $items = [
-            ['file' => 'phone-100.csv','card_type' => mtopcard\PhoneCardPaper, 'value' => 100],
-            ['file' => 'oil-100.csv','card_type'   => mtopcard\OilCardPaper, 'value' => 100],
-            ['file' => 'oil-200.csv','card_type'   => mtopcard\OilCardPaper, 'value' => 200],
-            ['file' => 'oil-500.csv','card_type'   => mtopcard\OilCardPaper, 'value' => 500],
-            ['file' => 'oil-1000.csv','card_type'  => mtopcard\OilCardPaper, 'value' => 1000],
-        ];
-
-        $mod_card = Model('card_key');
-        foreach ($items as $item)
-        {
-            $file = BASE_DATA_PATH . '/cards/' . $item['file'];
-            $amount = $item['value'];
-            $card_type = $item['card_type'];
-
-            $fn = fopen($file,"r");
-            if(empty($fn)) {
-                Log::record("Open File {$item['file']} error.",Log::ERR);
-                break;
-            }
-            else {
-                Log::record("{$item['file']} start woring",Log::DEBUG);
-            }
-
-            while(! feof($fn))  {
-                $line = trim(fgets($fn));
-                $results = explode(',',$line);
-                if(empty($results)) {
-                    continue;
-                }
-                elseif(count($results) == 2) {
-                    $card_no = trim($results[0]);
-                    $card_key = trim($results[1]);
-                }
-                elseif(count($results) == 3) {
-                    $card_no = trim($results[1]);
-                    $card_key = trim($results[2]);
-                }
-                else {
-                    Log::record("分析数据失败:{$line}",Log::ERR);
-                    continue;
-                }
-
-                $this->addCard($mod_card,$card_no,$card_key,$card_type,$amount);
-            }
-
-            fclose($fn);
-        }
-
-        Log::record("All cards has been add to database.",Log::DEBUG);
-    }
-
-    private function addFile($file)
-    {
-        $filename = BASE_DATA_PATH . "/cards/{$file}";
-        if(!file_exists($filename)) {
-            Log::record("{$file} not exists.",Log::ERR);
-            return false;
-        }
-
-        $mod_card = Model('card_key');
-
-        $fileType = PHPExcel_IOFactory::identify($filename);
-        $objReader = PHPExcel_IOFactory::createReader($fileType);
-        $objPHPExcel = $objReader->load($filename);
-
-        Log::record("{$file} begin....",Log::DEBUG);
-
-        foreach ($objPHPExcel->getWorkSheetIterator() as $sheet)
-        {
-            $title = strtolower($sheet->getTitle());
-            Log::record("{$file} - {$title} start....",Log::DEBUG);
-
-            [$type,$amount,$id] = explode('-',$title);
-            Log::record("type = {$type} amount = {$amount}",Log::DEBUG);
-
-            if($type == 'p') {
-                $card_type = mtopcard\PhoneCardPaper;
-            }
-            elseif($type == 'o') {
-                $card_type = mtopcard\OilCardPaper;
-            }
-            else {
-                Log::record("{$filename} sheet {$title} name type error.",Log::ERR);
-                return false;
-            }
-
-            if($amount <= 0) {
-                Log::record("{$filename} sheet {$title} name amount error.",Log::ERR);
-                return false;
-            }
-
-            foreach ($sheet->getRowIterator() as $row)
-            {
-                $index = $row->getRowIndex();
-                if ($index < 2) continue;
-
-                $datas = [];
-                foreach ($row->getCellIterator() as $cell) {
-                    $data = $cell->getValue();
-                    $datas[] = $data;
-                }
-
-                if(empty($datas[1]) || empty($datas[2])) {
-                    continue;
-                }
-
-                $card_no = trim($datas[1]);
-                $card_key = trim($datas[2]);
-                if($this->check_cardno($card_no) && $this->check_cardkey($card_key)) {
-                    $this->addCard($mod_card,$card_no,$card_key,$card_type,$amount);
-                }
-                else {
-                    Log::record("{$card_no} {$card_key}",Log::ERR);
-                }
-            }
-        }
-        Log::record("{$file} end....",Log::DEBUG);
-        return true;
-    }
-
-    private function check_cardno($card_no)
-    {
-        $count = self::CardNoLength;
-        return preg_match("/^\d{{$count}}$/i",$card_no) > 0;
-    }
-
-    private function check_cardkey($card_no)
-    {
-        $count = self::CardKeyLength;
-        return preg_match("/^[a-z0-9]{{$count}}$/",$card_no) > 0;
-    }
-
-    public function testAddCradFromExecl()
-    {
-        $files = ['lm-1.xlsx','by-1.xlsx'];
-        foreach ($files as $file) {
-            $this->addFile($file);
-        }
-    }
-
-    public function testCancelOrder()
-    {
-        //2020-08-20 处理了一些订单。
-        $card_nos = ['1900000000668434',
-            '1900000000668403',
-            '1900000000668402',
-            '1900000000668400',
-            '1900000000668398',
-            '1900000000668399',
-            '1900000000668397',
-            '1900000000668396',
-            '1900000000668395',
-            '1900000000668394',
-            '1900000000668392',
-            '1900000000668390',
-            '1900000000668393',
-            '1900000000668387',
-            '1900000000668384',
-            '1900000000668327',
-            '1900000000040001',
-            '1900000000569005',
-            '1900000000264501',
-            '1900000000569004'];
-
-        $this->cancel_order($card_nos);
-    }
-
-    private function cancel_order($card_nos)
-    {
-        $mod_card = Model('card_key');
-        foreach ($card_nos as $card_no)
-        {
-            $items = $mod_card->field('*')->where(['card_no' => $card_no])->select();
-            $length = count($items);
-            if($length > 1) {
-                Log::record("有{$length}张卡号为{$card_no}的卡",Log::ERR);
-            }
-            elseif(empty($items)) {
-                Log::record("未找到{$card_no}的卡号",Log::ERR);
-            }
-            else {
-                $order_id = intval($items[0]['order_id']);
-                $order_info = Model('vr_order')->getOrderInfo(['order_id' => $order_id]);
-                $vr_logic = Logic('vr_order');
-                $result = $vr_logic->changeOrderStateCancel($order_info,'','管理员申请退款.');
-                Log::record("{$card_no} : {$result['state']}",Log::DEBUG);
-            }
-        }
-    }
-
-    public function testCardSequence()
-    {
-        $card_key = Model('card_key');
-
-        $count = 1000;
-        $i = 0;
-
-        $pairs = [];
-        $pair = ['start' => 0,'end' => 0];
-        while (true)
-        {
-            $start = $i * $count;
-            $items = $card_key->field('*')->order('card_no asc')->limit("{$start},{$count}")->select();
-            if(empty($items)) {
-                break;
-            }
-            $i++;
-
-            foreach ($items as $item)
-            {
-                try {
-                    $card_no = intval($item['card_no']);
-
-                    if($pair['end'] + 1 == $card_no) {
-                        $pair['end'] = $card_no;
-                    }
-                    else {
-                        $pairs[] = $pair;
-                        $pair = ['start' => $card_no,'end' => $card_no];
-                    }
-                }
-                catch (Exception $ex) {
-                    Log::record($ex->getMessage(),Log::DEBUG);
-                }
-            }
-        }
-
-        foreach ($pairs as $pair) {
-            $count = $pair['end'] - $pair['start'] + 1;
-            Log::record("{$pair['start']}------{$pair['end']} count = {$count}",Log::DEBUG);
-        }
-    }
-
-    public function testCardCheck()
-    {
-        $card_no = 1000113300023292731;
-        $topcard = Model('topcard');
-        $items = $topcard->get_cards($card_no - 500,$card_no + 500);
-    }
-
-    private function find_card($file,$card_no)
-    {
-        $fileType = PHPExcel_IOFactory::identify($file);
-        $objReader = PHPExcel_IOFactory::createReader($fileType);
-        $objPHPExcel = $objReader->load($file);
-
-        foreach ($objPHPExcel->getWorkSheetIterator() as $sheet)
-        {
-            foreach ($sheet->getRowIterator() as $row)
-            {
-                $index = $row->getRowIndex();
-                if ($index < 2) continue;
-
-                $datas = [];
-                foreach ($row->getCellIterator() as $cell) {
-                    $data = $cell->getValue();
-                    $datas[] = $data;
-                }
-
-                if(empty($datas[1]) || empty($datas[2])) {
-                    continue;
-                }
-
-                $no = trim($datas[1]);
-                if($no == $card_no) {
-                    return true;
-                }
-            }
-        }
-        return false;
-    }
-
-    public function testFindCard()
-    {
-        $finder = function ($card_no) {
-            $dir = BASE_DATA_PATH . "/cards/old/";
-            if ($dh = opendir($dir))
-            {
-                while (($file = readdir($dh)) !== false)
-                {
-                    $file_name = $dir . $file;
-                    $ext = pathinfo($file_name)['extension'];
-                    if($ext == 'xlsx') {
-                        $ret = $this->find_card($file_name,$card_no);
-                        if($ret) {
-                            Log::record("{$card_no} in {$file}",Log::DEBUG);
-                            break;
-                        }
-                    }
-                }
-                closedir($dh);
-            }
-        };
-
-        $cards = ['1900000000669244','1900000000669294','1900000000669344','1900000000669094','1900000000669144',
-            '1900000000669194','1900000000669394','1900000000669044','1900000000669994'];
-        foreach ($cards as $card_no) {
-            Log::record("{$card_no} is finding....",Log::DEBUG);
-            $finder($card_no);
-            Log::record("{$card_no} over.",Log::DEBUG);
-        }
-    }
-
-    public function testModifyCardno()
-    {
-        $changer = function ($start,$end) {
-            $card_key = Model('card_key');
-            $cond = ['_multi' => true, ['egt', $start], ['lt', $end]];
-            $items = $card_key->field('*')->where(['card_no&card_no' => $cond])->order('card_no asc')->select();
-            return $items;
-        };
-        $cards = $changer('1900000000699000','1900000000700000');
-
-        $card_key = Model('card_key');
-        foreach ($cards as $card) {
-            $card_id = intval($card['card_id']);
-            $card_no = intval($card['card_no']) - 30000;
-            $ret = $card_key->where(['card_id' => $card_id])->update(['card_no' => "{$card_no}"]);
-            Log::record("{$card_no} ret = {$ret}",Log::DEBUG);
-        }
-    }
-
-    public function testAddCard()
-    {
-        $finder = function ()
-        {
-            $files = [];
-            $dir = BASE_DATA_PATH . "/cards/";
-            $dh = opendir($dir);
-            if($dh)
-            {
-                while (($file = readdir($dh)) !== false)
-                {
-                    $file_name = $dir . $file;
-                    $ext = pathinfo($file_name)['extension'];
-                    if($ext == 'xlsx') {
-                        $files[] = $file;
-                    }
-                }
-
-                closedir($dh);
-            }
-            return $files;
-        };
-
-        $files = $finder();
-        foreach ($files as $file) {
-            $this->addFile($file);
-        }
-    }
-}
-
-//docker-compose -f ./docker-compose-dev.yml run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestAddData::testCancelOrder)( .*)?$/" --test-suffix TestAddData.php /var/www/html/test
-//docker-compose -f ./docker-compose-dev.yml run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestAddData::test20200821_addCard)( .*)?$/" --test-suffix TestAddData.php /var/www/html/test
-//docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestAddData::testAddCard)( .*)?$/" --test-suffix TestAddData.php /var/www/html/test
-
-//docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestAddData::testModifyCardno)( .*)?$/" --test-suffix TestAddData.php /var/www/html/test
-//docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testSuhcQuery)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test
-
+<?php
+declare(strict_types=0);
+
+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');
+
+require_once(BASE_HELPER_PATH . '/mcard/mcard.php');
+require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
+require_once(BASE_HELPER_PATH . '/util_helper.php');
+require_once(BASE_HELPER_PATH . '/order_helper.php');
+require_once(BASE_HELPER_PATH . '/bonus_helper.php');
+require_once(BASE_HELPER_PATH . '/vrorder_helper.php');
+require_once(BASE_HELPER_PATH . '/PHPExcel/PHPExcel.php');
+require_once (BASE_CORE_PATH . '/framework/function/http.php');
+
+use PHPUnit\Framework\TestCase;
+use function mtopcard\formatProvince;
+use const mtopcard\ProvinceList;
+
+class TestAddData extends TestCase
+{
+    const CardNoLength  = 16;
+    const CardKeyLength = 12;
+
+    public static function setUpBeforeClass(): void
+    {
+        Base::run_util();
+    }
+
+    private function addCard($mod_card,$car_no,$card_key,$card_type,$amount)
+    {
+        $mod_card->addCard(['card_no' => $car_no,'card_key' => $card_key,'card_type' => $card_type,'amount' => $amount]);
+    }
+
+    public function testRegin()
+    {
+        $card_type = mtopcard\card_type('13911129867',$regin);
+    }
+
+    public function testCardtype()
+    {
+        $url = "https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=13911129867";
+        $resp = http_request($url);  //获取API返回 的数据
+        if(empty($resp)) return false;
+
+        $resp = mb_convert_encoding($resp, 'UTF-8', 'UTF-8,GBK,GB2312,BIG5'); //解决中文乱码
+        $datas = explode('=', $resp);
+        if(count($datas) == 2)
+        {
+            $body = trim($datas[1]);
+            if(preg_match_all("/(\w+):'([^']+)/", $body, $m)) {
+                $res = array_combine($m[1], $m[2]);
+
+                $province = formatProvince($res['province']);
+                $region = array_search($province,ProvinceList);
+                return $res;
+            }
+        }
+    }
+
+    public function testFSheng()
+    {
+        $data = 'a:3:{i:4;s:17:"10,11,15,16,25,28";i:5;i:-1;i:6;i:-1;}';
+        $regins = [];
+        $tmp = unserialize($data);
+        if(!empty($tmp))
+        {
+            foreach ($tmp as $card_type => $sregions)
+            {
+                $regins = explode(',',$sregions);
+                if(!empty($regins)) {
+                    $regins[$card_type] = $regins;
+                }
+            }
+        }
+    }
+
+    public function testReadCSVFile()
+    {
+        $items = [
+            ['file' => 'phone-100.csv','card_type' => mtopcard\PhoneCardPaper, 'value' => 100],
+            ['file' => 'oil-100.csv','card_type'   => mtopcard\OilCardPaper, 'value' => 100],
+            ['file' => 'oil-200.csv','card_type'   => mtopcard\OilCardPaper, 'value' => 200],
+            ['file' => 'oil-500.csv','card_type'   => mtopcard\OilCardPaper, 'value' => 500],
+            ['file' => 'oil-1000.csv','card_type'  => mtopcard\OilCardPaper, 'value' => 1000],
+        ];
+
+        $mod_card = Model('card_key');
+        foreach ($items as $item)
+        {
+            $file = BASE_DATA_PATH . '/cards/' . $item['file'];
+            $amount = $item['value'];
+            $card_type = $item['card_type'];
+
+            $fn = fopen($file,"r");
+            if(empty($fn)) {
+                Log::record("Open File {$item['file']} error.",Log::ERR);
+                break;
+            }
+            else {
+                Log::record("{$item['file']} start woring",Log::DEBUG);
+            }
+
+            while(! feof($fn))  {
+                $line = trim(fgets($fn));
+                $results = explode(',',$line);
+                if(empty($results)) {
+                    continue;
+                }
+                elseif(count($results) == 2) {
+                    $card_no = trim($results[0]);
+                    $card_key = trim($results[1]);
+                }
+                elseif(count($results) == 3) {
+                    $card_no = trim($results[1]);
+                    $card_key = trim($results[2]);
+                }
+                else {
+                    Log::record("分析数据失败:{$line}",Log::ERR);
+                    continue;
+                }
+
+                $this->addCard($mod_card,$card_no,$card_key,$card_type,$amount);
+            }
+
+            fclose($fn);
+        }
+
+        Log::record("All cards has been add to database.",Log::DEBUG);
+    }
+
+    private function addFile($file)
+    {
+        $filename = BASE_DATA_PATH . "/cards/{$file}";
+        if(!file_exists($filename)) {
+            Log::record("{$file} not exists.",Log::ERR);
+            return false;
+        }
+
+        $mod_card = Model('card_key');
+
+        $fileType = PHPExcel_IOFactory::identify($filename);
+        $objReader = PHPExcel_IOFactory::createReader($fileType);
+        $objPHPExcel = $objReader->load($filename);
+
+        Log::record("{$file} begin....",Log::DEBUG);
+
+        foreach ($objPHPExcel->getWorkSheetIterator() as $sheet)
+        {
+            $title = strtolower($sheet->getTitle());
+            Log::record("{$file} - {$title} start....",Log::DEBUG);
+
+            [$type,$amount,$id] = explode('-',$title);
+            Log::record("type = {$type} amount = {$amount}",Log::DEBUG);
+
+            if($type == 'p') {
+                $card_type = mtopcard\PhoneCardPaper;
+            }
+            elseif($type == 'o') {
+                $card_type = mtopcard\OilCardPaper;
+            }
+            else {
+                Log::record("{$filename} sheet {$title} name type error.",Log::ERR);
+                return false;
+            }
+
+            if($amount <= 0) {
+                Log::record("{$filename} sheet {$title} name amount error.",Log::ERR);
+                return false;
+            }
+
+            foreach ($sheet->getRowIterator() as $row)
+            {
+                $index = $row->getRowIndex();
+                if ($index < 2) continue;
+
+                $datas = [];
+                foreach ($row->getCellIterator() as $cell) {
+                    $data = $cell->getValue();
+                    $datas[] = $data;
+                }
+
+                if(empty($datas[1]) || empty($datas[2])) {
+                    continue;
+                }
+
+                $card_no = trim($datas[1]);
+                $card_key = trim($datas[2]);
+                if($this->check_cardno($card_no) && $this->check_cardkey($card_key)) {
+                    $this->addCard($mod_card,$card_no,$card_key,$card_type,$amount);
+                }
+                else {
+                    Log::record("{$card_no} {$card_key}",Log::ERR);
+                }
+            }
+        }
+        Log::record("{$file} end....",Log::DEBUG);
+        return true;
+    }
+
+    private function check_cardno($card_no)
+    {
+        $count = self::CardNoLength;
+        return preg_match("/^\d{{$count}}$/i",$card_no) > 0;
+    }
+
+    private function check_cardkey($card_no)
+    {
+        $count = self::CardKeyLength;
+        return preg_match("/^[a-z0-9]{{$count}}$/",$card_no) > 0;
+    }
+
+    public function testAddCradFromExecl()
+    {
+        $files = ['lm-1.xlsx','by-1.xlsx'];
+        foreach ($files as $file) {
+            $this->addFile($file);
+        }
+    }
+
+    public function testCancelOrder()
+    {
+        //2020-08-20 处理了一些订单。
+        $card_nos = ['1900000000668434',
+            '1900000000668403',
+            '1900000000668402',
+            '1900000000668400',
+            '1900000000668398',
+            '1900000000668399',
+            '1900000000668397',
+            '1900000000668396',
+            '1900000000668395',
+            '1900000000668394',
+            '1900000000668392',
+            '1900000000668390',
+            '1900000000668393',
+            '1900000000668387',
+            '1900000000668384',
+            '1900000000668327',
+            '1900000000040001',
+            '1900000000569005',
+            '1900000000264501',
+            '1900000000569004'];
+
+        $this->cancel_order($card_nos);
+    }
+
+    private function cancel_order($card_nos)
+    {
+        $mod_card = Model('card_key');
+        foreach ($card_nos as $card_no)
+        {
+            $items = $mod_card->field('*')->where(['card_no' => $card_no])->select();
+            $length = count($items);
+            if($length > 1) {
+                Log::record("有{$length}张卡号为{$card_no}的卡",Log::ERR);
+            }
+            elseif(empty($items)) {
+                Log::record("未找到{$card_no}的卡号",Log::ERR);
+            }
+            else {
+                $order_id = intval($items[0]['order_id']);
+                $order_info = Model('vr_order')->getOrderInfo(['order_id' => $order_id]);
+                $vr_logic = Logic('vr_order');
+                $result = $vr_logic->changeOrderStateCancel($order_info,'','管理员申请退款.');
+                Log::record("{$card_no} : {$result['state']}",Log::DEBUG);
+            }
+        }
+    }
+
+    public function testCardSequence()
+    {
+        $card_key = Model('card_key');
+
+        $count = 1000;
+        $i = 0;
+
+        $pairs = [];
+        $pair = ['start' => 0,'end' => 0];
+        while (true)
+        {
+            $start = $i * $count;
+            $items = $card_key->field('*')->order('card_no asc')->limit("{$start},{$count}")->select();
+            if(empty($items)) {
+                break;
+            }
+            $i++;
+
+            foreach ($items as $item)
+            {
+                try {
+                    $card_no = intval($item['card_no']);
+
+                    if($pair['end'] + 1 == $card_no) {
+                        $pair['end'] = $card_no;
+                    }
+                    else {
+                        $pairs[] = $pair;
+                        $pair = ['start' => $card_no,'end' => $card_no];
+                    }
+                }
+                catch (Exception $ex) {
+                    Log::record($ex->getMessage(),Log::DEBUG);
+                }
+            }
+        }
+
+        foreach ($pairs as $pair) {
+            $count = $pair['end'] - $pair['start'] + 1;
+            Log::record("{$pair['start']}------{$pair['end']} count = {$count}",Log::DEBUG);
+        }
+    }
+
+    public function testCardCheck()
+    {
+        $card_no = 1000113300023292731;
+        $topcard = Model('topcard');
+        $items = $topcard->get_cards($card_no - 500,$card_no + 500);
+    }
+
+    private function find_card($file,$card_no)
+    {
+        $fileType = PHPExcel_IOFactory::identify($file);
+        $objReader = PHPExcel_IOFactory::createReader($fileType);
+        $objPHPExcel = $objReader->load($file);
+
+        foreach ($objPHPExcel->getWorkSheetIterator() as $sheet)
+        {
+            foreach ($sheet->getRowIterator() as $row)
+            {
+                $index = $row->getRowIndex();
+                if ($index < 2) continue;
+
+                $datas = [];
+                foreach ($row->getCellIterator() as $cell) {
+                    $data = $cell->getValue();
+                    $datas[] = $data;
+                }
+
+                if(empty($datas[1]) || empty($datas[2])) {
+                    continue;
+                }
+
+                $no = trim($datas[1]);
+                if($no == $card_no) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    public function testFindCard()
+    {
+        $finder = function ($card_no) {
+            $dir = BASE_DATA_PATH . "/cards/old/";
+            if ($dh = opendir($dir))
+            {
+                while (($file = readdir($dh)) !== false)
+                {
+                    $file_name = $dir . $file;
+                    $ext = pathinfo($file_name)['extension'];
+                    if($ext == 'xlsx') {
+                        $ret = $this->find_card($file_name,$card_no);
+                        if($ret) {
+                            Log::record("{$card_no} in {$file}",Log::DEBUG);
+                            break;
+                        }
+                    }
+                }
+                closedir($dh);
+            }
+        };
+
+        $cards = ['1900000000669244','1900000000669294','1900000000669344','1900000000669094','1900000000669144',
+            '1900000000669194','1900000000669394','1900000000669044','1900000000669994'];
+        foreach ($cards as $card_no) {
+            Log::record("{$card_no} is finding....",Log::DEBUG);
+            $finder($card_no);
+            Log::record("{$card_no} over.",Log::DEBUG);
+        }
+    }
+
+    public function testModifyCardno()
+    {
+        $changer = function ($start,$end) {
+            $card_key = Model('card_key');
+            $cond = ['_multi' => true, ['egt', $start], ['lt', $end]];
+            $items = $card_key->field('*')->where(['card_no&card_no' => $cond])->order('card_no asc')->select();
+            return $items;
+        };
+        $cards = $changer('1900000000699000','1900000000700000');
+
+        $card_key = Model('card_key');
+        foreach ($cards as $card) {
+            $card_id = intval($card['card_id']);
+            $card_no = intval($card['card_no']) - 30000;
+            $ret = $card_key->where(['card_id' => $card_id])->update(['card_no' => "{$card_no}"]);
+            Log::record("{$card_no} ret = {$ret}",Log::DEBUG);
+        }
+    }
+
+    public function testAddCard()
+    {
+        $finder = function ()
+        {
+            $files = [];
+            $dir = BASE_DATA_PATH . "/cards/";
+            $dh = opendir($dir);
+            if($dh)
+            {
+                while (($file = readdir($dh)) !== false)
+                {
+                    $file_name = $dir . $file;
+                    $ext = pathinfo($file_name)['extension'];
+                    if($ext == 'xlsx') {
+                        $files[] = $file;
+                    }
+                }
+
+                closedir($dh);
+            }
+            return $files;
+        };
+
+        $files = $finder();
+        foreach ($files as $file) {
+            $this->addFile($file);
+        }
+    }
+}
+
+//docker-compose -f ./docker-compose-dev.yml run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestAddData::testCancelOrder)( .*)?$/" --test-suffix TestAddData.php /var/www/html/test
+//docker-compose -f ./docker-compose-dev.yml run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestAddData::test20200821_addCard)( .*)?$/" --test-suffix TestAddData.php /var/www/html/test
+//docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestAddData::testAddCard)( .*)?$/" --test-suffix TestAddData.php /var/www/html/test
+
+//docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestAddData::testModifyCardno)( .*)?$/" --test-suffix TestAddData.php /var/www/html/test
+//docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testSuhcQuery)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test
+

+ 20 - 7
test/TestRefill.php

@@ -2,6 +2,8 @@
 
 
 use PHPUnit\Framework\TestCase;
+use function mtopcard\formatProvince;
+use const mtopcard\ProvinceList;
 
 define('APP_ID', 'test');
 define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
@@ -377,6 +379,16 @@ class TestRefill extends TestCase
         refill\RefillFactory::instance()->notify('zanzanquick',$params);
     }
 
+    public function testFengyemanPhone()
+    {
+        $providers = new refill\fengyeman\RefillPhone([]);
+//        $resp = $providers->add(18500608333, 5, 50, ['order_sn' => $this->make_sn()]);
+//        $resp = $providers->query(['order_sn' => '46221624265179185139']);
+        $data = '{"order_id":"46221624265179185139","mchid":"HF67a65_10008","tel":"18500608333","price":"50.00","sign":"2bb4ed5edc97ba7f60cf3848aab82cf4","out_order_id":"206877995456","status":"1"}';
+        $params = json_decode($data , true);
+        refill\RefillFactory::instance()->notify('fengyeman',$params);
+    }
+
     public function testTongluPhone()
     {
         $providers = new refill\tonglu\RefillPhone([]);
@@ -1183,12 +1195,13 @@ class TestRefill extends TestCase
     public function testcreateSign()
     {
         $params['act'] = 'refill';
-        $params['amount'] = '100';
-        $params['cardno'] = '1000111200006005872';
-        $params['mchid'] = '1092';
-        $params['notifyurl'] = 'http://202.85.213.156:8080//YeZiYKCallBackOrderServlet';
-        $params['op'] = 'balance';
-        $params['order_sn'] = 'jftest0000123';
+        $params['amount'] = '50';
+        $params['cardno'] = '18276257399';
+        $params['mchid'] = '10162';
+        $params['notifyurl'] = 'http://www.baidu.com';
+        $params['op'] = 'add';
+        $params['order_sn'] = 'a814ebeb4ee883d01d98';
+        $params['quality'] = 2;
         $sign = $this->md5_sign($params);
     }
 
@@ -1242,7 +1255,7 @@ class TestRefill extends TestCase
             }
         }
 
-        $body .= "&key=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
+        $body .= "&key=CEFA8CCC89FE4916BA215306AABE2206";
 
         return md5($body);
     }