TestRefillThird.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. <?php
  2. use PHPUnit\Framework\TestCase;
  3. use refill\util;
  4. define('APP_ID', 'test');
  5. define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
  6. require_once(BASE_ROOT_PATH . '/global.php');
  7. require_once(BASE_CORE_PATH . '/lrlz.php');
  8. require_once(BASE_ROOT_PATH . '/fooder.php');
  9. require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
  10. require_once(BASE_HELPER_PATH . '/refill_proxy.php');
  11. require_once(BASE_CORE_PATH . '/framework/function/http.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 testAddthirdNet()
  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/callback/testcb.php',
  30. 'card_type' => 1,
  31. 'cardno' => '93582250159',
  32. 'product_code' => 'XYZ100789',
  33. 'quantity' => 1
  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. 'cardno' => '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 testPushAddZero()
  54. {
  55. $params = [ 'mchid' => 1092,
  56. 'buyer_id' => 60221,
  57. 'amount' => 30,
  58. 'mch_order' => $this->make_sn(),
  59. // 'org_quality' => 1,
  60. 'card_no' => '13911129867'
  61. ];
  62. $ret = refill\util::push_add_zero($params);
  63. Log::record("push message",Log::DEBUG);
  64. }
  65. public function testPushPhone()
  66. {
  67. $params = [ 'mchid' => 1092,
  68. 'buyer_id' => 60221,
  69. 'amount' => 100,
  70. 'mch_order' => $this->make_sn(),
  71. // 'org_quality' => 1,
  72. 'card_no' => '13911129867' //,
  73. // 'card_type' => 5,
  74. // 'regin_no' => 1
  75. ];
  76. $ret = refill\util::push_add($params);
  77. Log::record("push message",Log::DEBUG);
  78. }
  79. //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillThird::testPushPhone)( .*)?$/" --test-suffix TestRefillThird.php /var/www/html/test
  80. public function testLittlePushPhones()
  81. {
  82. $time = time();
  83. for ($i = 0; $i < 1000; $i++)
  84. {
  85. $params = [ 'mchid' => 1092,
  86. 'buyer_id' => 60221,
  87. 'amount' => 30,
  88. 'mch_order' => "{$time}" . sprintf("%'010d",$i),
  89. 'card_no' => '13911129867',
  90. 'card_type' => 5,
  91. 'regin_no' => 1,
  92. 'cardno_state' => 1,
  93. 'is_validate' => 1,
  94. 'is_transfer' => 1
  95. ];
  96. $ret = refill\util::push_add($params);
  97. Log::record("push message",Log::DEBUG);
  98. }
  99. //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillThird::testLittlePushPhones)( .*)?$/" --test-suffix TestRefillThird.php /var/www/html/test
  100. }
  101. public function testSlowPushPhones()
  102. {
  103. $sender = function ()
  104. {
  105. $time = time();
  106. for ($i = 0; $i < 100; $i++)
  107. {
  108. $params = [ 'mchid' => 1092,
  109. 'buyer_id' => 60221,
  110. 'amount' => 30,
  111. 'mch_order' => "{$time}" . sprintf("%'010d",$i),
  112. 'card_no' => '13911129867',
  113. 'card_type' => 5,
  114. 'regin_no' => 1,
  115. 'cardno_state' => 1,
  116. 'is_validate' => 1,
  117. 'is_transfer' => 1
  118. ];
  119. $ret = refill\util::push_add($params);
  120. Log::record("push message",Log::DEBUG);
  121. }
  122. };
  123. for ($i = 0;$i < 100; $i++) {
  124. $sender();
  125. sleep(2);
  126. }
  127. //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillThird::testSlowPushPhones)( .*)?$/" --test-suffix TestRefillThird.php /var/www/html/test
  128. }
  129. public function testPushPhones()
  130. {
  131. $time = time();
  132. for ($i = 0; $i < 100000; $i++)
  133. {
  134. $params = [ 'mchid' => 1092,
  135. 'buyer_id' => 60221,
  136. 'amount' => 30,
  137. 'mch_order' => "{$time}" . sprintf("%'010d",$i),
  138. 'card_no' => '13911129867',
  139. 'card_type' => 5,
  140. 'regin_no' => 1,
  141. 'cardno_state' => 1,
  142. 'is_validate' => 1,
  143. 'is_transfer' => 1
  144. ];
  145. $ret = refill\util::push_add($params);
  146. Log::record("push message",Log::DEBUG);
  147. }
  148. //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillThird::testPushPhones)( .*)?$/" --test-suffix TestRefillThird.php /var/www/html/test
  149. }
  150. private function push_order($mchid,$member_id,$time,$index)
  151. {
  152. $params = [ 'mchid' => $mchid,
  153. 'buyer_id' => $member_id,
  154. 'amount' => 30,
  155. 'mch_order' => "{$time}" . sprintf("%'010d",$index),
  156. 'org_quality' => 13,
  157. 'card_no' => '13911129867'
  158. ];
  159. $ret = refill\util::push_add($params);
  160. }
  161. public function testPushOtherPhones()
  162. {
  163. $time = time();
  164. Log::record("push message start:{$time}",Log::DEBUG);
  165. for ($i = 0; $i < 10; $i++)
  166. {
  167. $this->push_order(1092,60221,$time,$i);
  168. // $this->push_order(1093,65771,$time,$i);
  169. // $this->push_order(1094,65772,$time,$i);
  170. // $this->push_order(1095,65773,$time,$i);
  171. // $this->push_order(1096,65774,$time,$i);
  172. }
  173. Log::record("push message end",Log::DEBUG);
  174. //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillThird::testPushOtherPhones)( .*)?$/" --test-suffix TestRefillThird.php /var/www/html/test
  175. }
  176. public function testPushLzThird()
  177. {
  178. $params = [ 'mchid' => 1092,
  179. 'buyer_id' => 60221,
  180. 'amount' => refill\util::ThirdRefillAmount,
  181. 'mch_order' => $this->make_sn(),
  182. 'notify_url' => '',
  183. 'org_quality' => 1,
  184. 'card_type' => mtopcard\ThirdRefillCard,
  185. 'card_no' => '13911129867',
  186. 'product_code' => 'DY_XYZ_30_LOW',
  187. 'quantity' => 1,
  188. 'third_card_type' => 1
  189. ];
  190. $ret = refill\util::push_addthird($params);
  191. }
  192. public function testXXX()
  193. {
  194. $thrid_refill = Model('thrid_refill');
  195. $third_info = $thrid_refill->getThird(1140016178);
  196. $new_info = $thrid_refill->trans_order($third_info);
  197. }
  198. public function testAddthirdLocal()
  199. {
  200. $params = [ 'mchid' => 1092,
  201. "act" => "refill",
  202. "op" => "add_third",
  203. 'order_sn' => $this->make_sn(),
  204. 'notifyurl' => 'https://www.xyzshops.cn/mobile/callback/testcb.php',
  205. 'card_type' => 1,
  206. 'cardno' => '403149064',
  207. 'product_code' => 'DY_XYZ_30_LOW',
  208. 'quantity' => 5
  209. ];
  210. $proxy = new refill_proxy('210fe406954220f56085997d6a4c5b80');
  211. $proxy->send("http://192.168.1.220/mobile/index.php",$params);
  212. }
  213. public function testPushXYZThird()
  214. {
  215. $params = [ 'mchid' => 1092,
  216. 'buyer_id' => 60221,
  217. 'amount' => refill\util::ThirdRefillAmount,
  218. 'mch_order' => $this->make_sn(),
  219. 'notify_url' => '',
  220. 'org_quality' => 1,
  221. 'card_type' => mtopcard\ThirdRefillCard,
  222. 'card_no' => '403149064',
  223. 'product_code' => 'XYZ100744',
  224. 'quantity' => 5,
  225. 'third_card_type' => 1
  226. ];
  227. $ret = refill\util::push_addthird($params);
  228. }
  229. private function make_sn()
  230. {
  231. return mt_rand(1000, 9999)
  232. . sprintf('%010d', time())
  233. . sprintf('%06d', (float)microtime() * 1000000);
  234. }
  235. public function testLingzhthirdPhone()
  236. {
  237. $providers = $this->getProvider('lingzhthird');
  238. $resp = $providers->add(18500608333, 5, 10,
  239. ['order_sn' => $this->make_sn(),
  240. 'goods_id' => 6559,
  241. 'quantity'=>5,'product_code'=>'XYZ100744','third_card_type'=>1]);
  242. }
  243. public function testFNMS()
  244. {
  245. $providers = $this->getProvider('feinimoshu_hf','RefillPhone');
  246. $order_sn = $this->make_sn();
  247. // [$state, $ch_order, $neterr] = $providers->add(18500608333, 5, 30, ['order_sn' => $order_sn]);
  248. $providers->query(['order_sn' => '60711623734193929309']);
  249. }
  250. public function testFNMSCB()
  251. {
  252. $params = ['appid' => 'CZ30533982',
  253. 'order' => 'D20210616111088971260328',
  254. 'morder' => '1879340677155108772500',
  255. 'status' => '2',
  256. 'cash' => '30',
  257. 'vnum' => '110103308152106161039260597703',
  258. 'actual_cash' => '28.86',
  259. 'signature' => 'c3077297f26f6231eeaa31ccb8c16148'];
  260. $provider = $this->getProvider('feinimoshu_hf','RefillCallBack');
  261. $ret = $provider->verify($params);
  262. $this->assertTrue($ret,'Verify is OK');
  263. $provider->notify($params);
  264. }
  265. private function getProvider($name,$type = 'RefillPhone')
  266. {
  267. $file = BASE_HELPER_RAPI_PATH . "/$name/{$type}.php";
  268. if(!file_exists($file)){
  269. Log::record("provider api file={$file} not exist.",Log::DEBUG);
  270. return false;
  271. } else {
  272. require_once($file);
  273. Log::record("file={$file} load success.",Log::DEBUG);
  274. }
  275. $class_name = "refill\\{$name}\\{$type}";
  276. if (class_exists($class_name, false)) {
  277. $caller = new $class_name([]);
  278. return $caller;
  279. } else {
  280. $error = "Base Error: class {$class_name} isn't exists!";
  281. Log::record($error, Log::ERR);
  282. return false;
  283. }
  284. }
  285. public function testCallBack()
  286. {
  287. $body = '{"AppKey":"211394658","TimesTamp":"1620987358973","MOrderID":"7088040674302538334319","OrderID":"210514101558013001","State":"2","ChargeAccount":"403149064","Version":"1.0","BuyCount":"5","Attach":"","Sign":"BF8D2895A6C214931A511AE12EB9E8EE"}';
  288. $params = json_decode($body, true);
  289. refill\RefillFactory::instance()->notify('sctongqian', $params);
  290. }
  291. public function testInstance()
  292. {
  293. refill\RefillFactory::instance()->notify_merchant(1,false);
  294. }
  295. public function testEncrypt()
  296. {
  297. $mod_mch = Model('merchant');
  298. $mch_info = $mod_mch->getMerchant(9618);
  299. $mod_third = Model('thrid_refill');
  300. $thrid_info = $mod_third->getThird(6244720);
  301. if (!empty($mch_info) && !empty($thrid_info))
  302. {
  303. $card_info = $thrid_info['card_info'];
  304. if (!empty($card_info)) {
  305. $passwd = $mch_info['secure_key'];
  306. $encrypt = openssl_encrypt($card_info,'AES-128-CBC',$passwd);
  307. if($encrypt != false) {
  308. $params['card_info'] = $encrypt;
  309. }
  310. $output = openssl_decrypt($encrypt, 'AES-128-CBC', $passwd);
  311. }
  312. }
  313. }
  314. public function testZanzan()
  315. {
  316. $providers = $this->getProvider('zanzan','RefillPhone');
  317. // $order_sn = $this->make_sn();
  318. // [$state, $ch_order, $neterr] = $providers->add(13911129867, 5, 100, ['order_sn' => $order_sn]);
  319. // [$state, $ch_order, $neterr] = $providers->add(18500608333, 5, 100, ['order_sn' => $order_sn]);
  320. // $providers->query(['ch_trade_no' => '','order_sn' => '4599550676464663945778']);
  321. $resp = $providers->balance();
  322. }
  323. public function testSuning()
  324. {
  325. $providers = $this->getProvider('suning','RefillPhone');
  326. $providers->mStoreID = 61;
  327. $order_sn = $this->make_sn();
  328. $resp = $providers->add(14011221111, 7, 1,
  329. ['order_sn' => $order_sn, 'goods_id' => 6619,
  330. 'quantity' => 5, 'product_code' => 'XYZ100745', 'third_card_type' => 1]);
  331. }
  332. public function testSuningCardKey()
  333. {
  334. $providers = $this->getProvider('suning','RefillPhone');
  335. $providers->mStoreID = 61;
  336. $order_sn = $this->make_sn();
  337. $resp = $providers->add('', 7, 1,
  338. ['order_sn' => $order_sn, 'goods_id' => 6619,
  339. 'quantity' => 5, 'product_code' => 'XYZ100745', 'third_card_type' => 1]);
  340. }
  341. public function testSendMobile()
  342. {
  343. $phone = '13911129867';
  344. $amount = 30;
  345. $url = "https://www.xyzshops.cn" . "/mobile/index.php";
  346. $params = ['mchid' => 1092,
  347. 'cardno' => $phone,
  348. 'amount' => $amount,
  349. "act" => "refill",
  350. "op" => "add",
  351. 'order_sn' => $this->make_sn(),
  352. 'notifyurl' => "https://www.xyzshops.cn/signature.php"];
  353. $proxy = new refill_proxy("210fe406954220f56085997d6a4c5b80");
  354. $resp = $proxy->send($url, $params);
  355. }
  356. public function testLoad()
  357. {
  358. refill\RefillFactory::instance();
  359. }
  360. public function testManualCancel()
  361. {
  362. $order_id = 87845887;
  363. try {
  364. $mod_order = Model('vr_order');
  365. $logic_vr_order = Logic("vr_order");
  366. $tran = new trans_wapper($mod_order,'manual_cancel state trans');
  367. $order_info = $mod_order->getOrderInfo(['order_id' => $order_id],'*',true,true);
  368. $logic_vr_order->changeOrderStateCancel($order_info, '', "后台手动回调通知失败",true,true);
  369. $tran->commit();
  370. return true;
  371. }
  372. catch (Exception $ex) {
  373. $tran->rollback();
  374. Log::record("manual_cancel exception:{$ex->getMessage()}",Log::ERR);
  375. return false;
  376. }
  377. }
  378. public function testDingHui()
  379. {
  380. $content = 'method=order.charge.status.update.notify&format=json&sign=60d4e658cb730b9d8cc0c451414de9b51b79d14fa217261f7bbcf4a3472553b093a5c2377abba9573ed9d5e1a39a9f693830671ff1e641cc97a9782d2b2f393bed6a7bd22be0c642a13e20a7c6cf9f562c11ae65335758bd58ee55853b555cc2e511b6655c6e944a9defa6f0247263578d1554ff7709a7ced90db93911562dcb485518a4da3c21cb650ff01cacfcfa8dd9de533f5a5be2accc065e23cbd38b1b104e15feb3ce823c8cb7c7d5adf3fef0be768d8c25dc813a9112a14ec54a9e2ee517a5ba5b9ce2234dd4329b61c5456a82405aa6d2a307b4ec04be52bd1e3e5b204a2a4d7899d6fbf0fc09cd443cddc947f02bf58730142e9edc2b98eeeae086&message=GYmjEFMoy5jUfg%2FJu7NRCSyaoyg2fu9EWpABAHb55xKpkvIedqXPDqRwG6Lo7iNx0A2yc6%2FIaU7vqwNV9YEVZOwHBDtsGXuHK1GCq5KUaW70pq1wEKr6kgjAHDITH7XdB3jmdSAQFhQYTi5hCz5EWWAzRKLYgTZeDksePKshm67QDbJzr8hpTu%2BrA1X1gRVkVqAL750crFPclgeWEYFG4mO4ZlmqygUrgz4si%2BseZ3f0pq1wEKr6kgjAHDITH7XdkFLNHratZfufbZKIZ5r%2BCA%3D%3D&msgtype=notify_msg&version=V2.0&app_id=yeziapi&notify_id=0000017c83f4786201547473800e31ee&timestamp=1634301409378';
  381. // $params = parse_url($content,PHP_URL_PATH);
  382. parse_str($content,$params);
  383. $provider = $this->getProvider('dinghui','RefillCallBack');
  384. $ret = $provider->verify($params);
  385. $this->assertTrue($ret,'Verify is OK');
  386. $provider->notify($params);
  387. }
  388. }