TestRefillThird.php 12 KB

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