123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- <?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 testPushPhone()
- {
- $params = [ 'mchid' => 9618,
- 'buyer_id' => 6,
- 'amount' => 30,
- 'mch_order' => $this->make_sn(),
- 'org_quality' => 1,
- 'card_no' => '13911129867'
- ];
- $ret = refill\util::push_add($params);
- }
- 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','RefillOil');
- $order_sn = $this->make_sn();
- [$state, $ch_order, $neterr] = $providers->add(1000111100021211884, 2, 50, ['order_sn' => $order_sn]);
- $providers->query(['ch_trade_no' => $ch_order,'order_sn' => $order_sn]);
- }
- 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);
- }
- }
- }
- }
|