TestRefillThird.php 7.2 KB

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