123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370 |
- <?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');
- require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
- require_once(BASE_HELPER_PATH . '/refill_proxy.php');
- require_once(BASE_CORE_PATH . '/framework/function/http.php');
- class TestRefillThird extends TestCase
- {
- public static function setUpBeforeClass(): void
- {
- Base::run_util();
- }
- public function testProvider()
- {
- $provider = new refill\ProviderManager();
- $provider->load();
- }
- public function testAddthirdNet()
- {
- $params = [ 'mchid' => 1092,
- "act" => "refill",
- "op" => "add_third",
- 'order_sn' => $this->make_sn(),
- 'notifyurl' => 'https://www.xyzshops.cn/mobile/signature.php',
- 'card_type' => 1,
- 'cardno' => '403149064',
- 'product_code' => 'XYZ100744',
- 'quantity' => 5
- ];
- $proxy = new refill_proxy('210fe406954220f56085997d6a4c5b80');
- $proxy->send("https://www.xyzshops.cn/mobile/index.php",$params);
- }
- public function testAddthirdExample()
- {
- $params = [ 'mchid' => 'xxxx', //贵方账号
- "act" => "refill",
- "op" => "add_third",
- 'order_sn' => $this->make_sn(), //贵方单号
- 'notifyurl' => 'xxxx', //回调URL
- 'card_type' => 1,//卡类型,1 2,3 回头写文档
- 'cardno' => '403149064',//充值号码`
- 'product_code' => 'XYZ100744', //充值产品编码
- 'quantity' => 5, //数量
- ];
- $proxy = new refill_proxy('秘钥');
- $proxy->send("https://www.xyzshops.cn/mobile/index.php",$params);
- }
- public function testPushAddZero()
- {
- $params = [ 'mchid' => 1092,
- 'buyer_id' => 60221,
- 'amount' => 30,
- 'mch_order' => $this->make_sn(),
- 'org_quality' => 1,
- 'card_no' => '13911129867'
- ];
- $ret = refill\util::push_add_zero($params);
- Log::record("push message",Log::DEBUG);
- }
- public function testPushPhone()
- {
- $params = [ 'mchid' => 1092,
- 'buyer_id' => 60221,
- 'amount' => 30,
- 'mch_order' => $this->make_sn(),
- 'org_quality' => 1,
- 'card_no' => '13911129867',
- 'card_type' => 5,
- 'regin_no' => 1
- ];
- $ret = refill\util::push_add($params);
- Log::record("push message",Log::DEBUG);
- }
- //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillThird::testPushPhone)( .*)?$/" --test-suffix TestRefillThird.php /var/www/html/test
- public function testPushPhones()
- {
- $time = time();
- for ($i = 0; $i < 100000; $i++)
- {
- $params = [ 'mchid' => 1092,
- 'buyer_id' => 60221,
- 'amount' => 30,
- 'mch_order' => "{$time}" . sprintf("%'010d",$i),
- 'org_quality' => 1,
- 'card_no' => '13911129867',
- 'card_type' => 5,
- 'regin_no' => 1
- ];
- $ret = refill\util::push_add($params);
- Log::record("push message",Log::DEBUG);
- }
- //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillThird::testPushPhones)( .*)?$/" --test-suffix TestRefillThird.php /var/www/html/test
- }
- private function push_order($mchid,$member_id,$time,$index)
- {
- $params = [ 'mchid' => $mchid,
- 'buyer_id' => $member_id,
- 'amount' => 30,
- 'mch_order' => "{$time}" . sprintf("%'010d",$index),
- 'org_quality' => 13,
- 'card_no' => '13911129867'
- ];
- $ret = refill\util::push_add($params);
- }
- public function testPushOtherPhones()
- {
- $time = time();
- Log::record("push message start:{$time}",Log::DEBUG);
- for ($i = 0; $i < 10; $i++)
- {
- $this->push_order(1092,60221,$time,$i);
- // $this->push_order(1093,65771,$time,$i);
- // $this->push_order(1094,65772,$time,$i);
- // $this->push_order(1095,65773,$time,$i);
- // $this->push_order(1096,65774,$time,$i);
- }
- Log::record("push message end",Log::DEBUG);
- //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillThird::testPushOtherPhones)( .*)?$/" --test-suffix TestRefillThird.php /var/www/html/test
- }
- public function testPushLzThird()
- {
- $params = [ 'mchid' => 9618,
- 'buyer_id' => 6,
- 'amount' => refill\util::ThirdRefillAmount,
- 'mch_order' => $this->make_sn(),
- 'notify_url' => '',
- 'org_quality' => 1,
- 'card_type' => mtopcard\ThirdRefillCard,
- 'card_no' => '403149064',
- 'product_code' => 'LZ100744',
- 'quantity' => 5,
- 'third_card_type' => 1
- ];
- $ret = refill\util::push_addthird($params);
- }
- public function testAddthirdLocal()
- {
- $params = [ 'mchid' => 1092,
- "act" => "refill",
- "op" => "add_third",
- 'order_sn' => $this->make_sn(),
- 'notifyurl' => 'https://www.xyzshops.cn/mobile/signature.php',
- 'card_type' => 1,
- 'cardno' => '403149064',
- 'product_code' => 'XYZ100744',
- 'quantity' => 5
- ];
- $proxy = new refill_proxy('210fe406954220f56085997d6a4c5b80');
- $proxy->send("http://192.168.1.220/mobile/index.php",$params);
- }
- public function testPushXYZThird()
- {
- $params = [ 'mchid' => 1092,
- 'buyer_id' => 60221,
- 'amount' => refill\util::ThirdRefillAmount,
- 'mch_order' => $this->make_sn(),
- 'notify_url' => '',
- 'org_quality' => 1,
- 'card_type' => mtopcard\ThirdRefillCard,
- 'cardno' => '403149064',
- 'product_code' => 'XYZ100744',
- 'quantity' => 5,
- 'third_card_type' => 1
- ];
- $ret = refill\util::push_addthird($params);
- }
- private function make_sn()
- {
- return mt_rand(1000, 9999)
- . sprintf('%010d', time())
- . sprintf('%06d', (float)microtime() * 1000000);
- }
- public function testAddQQ()
- {
- $params = $this->params();
- }
- private function params($card_no,$card_type,$quantity,$pcode,$order_sn)
- {
- $params['act'] = 'lzrefill';
- $params['op'] = 'add_third';
- $params['notifyurl'] = 'https://www.xyzshops.cn/mobile/signature.php';
- $params['usr'] = 9618;
- $params['card_no'] = $card_no;
- $params['quantity'] = $quantity;
- $params['product_code'] = $pcode;
- $params['card_type'] = $card_type;
- $params['ord'] = $order_sn;
- $params['tim'] = date("YmdHis");
- $params['yysid'] = 0;
- $params['hmlx'] = 0;
- return $params;
- }
- public function testLingzhthirdPhone()
- {
- $providers = $this->getProvider('lingzhthird');
- $resp = $providers->add(18500608333, 5, 10,
- ['order_sn' => $this->make_sn(),
- 'goods_id' => 6559,
- 'quantity'=>5,'product_code'=>'XYZ100744','third_card_type'=>1]);
- }
- public function testFNMS()
- {
- $providers = $this->getProvider('feinimoshu_hf','RefillPhone');
- $order_sn = $this->make_sn();
- // [$state, $ch_order, $neterr] = $providers->add(18500608333, 5, 30, ['order_sn' => $order_sn]);
- $providers->query(['order_sn' => '60711623734193929309']);
- }
- public function testFNMSCB()
- {
- $params = ['appid' => 'CZ30533982',
- 'order' => 'D20210616111088971260328',
- 'morder' => '1879340677155108772500',
- 'status' => '2',
- 'cash' => '30',
- 'vnum' => '110103308152106161039260597703',
- 'actual_cash' => '28.86',
- 'signature' => 'c3077297f26f6231eeaa31ccb8c16148'];
- $provider = $this->getProvider('feinimoshu_hf','RefillCallBack');
- $ret = $provider->verify($params);
- $this->assertTrue($ret,'Verify is OK');
- $provider->notify($params);
- }
- private function getProvider($name,$type = 'RefillPhone')
- {
- $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([]);
- return $caller;
- } else {
- $error = "Base Error: class {$class_name} isn't exists!";
- Log::record($error, Log::ERR);
- return false;
- }
- }
- public function testCallBack()
- {
- $body = '{"AppKey":"211394658","TimesTamp":"1620987358973","MOrderID":"7088040674302538334319","OrderID":"210514101558013001","State":"2","ChargeAccount":"403149064","Version":"1.0","BuyCount":"5","Attach":"","Sign":"BF8D2895A6C214931A511AE12EB9E8EE"}';
- $params = json_decode($body, true);
- refill\RefillFactory::instance()->notify('sctongqian', $params);
- }
- public function testInstance()
- {
- refill\RefillFactory::instance()->notify_merchant(1,false);
- }
- public function testEncrypt()
- {
- $mod_mch = Model('merchant');
- $mch_info = $mod_mch->getMerchant(9618);
- $mod_third = Model('thrid_refill');
- $thrid_info = $mod_third->getThird(6244720);
- if (!empty($mch_info) && !empty($thrid_info))
- {
- $card_info = $thrid_info['card_info'];
- if (!empty($card_info)) {
- $passwd = $mch_info['secure_key'];
- $encrypt = openssl_encrypt($card_info,'AES-128-CBC',$passwd);
- if($encrypt != false) {
- $params['card_info'] = $encrypt;
- }
- $output = openssl_decrypt($encrypt, 'AES-128-CBC', $passwd);
- }
- }
- }
- public function testZanzan()
- {
- $providers = $this->getProvider('zanzan','RefillPhone');
- // $order_sn = $this->make_sn();
- // [$state, $ch_order, $neterr] = $providers->add(13911129867, 5, 100, ['order_sn' => $order_sn]);
- // [$state, $ch_order, $neterr] = $providers->add(18500608333, 5, 100, ['order_sn' => $order_sn]);
- $providers->query(['ch_trade_no' => '','order_sn' => '4599550676464663945778']);
- }
- public function testSuning()
- {
- $providers = $this->getProvider('suning','RefillPhone');
- $providers->mStoreID = 61;
- $order_sn = $this->make_sn();
- $resp = $providers->add(14011221111, 7, 1,
- ['order_sn' => $order_sn, 'goods_id' => 6619,
- 'quantity' => 5, 'product_code' => 'XYZ100745', 'third_card_type' => 1]);
- }
- public function testSuningCardKey()
- {
- $providers = $this->getProvider('suning','RefillPhone');
- $providers->mStoreID = 61;
- $order_sn = $this->make_sn();
- $resp = $providers->add('', 7, 1,
- ['order_sn' => $order_sn, 'goods_id' => 6619,
- 'quantity' => 5, 'product_code' => 'XYZ100745', 'third_card_type' => 1]);
- }
- public function testSendMobile()
- {
- $phone = '13911129867';
- $amount = 30;
- $url = "https://www.xyzshops.cn" . "/mobile/index.php";
- $params = ['mchid' => 1092,
- 'cardno' => $phone,
- 'amount' => $amount,
- "act" => "refill",
- "op" => "add",
- 'order_sn' => $this->make_sn(),
- 'notifyurl' => "https://www.xyzshops.cn/signature.php"];
- $proxy = new refill_proxy("210fe406954220f56085997d6a4c5b80");
- $resp = $proxy->send($url, $params);
- }
- public function testLoad()
- {
- refill\RefillFactory::instance()->load();
- }
- }
|