TestRefillThird.php 12 KB

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