TestRefillThird.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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_proxy.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. $params = [ 'mchid' => 1092,
  26. "act" => "refill",
  27. "op" => "add_third",
  28. 'order_sn' => $this->make_sn(),
  29. 'notifyurl' => 'https://www.xyzshops.cn/mobile/signature.php',
  30. 'card_type' => 1,
  31. 'card_no' => '403149064',
  32. 'product_code' => 'XYZ100744',
  33. 'quantity' => 5,
  34. ];
  35. $proxy = new refill_proxy('210fe406954220f56085997d6a4c5b80');
  36. $proxy->send("https://www.xyzshops.cn/mobile/index.php",$params);
  37. }
  38. public function testAddthirdExample()
  39. {
  40. $params = [ 'mchid' => 'xxxx', //贵方账号
  41. "act" => "refill",
  42. "op" => "add_third",
  43. 'order_sn' => $this->make_sn(), //贵方单号
  44. 'notifyurl' => 'xxxx', //回调URL
  45. 'card_type' => 1,//卡类型,1 2,3 回头写文档
  46. 'card_no' => '403149064',//充值号码`
  47. 'product_code' => 'XYZ100744', //充值产品编码
  48. 'quantity' => 5, //数量
  49. ];
  50. $proxy = new refill_proxy('秘钥');
  51. $proxy->send("https://www.xyzshops.cn/mobile/index.php",$params);
  52. }
  53. public function testPushPhone()
  54. {
  55. $params = [ 'mchid' => 9618,
  56. 'buyer_id' => 6,
  57. 'amount' => 30,
  58. 'mch_order' => $this->make_sn(),
  59. 'org_quality' => 1,
  60. 'card_no' => '13911129867'
  61. ];
  62. $ret = refill\util::push_add($params);
  63. }
  64. public function testPushLzThird()
  65. {
  66. $params = [ 'mchid' => 9618,
  67. 'buyer_id' => 6,
  68. 'amount' => refill\util::ThirdRefillAmount,
  69. 'mch_order' => $this->make_sn(),
  70. 'notify_url' => '',
  71. 'org_quality' => 1,
  72. 'card_type' => mtopcard\ThirdRefillCard,
  73. 'card_no' => '403149064',
  74. 'product_code' => 'LZ100744',
  75. 'quantity' => 5,
  76. 'third_card_type' => 1
  77. ];
  78. $ret = refill\util::push_addthird($params);
  79. }
  80. public function testPushXYZThird()
  81. {
  82. $params = [ 'mchid' => 1092,
  83. 'buyer_id' => 60221,
  84. 'amount' => refill\util::ThirdRefillAmount,
  85. 'mch_order' => $this->make_sn(),
  86. 'notify_url' => '',
  87. 'org_quality' => 1,
  88. 'card_type' => mtopcard\ThirdRefillCard,
  89. 'card_no' => '403149064',
  90. 'product_code' => 'XYZ100744',
  91. 'quantity' => 5,
  92. 'third_card_type' => 1
  93. ];
  94. $ret = refill\util::push_addthird($params);
  95. }
  96. private function make_sn()
  97. {
  98. return mt_rand(1000, 9999)
  99. . sprintf('%010d', time())
  100. . sprintf('%06d', (float)microtime() * 1000000);
  101. }
  102. public function testAddQQ()
  103. {
  104. $params = $this->params();
  105. }
  106. private function params($card_no,$card_type,$quantity,$pcode,$order_sn)
  107. {
  108. $params['act'] = 'lzrefill';
  109. $params['op'] = 'add_third';
  110. $params['notifyurl'] = 'https://www.xyzshops.cn/mobile/signature.php';
  111. $params['usr'] = 9618;
  112. $params['card_no'] = $card_no;
  113. $params['quantity'] = $quantity;
  114. $params['product_code'] = $pcode;
  115. $params['card_type'] = $card_type;
  116. $params['ord'] = $order_sn;
  117. $params['tim'] = date("YmdHis");
  118. $params['yysid'] = 0;
  119. $params['hmlx'] = 0;
  120. return $params;
  121. }
  122. public function testLingzhthirdPhone()
  123. {
  124. $providers = $this->getProvider('lingzhthird');
  125. $resp = $providers->add(18500608333, 5, 10,
  126. ['order_sn' => $this->make_sn(),
  127. 'goods_id' => 6559,
  128. 'quantity'=>5,'product_code'=>'XYZ100744','third_card_type'=>1]);
  129. // $resp = $providers->query(['order_sn' => '59911615124025101286']);
  130. // $input['usr'] = 1;
  131. // $input['ord'] = '52741615119546453690';
  132. // $input['bz'] = '';
  133. // $input['state'] = 2;
  134. // $input['sgn'] = 'FFCBB75C307154DD306F4EC75BB69A6D';
  135. // refill\RefillFactory::instance()->notify('lingzhthird',$input);
  136. }
  137. private function getProvider($name)
  138. {
  139. $file = BASE_HELPER_RAPI_PATH . "/$name/RefillPhone.php";
  140. if(!file_exists($file)){
  141. Log::record("provider api file={$file} not exist.",Log::DEBUG);
  142. return false;
  143. } else {
  144. require_once($file);
  145. Log::record("file={$file} load success.",Log::DEBUG);
  146. }
  147. $class_name = "refill\\{$name}\\RefillPhone";
  148. if (class_exists($class_name, false)) {
  149. $caller = new $class_name([]);
  150. return $caller;
  151. } else {
  152. $error = "Base Error: class {$class_name} isn't exists!";
  153. Log::record($error, Log::ERR);
  154. return false;
  155. }
  156. }
  157. public function testCallBack()
  158. {
  159. $body = '{"AppKey":"211394658","TimesTamp":"1620987358973","MOrderID":"7088040674302538334319","OrderID":"210514101558013001","State":"2","ChargeAccount":"403149064","Version":"1.0","BuyCount":"5","Attach":"","Sign":"BF8D2895A6C214931A511AE12EB9E8EE"}';
  160. $params = json_decode($body, true);
  161. refill\RefillFactory::instance()->notify('sctongqian', $params);
  162. }
  163. public function testInstance()
  164. {
  165. refill\RefillFactory::instance()->notify_merchant(1,false);
  166. }
  167. public function testEncrypt()
  168. {
  169. $mod_mch = Model('merchant');
  170. $mch_info = $mod_mch->getMerchant(9618);
  171. $mod_third = Model('thrid_refill');
  172. $thrid_info = $mod_third->getThird(6244720);
  173. if (!empty($mch_info) && !empty($thrid_info))
  174. {
  175. $card_info = $thrid_info['card_info'];
  176. if (!empty($card_info)) {
  177. $passwd = $mch_info['secure_key'];
  178. $encrypt = openssl_encrypt($card_info,'AES-128-CBC',$passwd);
  179. if($encrypt != false) {
  180. $params['card_info'] = $encrypt;
  181. }
  182. $output = openssl_decrypt($encrypt, 'AES-128-CBC', $passwd);
  183. }
  184. }
  185. }
  186. }