TestRefillThird.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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' => '14749398007',
  31. 'product_code' => 'XYZ100754',
  32. 'quantity' => 1
  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 testPushAddZero()
  53. {
  54. $params = [ 'mchid' => 1092,
  55. 'buyer_id' => 60221,
  56. 'amount' => 30,
  57. 'mch_order' => $this->make_sn(),
  58. // 'org_quality' => 1,
  59. 'card_no' => '13911129867'
  60. ];
  61. $ret = refill\util::push_add_zero($params);
  62. Log::record("push message",Log::DEBUG);
  63. }
  64. public function testPushPhone()
  65. {
  66. $params = [ 'mchid' => 1092,
  67. 'buyer_id' => 60221,
  68. 'amount' => 30,
  69. 'mch_order' => $this->make_sn(),
  70. // 'org_quality' => 1,
  71. 'card_no' => '13911129867' //,
  72. // 'card_type' => 5,
  73. // 'regin_no' => 1
  74. ];
  75. $ret = refill\util::push_add($params);
  76. Log::record("push message",Log::DEBUG);
  77. }
  78. //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillThird::testPushPhone)( .*)?$/" --test-suffix TestRefillThird.php /var/www/html/test
  79. public function testLittlePushPhones()
  80. {
  81. $time = time();
  82. for ($i = 0; $i < 1000; $i++)
  83. {
  84. $params = [ 'mchid' => 1092,
  85. 'buyer_id' => 60221,
  86. 'amount' => 30,
  87. 'mch_order' => "{$time}" . sprintf("%'010d",$i),
  88. 'card_no' => '13911129867',
  89. 'card_type' => 5,
  90. 'regin_no' => 1,
  91. 'cardno_state' => 1,
  92. 'is_validate' => 1,
  93. 'is_transfer' => 1
  94. ];
  95. $ret = refill\util::push_add($params);
  96. Log::record("push message",Log::DEBUG);
  97. }
  98. //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillThird::testLittlePushPhones)( .*)?$/" --test-suffix TestRefillThird.php /var/www/html/test
  99. }
  100. public function testPushPhones()
  101. {
  102. $time = time();
  103. for ($i = 0; $i < 1000000; $i++)
  104. {
  105. $params = [ 'mchid' => 1092,
  106. 'buyer_id' => 60221,
  107. 'amount' => 30,
  108. 'mch_order' => "{$time}" . sprintf("%'010d",$i),
  109. 'card_no' => '13911129867',
  110. 'card_type' => 5,
  111. 'regin_no' => 1,
  112. 'cardno_state' => 1,
  113. 'is_validate' => 1,
  114. 'is_transfer' => 1
  115. ];
  116. $ret = refill\util::push_add($params);
  117. Log::record("push message",Log::DEBUG);
  118. }
  119. //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillThird::testPushPhones)( .*)?$/" --test-suffix TestRefillThird.php /var/www/html/test
  120. }
  121. private function push_order($mchid,$member_id,$time,$index)
  122. {
  123. $params = [ 'mchid' => $mchid,
  124. 'buyer_id' => $member_id,
  125. 'amount' => 30,
  126. 'mch_order' => "{$time}" . sprintf("%'010d",$index),
  127. 'org_quality' => 13,
  128. 'card_no' => '13911129867'
  129. ];
  130. $ret = refill\util::push_add($params);
  131. }
  132. public function testPushOtherPhones()
  133. {
  134. $time = time();
  135. Log::record("push message start:{$time}",Log::DEBUG);
  136. for ($i = 0; $i < 10; $i++)
  137. {
  138. $this->push_order(1092,60221,$time,$i);
  139. // $this->push_order(1093,65771,$time,$i);
  140. // $this->push_order(1094,65772,$time,$i);
  141. // $this->push_order(1095,65773,$time,$i);
  142. // $this->push_order(1096,65774,$time,$i);
  143. }
  144. Log::record("push message end",Log::DEBUG);
  145. //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillThird::testPushOtherPhones)( .*)?$/" --test-suffix TestRefillThird.php /var/www/html/test
  146. }
  147. public function testPushLzThird()
  148. {
  149. $params = [ 'mchid' => 9618,
  150. 'buyer_id' => 6,
  151. 'amount' => refill\util::ThirdRefillAmount,
  152. 'mch_order' => $this->make_sn(),
  153. 'notify_url' => '',
  154. 'org_quality' => 1,
  155. 'card_type' => mtopcard\ThirdRefillCard,
  156. 'card_no' => '403149064',
  157. 'product_code' => 'LZ100744',
  158. 'quantity' => 5,
  159. 'third_card_type' => 1
  160. ];
  161. $ret = refill\util::push_addthird($params);
  162. }
  163. public function testAddthirdLocal()
  164. {
  165. $params = [ 'mchid' => 1092,
  166. "act" => "refill",
  167. "op" => "add_third",
  168. 'order_sn' => $this->make_sn(),
  169. 'notifyurl' => 'https://www.xyzshops.cn/mobile/signature.php',
  170. 'card_type' => 1,
  171. 'cardno' => '403149064',
  172. 'product_code' => 'XYZ100744',
  173. 'quantity' => 5
  174. ];
  175. $proxy = new refill_proxy('210fe406954220f56085997d6a4c5b80');
  176. $proxy->send("http://192.168.1.220/mobile/index.php",$params);
  177. }
  178. public function testPushXYZThird()
  179. {
  180. $params = [ 'mchid' => 1092,
  181. 'buyer_id' => 60221,
  182. 'amount' => refill\util::ThirdRefillAmount,
  183. 'mch_order' => $this->make_sn(),
  184. 'notify_url' => '',
  185. 'org_quality' => 1,
  186. 'card_type' => mtopcard\ThirdRefillCard,
  187. 'card_no' => '403149064',
  188. 'product_code' => 'XYZ100744',
  189. 'quantity' => 5,
  190. 'third_card_type' => 1
  191. ];
  192. $ret = refill\util::push_addthird($params);
  193. }
  194. private function make_sn()
  195. {
  196. return mt_rand(1000, 9999)
  197. . sprintf('%010d', time())
  198. . sprintf('%06d', (float)microtime() * 1000000);
  199. }
  200. public function testAddQQ()
  201. {
  202. $params = $this->params();
  203. }
  204. private function params($card_no,$card_type,$quantity,$pcode,$order_sn)
  205. {
  206. $params['act'] = 'lzrefill';
  207. $params['op'] = 'add_third';
  208. $params['notifyurl'] = 'https://www.xyzshops.cn/mobile/signature.php';
  209. $params['usr'] = 9618;
  210. $params['card_no'] = $card_no;
  211. $params['quantity'] = $quantity;
  212. $params['product_code'] = $pcode;
  213. $params['card_type'] = $card_type;
  214. $params['ord'] = $order_sn;
  215. $params['tim'] = date("YmdHis");
  216. $params['yysid'] = 0;
  217. $params['hmlx'] = 0;
  218. return $params;
  219. }
  220. public function testLingzhthirdPhone()
  221. {
  222. $providers = $this->getProvider('lingzhthird');
  223. $resp = $providers->add(18500608333, 5, 10,
  224. ['order_sn' => $this->make_sn(),
  225. 'goods_id' => 6559,
  226. 'quantity'=>5,'product_code'=>'XYZ100744','third_card_type'=>1]);
  227. }
  228. public function testFNMS()
  229. {
  230. $providers = $this->getProvider('feinimoshu_hf','RefillPhone');
  231. $order_sn = $this->make_sn();
  232. // [$state, $ch_order, $neterr] = $providers->add(18500608333, 5, 30, ['order_sn' => $order_sn]);
  233. $providers->query(['order_sn' => '60711623734193929309']);
  234. }
  235. public function testFNMSCB()
  236. {
  237. $params = ['appid' => 'CZ30533982',
  238. 'order' => 'D20210616111088971260328',
  239. 'morder' => '1879340677155108772500',
  240. 'status' => '2',
  241. 'cash' => '30',
  242. 'vnum' => '110103308152106161039260597703',
  243. 'actual_cash' => '28.86',
  244. 'signature' => 'c3077297f26f6231eeaa31ccb8c16148'];
  245. $provider = $this->getProvider('feinimoshu_hf','RefillCallBack');
  246. $ret = $provider->verify($params);
  247. $this->assertTrue($ret,'Verify is OK');
  248. $provider->notify($params);
  249. }
  250. private function getProvider($name,$type = 'RefillPhone')
  251. {
  252. $file = BASE_HELPER_RAPI_PATH . "/$name/{$type}.php";
  253. if(!file_exists($file)){
  254. Log::record("provider api file={$file} not exist.",Log::DEBUG);
  255. return false;
  256. } else {
  257. require_once($file);
  258. Log::record("file={$file} load success.",Log::DEBUG);
  259. }
  260. $class_name = "refill\\{$name}\\{$type}";
  261. if (class_exists($class_name, false)) {
  262. $caller = new $class_name([]);
  263. return $caller;
  264. } else {
  265. $error = "Base Error: class {$class_name} isn't exists!";
  266. Log::record($error, Log::ERR);
  267. return false;
  268. }
  269. }
  270. public function testCallBack()
  271. {
  272. $body = '{"AppKey":"211394658","TimesTamp":"1620987358973","MOrderID":"7088040674302538334319","OrderID":"210514101558013001","State":"2","ChargeAccount":"403149064","Version":"1.0","BuyCount":"5","Attach":"","Sign":"BF8D2895A6C214931A511AE12EB9E8EE"}';
  273. $params = json_decode($body, true);
  274. refill\RefillFactory::instance()->notify('sctongqian', $params);
  275. }
  276. public function testInstance()
  277. {
  278. refill\RefillFactory::instance()->notify_merchant(1,false);
  279. }
  280. public function testEncrypt()
  281. {
  282. $mod_mch = Model('merchant');
  283. $mch_info = $mod_mch->getMerchant(9618);
  284. $mod_third = Model('thrid_refill');
  285. $thrid_info = $mod_third->getThird(6244720);
  286. if (!empty($mch_info) && !empty($thrid_info))
  287. {
  288. $card_info = $thrid_info['card_info'];
  289. if (!empty($card_info)) {
  290. $passwd = $mch_info['secure_key'];
  291. $encrypt = openssl_encrypt($card_info,'AES-128-CBC',$passwd);
  292. if($encrypt != false) {
  293. $params['card_info'] = $encrypt;
  294. }
  295. $output = openssl_decrypt($encrypt, 'AES-128-CBC', $passwd);
  296. }
  297. }
  298. }
  299. public function testZanzan()
  300. {
  301. $providers = $this->getProvider('zanzan','RefillPhone');
  302. // $order_sn = $this->make_sn();
  303. // [$state, $ch_order, $neterr] = $providers->add(13911129867, 5, 100, ['order_sn' => $order_sn]);
  304. // [$state, $ch_order, $neterr] = $providers->add(18500608333, 5, 100, ['order_sn' => $order_sn]);
  305. // $providers->query(['ch_trade_no' => '','order_sn' => '4599550676464663945778']);
  306. $resp = $providers->balance();
  307. }
  308. public function testSuning()
  309. {
  310. $providers = $this->getProvider('suning','RefillPhone');
  311. $providers->mStoreID = 61;
  312. $order_sn = $this->make_sn();
  313. $resp = $providers->add(14011221111, 7, 1,
  314. ['order_sn' => $order_sn, 'goods_id' => 6619,
  315. 'quantity' => 5, 'product_code' => 'XYZ100745', 'third_card_type' => 1]);
  316. }
  317. public function testSuningCardKey()
  318. {
  319. $providers = $this->getProvider('suning','RefillPhone');
  320. $providers->mStoreID = 61;
  321. $order_sn = $this->make_sn();
  322. $resp = $providers->add('', 7, 1,
  323. ['order_sn' => $order_sn, 'goods_id' => 6619,
  324. 'quantity' => 5, 'product_code' => 'XYZ100745', 'third_card_type' => 1]);
  325. }
  326. public function testSendMobile()
  327. {
  328. $phone = '13911129867';
  329. $amount = 30;
  330. $url = "https://www.xyzshops.cn" . "/mobile/index.php";
  331. $params = ['mchid' => 1092,
  332. 'cardno' => $phone,
  333. 'amount' => $amount,
  334. "act" => "refill",
  335. "op" => "add",
  336. 'order_sn' => $this->make_sn(),
  337. 'notifyurl' => "https://www.xyzshops.cn/signature.php"];
  338. $proxy = new refill_proxy("210fe406954220f56085997d6a4c5b80");
  339. $resp = $proxy->send($url, $params);
  340. }
  341. public function testLoad()
  342. {
  343. refill\RefillFactory::instance()->load();
  344. }
  345. }