TestRefillThird.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. use PHPUnit\Framework\TestCase;
  3. use refill\lingzhdl\config;
  4. use function aop\stripPKSC7Padding;
  5. define('APP_ID', 'test');
  6. define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
  7. require_once(BASE_ROOT_PATH . '/global.php');
  8. require_once(BASE_CORE_PATH . '/lrlz.php');
  9. require_once(BASE_ROOT_PATH . '/fooder.php');
  10. require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
  11. require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
  12. class TestRefillThird extends TestCase
  13. {
  14. public static function setUpBeforeClass(): void
  15. {
  16. Base::run_util();
  17. }
  18. public function testProvider()
  19. {
  20. $provider = new refill\ProviderManager();
  21. $provider->load();
  22. }
  23. public function testAddthird()
  24. {
  25. }
  26. public function testPushPhone()
  27. {
  28. $params = [ 'mchid' => 9618,
  29. 'buyer_id' => 6,
  30. 'amount' => 30,
  31. 'mch_order' => $this->make_sn(),
  32. 'org_quality' => 1,
  33. 'card_no' => '13911129867'
  34. ];
  35. $ret = refill\util::push_add($params);
  36. }
  37. public function testPushLzThird()
  38. {
  39. $params = [ 'mchid' => 9618,
  40. 'buyer_id' => 6,
  41. 'amount' => refill\util::ThirdRefillAmount,
  42. 'mch_order' => $this->make_sn(),
  43. 'notify_url' => '',
  44. 'org_quality' => 1,
  45. 'card_type' => mtopcard\ThirdRefillCard,
  46. 'card_no' => '403149064',
  47. 'product_code' => 'LZ100744',
  48. 'quantity' => 5,
  49. 'third_card_type' => 1
  50. ];
  51. $ret = refill\util::push_addthird($params);
  52. }
  53. public function testPushXYZThird()
  54. {
  55. $params = [ 'mchid' => 1092,
  56. 'buyer_id' => 60221,
  57. 'amount' => refill\util::ThirdRefillAmount,
  58. 'mch_order' => $this->make_sn(),
  59. 'notify_url' => '',
  60. 'org_quality' => 1,
  61. 'card_type' => mtopcard\ThirdRefillCard,
  62. 'card_no' => '403149064',
  63. 'product_code' => 'XYZ100744',
  64. 'quantity' => 5,
  65. 'third_card_type' => 1
  66. ];
  67. $ret = refill\util::push_addthird($params);
  68. }
  69. private function make_sn()
  70. {
  71. return mt_rand(1000, 9999)
  72. . sprintf('%010d', time())
  73. . sprintf('%06d', (float)microtime() * 1000000);
  74. }
  75. public function testAddQQ()
  76. {
  77. $params = $this->params();
  78. }
  79. private function params($card_no,$card_type,$quantity,$pcode,$order_sn)
  80. {
  81. $params['act'] = 'lzrefill';
  82. $params['op'] = 'add_third';
  83. $params['notifyurl'] = 'https://www.xyzshops.cn/mobile/signature.php';
  84. $params['usr'] = 9618;
  85. $params['card_no'] = $card_no;
  86. $params['quantity'] = $quantity;
  87. $params['product_code'] = $pcode;
  88. $params['card_type'] = $card_type;
  89. $params['ord'] = $order_sn;
  90. $params['tim'] = date("YmdHis");
  91. $params['yysid'] = 0;
  92. $params['hmlx'] = 0;
  93. return $params;
  94. }
  95. public function testLingzhthirdPhone()
  96. {
  97. $providers = $this->getProvider('lingzhthird');
  98. $resp = $providers->add(18500608333, 5, 10,
  99. ['order_sn' => $this->make_sn(),
  100. 'goods_id' => 6559,
  101. 'quantity'=>5,'product_code'=>'XYZ100744','third_card_type'=>1]);
  102. // $resp = $providers->query(['order_sn' => '59911615124025101286']);
  103. // $input['usr'] = 1;
  104. // $input['ord'] = '52741615119546453690';
  105. // $input['bz'] = '';
  106. // $input['state'] = 2;
  107. // $input['sgn'] = 'FFCBB75C307154DD306F4EC75BB69A6D';
  108. // refill\RefillFactory::instance()->notify('lingzhthird',$input);
  109. }
  110. private function getProvider($name)
  111. {
  112. $file = BASE_HELPER_RAPI_PATH . "/$name/RefillPhone.php";
  113. if(!file_exists($file)){
  114. Log::record("provider api file={$file} not exist.",Log::DEBUG);
  115. return false;
  116. } else {
  117. require_once($file);
  118. Log::record("file={$file} load success.",Log::DEBUG);
  119. }
  120. $class_name = "refill\\{$name}\\RefillPhone";
  121. if (class_exists($class_name, false)) {
  122. $caller = new $class_name([]);
  123. return $caller;
  124. } else {
  125. $error = "Base Error: class {$class_name} isn't exists!";
  126. Log::record($error, Log::ERR);
  127. return false;
  128. }
  129. }
  130. public function testCallBack()
  131. {
  132. $body = '{"AppKey":"211394658","TimesTamp":"1620987358973","MOrderID":"7088040674302538334319","OrderID":"210514101558013001","State":"2","ChargeAccount":"403149064","Version":"1.0","BuyCount":"5","Attach":"","Sign":"BF8D2895A6C214931A511AE12EB9E8EE"}';
  133. $params = json_decode($body, true);
  134. refill\RefillFactory::instance()->notify('sctongqian', $params);
  135. }
  136. public function testInstance()
  137. {
  138. refill\RefillFactory::instance()->notify_merchant(1,false);
  139. }
  140. public function testEncrypt()
  141. {
  142. $mod_mch = Model('merchant');
  143. $mch_info = $mod_mch->getMerchant(9618);
  144. $mod_third = Model('thrid_refill');
  145. $thrid_info = $mod_third->getThird(6244720);
  146. if (!empty($mch_info) && !empty($thrid_info))
  147. {
  148. $card_info = $thrid_info['card_info'];
  149. if (!empty($card_info)) {
  150. $passwd = $mch_info['secure_key'];
  151. $encrypt = openssl_encrypt($card_info,'AES-128-CBC',$passwd);
  152. if($encrypt != false) {
  153. $params['card_info'] = $encrypt;
  154. }
  155. $output = openssl_decrypt($encrypt, 'AES-128-CBC', $passwd);
  156. }
  157. }
  158. }
  159. }