TestRefillThird.php 12 KB

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