TestRefillThird.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  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/signature.php',
  30. 'card_type' => 1,
  31. 'cardno' => '608168539',
  32. 'product_code' => 'XYZ100772',
  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' => 9618,
  179. 'buyer_id' => 6,
  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' => '403149064',
  186. 'product_code' => 'LZ100744',
  187. 'quantity' => 5,
  188. 'third_card_type' => 1
  189. ];
  190. $ret = refill\util::push_addthird($params);
  191. }
  192. public function testAddthirdLocal()
  193. {
  194. $params = [ 'mchid' => 1092,
  195. "act" => "refill",
  196. "op" => "add_third",
  197. 'order_sn' => $this->make_sn(),
  198. 'notifyurl' => 'https://www.xyzshops.cn/mobile/signature.php',
  199. 'card_type' => 1,
  200. 'cardno' => '403149064',
  201. 'product_code' => 'XYZ100744',
  202. 'quantity' => 5
  203. ];
  204. $proxy = new refill_proxy('210fe406954220f56085997d6a4c5b80');
  205. $proxy->send("http://192.168.1.220/mobile/index.php",$params);
  206. }
  207. public function testPushXYZThird()
  208. {
  209. $params = [ 'mchid' => 1092,
  210. 'buyer_id' => 60221,
  211. 'amount' => refill\util::ThirdRefillAmount,
  212. 'mch_order' => $this->make_sn(),
  213. 'notify_url' => '',
  214. 'org_quality' => 1,
  215. 'card_type' => mtopcard\ThirdRefillCard,
  216. 'card_no' => '403149064',
  217. 'product_code' => 'XYZ100744',
  218. 'quantity' => 5,
  219. 'third_card_type' => 1
  220. ];
  221. $ret = refill\util::push_addthird($params);
  222. }
  223. private function make_sn()
  224. {
  225. return mt_rand(1000, 9999)
  226. . sprintf('%010d', time())
  227. . sprintf('%06d', (float)microtime() * 1000000);
  228. }
  229. public function testLingzhthirdPhone()
  230. {
  231. $providers = $this->getProvider('lingzhthird');
  232. $resp = $providers->add(18500608333, 5, 10,
  233. ['order_sn' => $this->make_sn(),
  234. 'goods_id' => 6559,
  235. 'quantity'=>5,'product_code'=>'XYZ100744','third_card_type'=>1]);
  236. }
  237. public function testFNMS()
  238. {
  239. $providers = $this->getProvider('feinimoshu_hf','RefillPhone');
  240. $order_sn = $this->make_sn();
  241. // [$state, $ch_order, $neterr] = $providers->add(18500608333, 5, 30, ['order_sn' => $order_sn]);
  242. $providers->query(['order_sn' => '60711623734193929309']);
  243. }
  244. public function testFNMSCB()
  245. {
  246. $params = ['appid' => 'CZ30533982',
  247. 'order' => 'D20210616111088971260328',
  248. 'morder' => '1879340677155108772500',
  249. 'status' => '2',
  250. 'cash' => '30',
  251. 'vnum' => '110103308152106161039260597703',
  252. 'actual_cash' => '28.86',
  253. 'signature' => 'c3077297f26f6231eeaa31ccb8c16148'];
  254. $provider = $this->getProvider('feinimoshu_hf','RefillCallBack');
  255. $ret = $provider->verify($params);
  256. $this->assertTrue($ret,'Verify is OK');
  257. $provider->notify($params);
  258. }
  259. private function getProvider($name,$type = 'RefillPhone')
  260. {
  261. $file = BASE_HELPER_RAPI_PATH . "/$name/{$type}.php";
  262. if(!file_exists($file)){
  263. Log::record("provider api file={$file} not exist.",Log::DEBUG);
  264. return false;
  265. } else {
  266. require_once($file);
  267. Log::record("file={$file} load success.",Log::DEBUG);
  268. }
  269. $class_name = "refill\\{$name}\\{$type}";
  270. if (class_exists($class_name, false)) {
  271. $caller = new $class_name([]);
  272. return $caller;
  273. } else {
  274. $error = "Base Error: class {$class_name} isn't exists!";
  275. Log::record($error, Log::ERR);
  276. return false;
  277. }
  278. }
  279. public function testCallBack()
  280. {
  281. $body = '{"AppKey":"211394658","TimesTamp":"1620987358973","MOrderID":"7088040674302538334319","OrderID":"210514101558013001","State":"2","ChargeAccount":"403149064","Version":"1.0","BuyCount":"5","Attach":"","Sign":"BF8D2895A6C214931A511AE12EB9E8EE"}';
  282. $params = json_decode($body, true);
  283. refill\RefillFactory::instance()->notify('sctongqian', $params);
  284. }
  285. public function testInstance()
  286. {
  287. refill\RefillFactory::instance()->notify_merchant(1,false);
  288. }
  289. public function testEncrypt()
  290. {
  291. $mod_mch = Model('merchant');
  292. $mch_info = $mod_mch->getMerchant(9618);
  293. $mod_third = Model('thrid_refill');
  294. $thrid_info = $mod_third->getThird(6244720);
  295. if (!empty($mch_info) && !empty($thrid_info))
  296. {
  297. $card_info = $thrid_info['card_info'];
  298. if (!empty($card_info)) {
  299. $passwd = $mch_info['secure_key'];
  300. $encrypt = openssl_encrypt($card_info,'AES-128-CBC',$passwd);
  301. if($encrypt != false) {
  302. $params['card_info'] = $encrypt;
  303. }
  304. $output = openssl_decrypt($encrypt, 'AES-128-CBC', $passwd);
  305. }
  306. }
  307. }
  308. public function testZanzan()
  309. {
  310. $providers = $this->getProvider('zanzan','RefillPhone');
  311. // $order_sn = $this->make_sn();
  312. // [$state, $ch_order, $neterr] = $providers->add(13911129867, 5, 100, ['order_sn' => $order_sn]);
  313. // [$state, $ch_order, $neterr] = $providers->add(18500608333, 5, 100, ['order_sn' => $order_sn]);
  314. // $providers->query(['ch_trade_no' => '','order_sn' => '4599550676464663945778']);
  315. $resp = $providers->balance();
  316. }
  317. public function testSuning()
  318. {
  319. $providers = $this->getProvider('suning','RefillPhone');
  320. $providers->mStoreID = 61;
  321. $order_sn = $this->make_sn();
  322. $resp = $providers->add(14011221111, 7, 1,
  323. ['order_sn' => $order_sn, 'goods_id' => 6619,
  324. 'quantity' => 5, 'product_code' => 'XYZ100745', 'third_card_type' => 1]);
  325. }
  326. public function testSuningCardKey()
  327. {
  328. $providers = $this->getProvider('suning','RefillPhone');
  329. $providers->mStoreID = 61;
  330. $order_sn = $this->make_sn();
  331. $resp = $providers->add('', 7, 1,
  332. ['order_sn' => $order_sn, 'goods_id' => 6619,
  333. 'quantity' => 5, 'product_code' => 'XYZ100745', 'third_card_type' => 1]);
  334. }
  335. public function testSendMobile()
  336. {
  337. $phone = '13911129867';
  338. $amount = 30;
  339. $url = "https://www.xyzshops.cn" . "/mobile/index.php";
  340. $params = ['mchid' => 1092,
  341. 'cardno' => $phone,
  342. 'amount' => $amount,
  343. "act" => "refill",
  344. "op" => "add",
  345. 'order_sn' => $this->make_sn(),
  346. 'notifyurl' => "https://www.xyzshops.cn/signature.php"];
  347. $proxy = new refill_proxy("210fe406954220f56085997d6a4c5b80");
  348. $resp = $proxy->send($url, $params);
  349. }
  350. public function testLoad()
  351. {
  352. refill\RefillFactory::instance();
  353. }
  354. public function testManualCancel()
  355. {
  356. $order_id = 87845887;
  357. try {
  358. $mod_order = Model('vr_order');
  359. $logic_vr_order = Logic("vr_order");
  360. $tran = new trans_wapper($mod_order,'manual_cancel state trans');
  361. $order_info = $mod_order->getOrderInfo(['order_id' => $order_id],'*',true,true);
  362. $logic_vr_order->changeOrderStateCancel($order_info, '', "后台手动回调通知失败",true,true);
  363. $tran->commit();
  364. return true;
  365. }
  366. catch (Exception $ex) {
  367. $tran->rollback();
  368. Log::record("manual_cancel exception:{$ex->getMessage()}",Log::ERR);
  369. return false;
  370. }
  371. }
  372. public function testDingHui()
  373. {
  374. $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';
  375. // $params = parse_url($content,PHP_URL_PATH);
  376. parse_str($content,$params);
  377. $provider = $this->getProvider('dinghui','RefillCallBack');
  378. $ret = $provider->verify($params);
  379. $this->assertTrue($ret,'Verify is OK');
  380. $provider->notify($params);
  381. }
  382. }