TestRefill.php 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106
  1. <?php
  2. use PHPUnit\Framework\TestCase;
  3. use const mtopcard\SinopecCard;
  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_CORE_PATH . '/framework/function/http.php');
  10. require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
  11. require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
  12. const LocalTest = 1;
  13. const NetTest = 2;
  14. const CurrentTest = LocalTest;
  15. class TestRefill extends TestCase
  16. {
  17. private $mReqHost;
  18. private $mKey;
  19. private $mMchid;
  20. public function __construct(?string $name = null, array $data = [], $dataName = '')
  21. {
  22. parent::__construct($name, $data, $dataName);
  23. if (CurrentTest == LocalTest) {
  24. $this->mReqHost = BASE_SITE_URL;
  25. $this->mMchid = 1;
  26. $this->mKey = '1ff02223b771c0414468c8892151c602';
  27. } else {
  28. $this->mReqHost = 'https://www.xyzshops.cn';
  29. $this->mMchid = 1092;
  30. $this->mKey = '210fe406954220f56085997d6a4c5b80';
  31. }
  32. }
  33. public static function setUpBeforeClass(): void
  34. {
  35. Base::run_util();
  36. refill\RefillFactory::instance();
  37. }
  38. public function testFactory()
  39. {
  40. $providers = refill\RefillFactory::instance();
  41. }
  42. private function make_sn()
  43. {
  44. return mt_rand(1000, 9999)
  45. . sprintf('%010d', time())
  46. . sprintf('%06d', (float)microtime() * 1000000);
  47. }
  48. public function testRandomMobile()
  49. {
  50. $no = "1" . mt_rand(1, 9999999999);
  51. Log::record("phone no={$no}",Log::DEBUG);
  52. }
  53. public function testBJBAddPhone()
  54. {
  55. $providers = new refill\bjb\RefillPhone([]);
  56. for ($i = 3; $i > 0; --$i) {
  57. $resp = $providers->add(13911129867, 4, 10, ['order_sn' => $this->make_sn()]);
  58. $resp = $providers->add(18500608333, 4, 10, ['order_sn' => $this->make_sn()]);
  59. $resp = $providers->add(18510683168, 4, 10, ['order_sn' => $this->make_sn()]);
  60. $resp = $providers->add(18513846008, 4, 10, ['order_sn' => $this->make_sn()]);
  61. $resp = $providers->add(18518237398, 4, 10, ['order_sn' => $this->make_sn()]);
  62. }
  63. }
  64. public function testOilticket()
  65. {
  66. $providers = new refill\bjb\RefillPhone([]);
  67. }
  68. public function testBjbRet()
  69. {
  70. $resp = '0|提交成功|14936.8600';
  71. $resp = explode('|' , $resp);
  72. }
  73. public function testIpWhiteList()
  74. {
  75. $x = serialize(['47.99.57.105']);
  76. $ips = unserialize('a:1:{i:0;s:12:"47.99.57.105";}');
  77. if (!empty($ips)) {
  78. $addr = '47.99.57.105';
  79. Log::record("request ip:{$addr}", Log::DEBUG);
  80. if (!in_array($addr, $ips)) {
  81. throw new Exception("请求地址不在白名单中");
  82. }
  83. }
  84. }
  85. public function testBaizePhone()
  86. {
  87. $providers = new refill\baizeyd\RefillPhone([]);
  88. // $resp = $providers->add(17801048874, 5, 10, ['order_sn' => $this->make_sn()]);
  89. $resp = $providers->query(['order_sn' => '930668700375312006']);
  90. // $str = 'amount=10.00&orderId=720668384771999671&phone=13911129867&payTime=2021-03-06+22%3A26%3A12&sign=94dfe83221f7768650e70cce08879b60&appKey=uECmTOFAY6RPCTtI&payUrl=&statusDes=%E6%94%AF%E4%BB%98%E5%A4%B1%E8%B4%A5&status=7';
  91. // $input = $this->parse_request($str);
  92. // $input['amount'] = 10.00;
  93. // $input['orderId'] = '92391614943913061206';
  94. // $input['phone'] = 17801048874;
  95. // $input['payTime'] = '2021-03-05 19:31:55';
  96. // $input['sign'] = 'bef6ae50319fb1e8cb3f21302f0abef8';
  97. // $input['appKey'] = 'uECmTOFAY6RPCTtI';
  98. // $input['payUrl'] = '';
  99. // $input['statusDes'] = '支付失败';
  100. // $input['status'] = 7;
  101. // refill\RefillFactory::instance()->notify('baizeyd',$input);
  102. }
  103. private function parse_request($squery)
  104. {
  105. if(empty($squery)) return [];
  106. $result = [];
  107. $params = preg_split('/&/', $squery);
  108. foreach ($params as $pair)
  109. {
  110. if(empty($pair)) continue;
  111. $kv = explode('=', $pair);
  112. $count = count($kv);
  113. if($count === 1) {
  114. $key = $kv[0];
  115. $val = "";
  116. }
  117. elseif($count === 2) {
  118. $key = $kv[0];
  119. $val = urldecode($kv[1]);
  120. }
  121. else {
  122. continue;
  123. }
  124. if(!empty($key)) {
  125. $result[$key] = $val;
  126. }
  127. }
  128. return $result;
  129. }
  130. public function testAmPhone()
  131. {
  132. // $providers = new refill\aming\RefillPhone([]);
  133. // $resp = $providers->add(18500608333, 5, 10, ['order_sn' => $this->make_sn()]);
  134. $input['result'] = 'fail';
  135. $input['msg'] = 0;
  136. $input['order'] = 'null';
  137. $input['phone_no'] = 18500608333;
  138. $input['sign'] = 'c925ad19c63c3eb36ffc52d938e24604';
  139. $input['amount'] = '10.00';
  140. $input['op_no'] = '42601615096072517841';
  141. refill\RefillFactory::instance()->notify('aming',$input);
  142. }
  143. public function testBhcPhone()
  144. {
  145. $providers = new refill\binghc\RefillPhone([]);
  146. $resp = $providers->query(['order_sn' => 250668618955902006]);
  147. // $input['result'] = 'fail';
  148. // $input['msg'] = 0;
  149. // $input['order'] = 'null';
  150. // $input['phone_no'] = 18500608333;
  151. // $input['sign'] = 'c3aa38ee07cd1b69bfd5ead56f6da8d6';
  152. // $input['amount'] = '10.00';
  153. // $input['op_no'] = '24061615096361999002';
  154. // refill\RefillFactory::instance()->notify('binghc',$input);
  155. }
  156. public function testRuishunPhone()
  157. {
  158. // $providers = new refill\ruishun\RefillPhone([]);
  159. // $resp = $providers->add(18500608333, 5, 10, ['order_sn' => $this->make_sn()]);
  160. $input['result'] = 'fail';
  161. $input['msg'] = 0;
  162. $input['order'] = null;
  163. $input['phone_no'] = 18500608333;
  164. $input['sign'] = 'e234f7d1c0458ca236f53a0008436b46';
  165. $input['amount'] = "10.00";
  166. $input['op_no'] = '76361615095403188513';
  167. refill\RefillFactory::instance()->notify('ruishun',$input);
  168. }
  169. public function testWuchenPhone()
  170. {
  171. $providers = new refill\wuchen\RefillPhone([]);
  172. // $resp = $providers->add('13699279618', 5, 30, ['order_sn' => $this->make_sn()]);
  173. $resp = $providers->query(['order_sn' => '790668630498425006']);
  174. // $input['app_id'] = '70016';
  175. // $input['message'] = 'fail';
  176. // $input['order_sn'] = '43101615277293035501';
  177. // $input['platform_order_id'] = '';
  178. // $input['sign'] = '5ea59f8ac51a518f2c622824d7db2a04';
  179. // $input['state'] = "fail";
  180. // $input['sys_sn'] = '202103091608231836913889';
  181. // $input['timestamp'] = '1615277361';
  182. // refill\RefillFactory::instance()->notify('wuchen',$input);
  183. }
  184. public function testYibaoPhone()
  185. {
  186. $providers = new refill\yibao\RefillPhone([]);
  187. $resp = $providers->add('13699279618', 5, 30, ['order_sn' => $this->make_sn()]);
  188. // $resp = $providers->query(['order_sn' => '790668630498425006']);
  189. }
  190. public function testWeisPhone()
  191. {
  192. $providers = new refill\weisyd\RefillPhone([]);
  193. $resp = $providers->add(17801048874, 4, 10, ['order_sn' => $this->make_sn()]);
  194. }
  195. public function testXcPhone()
  196. {
  197. $providers = new refill\xc\RefillPhone([]);
  198. $resp = $providers->add(18500608333, 5, 100, ['order_sn' => $this->make_sn()]);
  199. }
  200. public function testAfandPhone()
  201. {
  202. $providers = new refill\afand\RefillPhone([]);
  203. for ($i = 3; $i > 0; --$i) {
  204. $resp = $providers->add(18518267398, 4, 30, ['order_sn' => $this->make_sn()]);
  205. }
  206. }
  207. public function testAfandengPhone()
  208. {
  209. $providers = new refill\afandeng\RefillPhone([]);
  210. $resp = $providers->add(13699279618, 4, 30, ['order_sn' => $this->make_sn()]);
  211. }
  212. public function testYifaPhone()
  213. {
  214. $providers = new refill\yifa\RefillPhone([]);
  215. $resp = $providers->add(15120035568, 5, 50, ['order_sn' => $this->make_sn()]);
  216. }
  217. public function testTianjtOil()
  218. {
  219. $cardno = 1000111100021211884;
  220. $providers = new refill\tianjt\RefillOil([]);
  221. $resp = $providers->add($cardno, 2, 500, ['order_sn' => $this->make_sn()]);
  222. }
  223. public function testTianxPhone()
  224. {
  225. $cardno = 13699279618;
  226. $providers = new refill\tianx\RefillPhone([]);
  227. $resp = $providers->add($cardno, 4, 50, ['order_sn' => $this->make_sn()]);
  228. }
  229. public function testWeitPhone()
  230. {
  231. $providers = new refill\weit\RefillPhone([]);
  232. for ($i = 0;$i<=10;$i++){
  233. $resp = $providers->add(18500608333, 5, 10, ['order_sn' => $this->make_sn()]);
  234. }
  235. }
  236. public function testWeitCB()
  237. {
  238. $params['sign'] = 'af820c33472f4b571fa0c48483dfb975';
  239. $params['status'] = 0;
  240. $params['price'] = 30;
  241. $params['op_order_id'] = '';
  242. $params['mch_order_id'] = '900664281823957221';
  243. $params['pt_order_id'] = '2021011802434412825405218901';
  244. $params['pay_type'] = '';
  245. $params['tel'] = 18500608333;
  246. $params['mchid'] = 10014;
  247. $resp = http_request($this->mReqHost . "/mobile/refill_weit.php", $params , 'POST');
  248. }
  249. public function testYifaCB()
  250. {
  251. $body = '{"app_id":"e4a61b2acf1119c72c1ed9b61781494e","nonce_str":"OQMEBRQWJGPKOWYUXDVPTNMLEQJHXFWG","timestamp":1610275083,"order_sn":"161027325773032634","coder_order_sn":"60641610273255214687","isp_order_sn":null,"phone":"15120035568","amount":"94.000","discount":"0.9400","create_time":"2021-01-10 18:07:42","recharge_time":"","status":"fail","channel_id":3,"sign":"47278AD74EFA7F5FC8DE3A6D362C409B"}';
  252. $input = json_decode($body,true);
  253. refill\RefillFactory::instance()->notify('yifa',$input);
  254. }
  255. public function testBjbQuery()
  256. {
  257. $providers = new refill\bjb\RefillPhone([]);
  258. $refill_info = ['order_sn' => 110667993758599771, 'ch_trade_no' => 499, 'card_no' => 1000111200005252927];
  259. $resp = $providers->query($refill_info);
  260. }
  261. public function testXcQuery()
  262. {
  263. $providers = new refill\xc\RefillPhone([]);
  264. $refill_info = ['order_sn' => 950663423236726632, 'ch_trade_no' => 499, 'card_no' => 1000111200005252927];
  265. $resp = $providers->query($refill_info);
  266. }
  267. public function testTianjtQuery()
  268. {
  269. $providers = new refill\tianjt\RefillOil([]);
  270. $refill_info = ['order_sn' => 680665862267622221, 'ch_trade_no' => 499, 'card_no' => 1000111200005252927];
  271. $resp = $providers->query($refill_info);
  272. }
  273. public function testSaihuOil()
  274. {
  275. $providers = new refill\saihu\RefillOil([]);
  276. $resp = $providers->add(1000111100021211884, 2, 100, ['order_sn' => $this->make_sn()]);
  277. }
  278. public function testBdtOil()
  279. {
  280. $providers = new refill\bdt\RefillOil([]);
  281. $resp = $providers->add(1000111100021211884, 2, 100, ['order_sn' => '200229600556618886']);
  282. }
  283. public function testGFTDOil()
  284. {
  285. $providers = new refill\gftd\RefillOil([]);
  286. $resp = $providers->add(1000111100020445281, mtopcard\SinopecCard, 100, ['order_sn' => $this->make_sn()]);
  287. }
  288. public function testGFTDCB()
  289. {
  290. $data = '{"channelOrderNumber":"79091610959059372019","orderNumber":"GYFL1610959060397001","message":"充值成功","signature":"881036222bd8f067ff47d248c75f4c8d","voucher":"","status":101}';
  291. $url = "http://192.168.1.220/mobile/refill_gftd.php?" . $data;
  292. $resp = http_post_data($url, $data, ['Content-Type: application/json;charset=UTF-8;','Accept:application/json;charset=UTF-8;']);
  293. }
  294. public function testJiecPhone()
  295. {
  296. $providers = new refill\jiec\RefillPhone([]);
  297. $resp = $providers->add('18500608333', 5, 30, ['order_sn' => $this->make_sn()]);
  298. }
  299. public function testBxtwtCB()
  300. {
  301. $data = '{"order_number":18219726,"shipping_status":4,"shipping_status_desc":"发货失败","shipping_status_message":"","sign":"863b4d972f2a4d39a9af7396879116c4","voucher":"","vouchertype":"","voucherurl":"","tradeNo":"100662475851197741"}';
  302. }
  303. public function testTianjtJDVerify()
  304. {
  305. $data = 'onlystr=920661883198026632&sign=533151e3f0dff5f507786aabc37b18f7&amt=100&notifyurl=https%3A%2F%2Fwww.xyzshops.cn%2Fmobile%2Frefill_tianjt.php&jdno&cardtype=Sinoepc&batchid=26106&cardno=1000111100020654226&orgid=1590993600&status=3';
  306. $url = "http://192.168.1.220/mobile/refill_tianjt.php?" . $data;
  307. $resp = http_request($url);
  308. }
  309. public function testSuhcPDD()
  310. {
  311. $data = 'onlystr=820663525320005221&pddno&sign=4b1e8645f7541ced34855779448d9d52&amt=100&notifyurl=https%3A%2F%2Fwww.xyzshops.cn%2Fmobile%2Frefill_suhcpdd.php&cardtype=Sinoepc&batchid=3&cardno=1000111100020445281&orgid=1590993600&status=2';
  312. $url = "https://www.xyzshops.cn/mobile/refill_suhcpdd.php?" . $data;
  313. $resp = http_request($url);
  314. }
  315. public function testSuhcTMVerify()
  316. {
  317. $data = 'onlystr=180662473867058221&sign=5ff5f95d54a89e78dbb49923f6b20c08&amt=100&notifyurl=https%3A%2F%2Fwww.xyzshops.cn%2Fmobile%2Frefill_suhctm.php&cardtype=Sinoepc&batchid=3&cardno=1000111100020445281&orgid=1590993600&status=3';
  318. $url = "https://www.xyzshops.cn/mobile/refill_suhctm.php?" . $data;
  319. $resp = http_request($url);
  320. }
  321. public function testBeixtVerify()
  322. {
  323. $data = '{"order_number":18219726,"shipping_status":4,"shipping_status_desc":"发货失败","shipping_status_message":"","sign":"863b4d972f2a4d39a9af7396879116c4","voucher":"","vouchertype":"","voucherurl":"","tradeNo":"100662475851197741"}';
  324. $url = "https://www.xyzshops.cn/mobile/refill_bxtwt.php";
  325. $headers = ['Content-Type: application/json'];
  326. $resp = http_post_data($url, $data, $headers);
  327. }
  328. public function testInput()
  329. {
  330. $input = fopen("php://input", "rw");
  331. file_put_contents($input, 'xxxx');
  332. $content = file_get_contents('php://input');
  333. }
  334. public function testUrl()
  335. {
  336. $data = 'onlystr=190661874318128632&sign=9eb60765c356341fd41c9bec6526f46a&amt=1000&notifyurl=https%3A%2F%2Fwww.xyzshops.cn%2Fmobile%2Frefill_suhc.php&jdno&cardtype=Sinoepc&batchid=25940&cardno=1000111100012304048&orgid=1590993600&status=2';
  337. $params = preg_split('/&/', $data);
  338. foreach ($params as $pair) {
  339. $kv = explode('=', $pair);
  340. $count = count($kv);
  341. if ($count === 1) {
  342. $key = $kv[0];
  343. $val = "";
  344. } elseif ($count === 2) {
  345. $key = $kv[0];
  346. $val = $kv[1];
  347. } else {
  348. continue;
  349. }
  350. Log::record("{$key}:{$val}", Log::DEBUG);
  351. }
  352. }
  353. public function testAddoil()
  354. {
  355. $url = $this->mReqHost . "/mobile/index.php";
  356. $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php';
  357. $params = ['mchid' => $this->mMchid,
  358. 'cardno' => '1000111100020445281',
  359. 'amount' => "100",
  360. "act" => "refill",
  361. "op" => "add",
  362. 'order_sn' => $this->make_sn(),
  363. 'notifyurl' => $notifyurl];
  364. $resp = $this->send_md5($url, $params);
  365. Log::record($resp, Log::DEBUG);
  366. }
  367. public function testBalance()
  368. {
  369. $url = $this->mReqHost . "/mobile/index.php";
  370. $params = ['mchid' => 1092,
  371. "act" => "refill",
  372. "op" => "balance"];
  373. $resp = $this->send_md5($url, $params);
  374. Log::record($resp, Log::DEBUG);
  375. }
  376. public function testAddPhoe()
  377. {
  378. $phones = [//13911129867,
  379. 18500608333,
  380. 18510683168,
  381. 18513846008,
  382. 18518237398];
  383. $amount = 10;
  384. for ($i = 0; $i < 3; $i++) {
  385. foreach ($phones as $phone) {
  386. $url = $this->mReqHost . "/mobile/index.php";
  387. $params = ['mchid' => 1092,
  388. 'cardno' => $phone,
  389. 'amount' => $amount,
  390. "act" => "refill",
  391. "op" => "add",
  392. 'order_sn' => $this->make_sn(),
  393. 'notifyurl' => $this->mReqHost . "/mobile/refill_xyz.php"];
  394. $resp = $this->send_md5($url, $params);
  395. Log::record($resp, Log::DEBUG);
  396. }
  397. }
  398. }
  399. public function testProxyHelper()
  400. {
  401. $phone = '13911129867';
  402. $amount = 100;
  403. $url = $this->mReqHost . "/mobile/index.php";
  404. $params = ['mchid' => 1090,
  405. 'cardno' => $phone,
  406. 'amount' => $amount,
  407. "act" => "refill",
  408. "op" => "add",
  409. 'order_sn' => $this->make_sn(),
  410. 'notifyurl' => "https://xxx"];
  411. $proxy = new refill_proxy("xxx");
  412. $resp = $proxy->send($url, $params);
  413. }
  414. public function testGoods()
  415. {
  416. $req_url = $this->mReqHost . '/mobile/index.php';
  417. $params = ['mchid' => $this->mMchid,
  418. "act" => "refill",
  419. "op" => "goods"];
  420. $resp = $this->send_md5($req_url, $params);
  421. }
  422. public function testQueryFactory()
  423. {
  424. refill\RefillFactory::instance()->query(295);
  425. }
  426. public function testQuery()
  427. {
  428. //$req_url = 'https://www.xyzshops.cn/mobile/index.php';
  429. // $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php';
  430. $req_url = BASE_SITE_URL . '/mobile/index.php';
  431. $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php';
  432. $params = ['mchid' => 1,
  433. "act" => "refill",
  434. "op" => "query",
  435. 'order_sn' => "13281476"];
  436. $resp = $this->send_md5($req_url, $params);
  437. }
  438. public function testRemoveSession()
  439. {
  440. $resp = http_request(BASE_SITE_URL . "/mobile/signature.php", [], 'POST');
  441. }
  442. public function testTianjtCB()
  443. {
  444. // $notifyurl = BASE_SITE_URL . "/mobile/refill_tianjt.php";
  445. $notifyurl = "https://www.xyzshops.cn/mobile/refill_tianjt.php";
  446. // $notifyurl = "https%3A%2F%2Fwww.xyzshops.cn%2Fmobile%2Frefill_tianjt.php";
  447. $params = ['onlystr' => '690665858589475818',
  448. 'amt' => 1000,
  449. 'jdno' => '',
  450. 'notifyurl' => $notifyurl,
  451. 'cardtype' => 'Sinoepc',
  452. 'batchid' => 30589,
  453. 'cardno' => '1000113300007993287',
  454. 'orgid' => '1590993600',
  455. 'status' => 3];
  456. $sign = $this->md5_sign($params);
  457. $params['sign'] = $sign;
  458. $resp = http_request($notifyurl, $params, 'POST');
  459. Log::record($resp, Log::DEBUG);
  460. }
  461. public function testBJBCB()
  462. {
  463. $params = [
  464. 'usr' => '13699279618',
  465. 'ord' => '710662733975412771',
  466. 'state' => '2',
  467. 'bz' => '',
  468. 'sgn' => 'AC9AFD254DE682D8440A97CA68B992DA'
  469. ];
  470. $resp = http_request("https://www.xyzshops.cn/mobile/refill_bjb.php", $params, 'POST');
  471. }
  472. public function testJiecCB()
  473. {
  474. $params['result'] = 'fail';
  475. $params['msg'] = '0';
  476. $params['order'] = 'null';
  477. $params['phone_no'] = '18500608333';
  478. $params['amount'] = '30.00';
  479. $params['op_no'] = '800663597981819221';
  480. $params['sign'] = '2510046895e8e12322c8a32547905ee9';
  481. $resp = http_request($this->mReqHost . "/mobile/refill_jiec.php", $params, 'POST');
  482. }
  483. public function testZFKJ()
  484. {
  485. //带签名参数:mchid=1090&act=refill&op=add&cardno=100112121212212133
  486. //&amount=10&order_sn=PH2012261356569433&
  487. //notifyurl=https%3A%2F%2Fqzcz.edusahoo.com.cn%2Findex%2Findex%2Fcallback
  488. //&sign=4a3ac5f9706e64aa70c6cab0fc5839d3
  489. $params = ['mchid' => 1090,
  490. 'cardno' => '100112121212212133',
  491. 'amount' => '10',
  492. "act" => "refill",
  493. "op" => "add",
  494. 'order_sn' => 'PH2012261356569433',
  495. 'notifyurl' => 'https://qzcz.edusahoo.com.cn/index/index/callback'];
  496. $resp = $this->send_md5(BASE_SITE_URL . '/mobile/index.php', $params);
  497. }
  498. protected function check_empty($value)
  499. {
  500. if (!isset($value))
  501. return true;
  502. if ($value === null)
  503. return true;
  504. if (trim($value) === "")
  505. return true;
  506. return false;
  507. }
  508. private function md5_sign($params)
  509. {
  510. ksort($params);
  511. $body = "";
  512. $i = 0;
  513. foreach ($params as $k => $v) {
  514. if (false === $this->check_empty($v) && "@" != substr($v, 0, 1)) {
  515. if ($i == 0) {
  516. $body .= "{$k}" . "=" . urldecode($v);
  517. } else {
  518. $body .= "&" . "{$k}" . "=" . urldecode($v);
  519. }
  520. $i++;
  521. }
  522. }
  523. $body .= "&key=7yDCLS6S2KzSAJQOUc3vsa";
  524. return md5($body);
  525. }
  526. public function testCallMech()
  527. {
  528. $logic = Logic('queue');
  529. $logic->NotifyMerchantComplete(['order_id' => 18171,'manual' => true]);
  530. }
  531. //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testCallMech)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test
  532. private function send($url, $params)
  533. {
  534. $mchid = $params['mchid'];
  535. $pri_key = BASE_DATA_PATH . "/api/merchant/key/{$mchid}_pri.pem";
  536. $key = file_get_contents($pri_key);
  537. $pri = openssl_get_privatekey($key);
  538. $body = $this->body($params);
  539. openssl_sign($body, $signed, $pri);
  540. $sign = base64_encode($signed);
  541. $params['sign'] = $sign;
  542. $resp = http_request($url, $params, 'POST');
  543. Log::record("resp:{$resp}", Log::DEBUG);
  544. }
  545. private function send_md5($url, $params)
  546. {
  547. $body = $this->body($params);
  548. $body .= "&key={$this->mKey}";
  549. $params['sign'] = md5($body);
  550. $resp = http_request($url, $params, 'POST');
  551. Log::record("resp:{$resp}", Log::DEBUG);
  552. return $resp;
  553. }
  554. public function testCardType()
  555. {
  556. $cardno = '1000111100021211884';
  557. $ret = preg_match('/^1[0-9]{18}$/', $cardno, $matches);
  558. }
  559. public function testMtrand()
  560. {
  561. }
  562. public function testHttpRefill()
  563. {
  564. $mchid = '000001';
  565. $pri_key = BASE_DATA_PATH . "/api/merchant/key/{$mchid}_pri.pem";
  566. $key = file_get_contents($pri_key);
  567. $pri = openssl_get_privatekey($key);
  568. $params = ['MCHID' => $mchid, 'cardno' => '1000111100021211884', 'amt' => "100", "act" => "refill", "op" => "addoil"];
  569. $body = $this->body($params);
  570. openssl_sign($body, $signed, $pri);
  571. $sign = base64_encode($signed);
  572. $params['sign'] = $sign;
  573. $resp = http_request(BASE_SITE_URL . "/mobile/index.php", $params, 'POST');
  574. }
  575. private function body($params)
  576. {
  577. ksort($params);
  578. $body = "";
  579. $i = 0;
  580. foreach ($params as $k => $v) {
  581. if (false === $this->checkEmpty($v) && "@" != substr($v, 0, 1)) {
  582. if ($i == 0) {
  583. $body .= "{$k}" . "=" . urlencode($v);
  584. } else {
  585. $body .= "&" . "{$k}" . "=" . urlencode($v);
  586. }
  587. $i++;
  588. }
  589. }
  590. return $body;
  591. }
  592. private function checkEmpty($value)
  593. {
  594. if (!isset($value))
  595. return true;
  596. if ($value === null)
  597. return true;
  598. if (trim($value) === "")
  599. return true;
  600. return false;
  601. }
  602. public function testKsort()
  603. {
  604. $age = ["Peter" => "35", "Ben" => "37", "Joe" => "43"];
  605. ksort($age);
  606. foreach ($age as $x => $x_value) {
  607. echo "Key=" . $x . ", Value=" . $x_value;
  608. echo "<br>";
  609. }
  610. }
  611. public function testip()
  612. {
  613. $model_merchant = Model('merchant');
  614. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => 1]);
  615. $ipwhitelist = unserialize($merchant_info['ip_white_list']);
  616. $res = json_encode($ipwhitelist);
  617. }
  618. //测试向内部店提交订单,可先屏蔽其它充值通道
  619. public function testAddoilToInnerStore()
  620. {
  621. $url = $this->mReqHost . "/mobile/index.php";
  622. $notifyurl = BASE_SITE_URL . '/mobile/signature.php';
  623. $params = ['mchid' => 1,
  624. 'cardno' => '1000111100020445281',
  625. 'amount' => "1000",
  626. "act" => "refill",
  627. "op" => "add",
  628. 'card_name' => '江海苗',
  629. 'order_sn' => $this->make_sn(),
  630. 'notifyurl' => $notifyurl];
  631. $resp = $this->send_md5($url, $params);
  632. Log::record($resp, Log::DEBUG);
  633. }
  634. public function testRefillInnerCB()
  635. {
  636. $params = ['state_type' => 'order_cancel', 'order_id' => 311, 'channel_name' => 'lx'];
  637. $resp = http_request(BASE_SITE_URL . '/mobile/refill_inner.php', $params, 'POST');
  638. }
  639. public function testArgs()
  640. {
  641. Log::record($_SERVER['argv'], Log::DEBUG);
  642. }
  643. public function testCall()
  644. {
  645. $order_id = 14974;
  646. QueueClient::async_push("NotifyMerchantComplete", ['order_id' => $order_id,'manual' => true], 10);
  647. }
  648. public function testSyncconfig()
  649. {
  650. $name_val_cfg = function ($items) {
  651. $result = [];
  652. foreach ($items as $item) {
  653. $name = $item->name();
  654. $result[$name] = $item;
  655. }
  656. return $result;
  657. };
  658. $name_val_row = function ($items) {
  659. $result = [];
  660. foreach ($items as $item) {
  661. $name = $item['name'];
  662. $result[$name] = $item;
  663. }
  664. return $result;
  665. };
  666. $match = function ($all,$cur)
  667. {
  668. $insert = [];
  669. foreach ($all as $key => $value)
  670. {
  671. if(!array_key_exists($key,$cur)) {
  672. $insert[] = $key;
  673. }
  674. }
  675. return $insert;
  676. };
  677. $inserter = function ($mod,$type,$names)
  678. {
  679. foreach ($names as $name) {
  680. $data = ['name' => $name,'type' => $type];
  681. $mod->insert($data);
  682. }
  683. };
  684. $providers = refill\RefillFactory::instance()->providers();
  685. $oils = $name_val_cfg($providers['oil']);
  686. $phones = $name_val_cfg($providers['phone']);
  687. $mod_prov = Model('refill_provider');
  688. $oil_items = $mod_prov->getProviderList(['type' => 1]);
  689. $oil_items = $name_val_row($oil_items);
  690. $oil_inserts = $match($oils,$oil_items);
  691. $phone_items = $mod_prov->getProviderList(['type' => 2]);
  692. $phone_items = $name_val_row($phone_items);
  693. $phone_inserts = $match($phones,$phone_items);
  694. $inserter($mod_prov,1,$oil_inserts);
  695. $inserter($mod_prov,2,$phone_inserts);
  696. }
  697. public function testStat()
  698. {
  699. $model_refill_order = Model('refill_order');
  700. $stat = Model('')->table('refill_order,vr_order')->join('inner')
  701. ->on('refill_order.order_id=vr_order.order_id')
  702. ->field('sum(refill_amount) as refill_amounts , sum(channel_amount) as channel_amounts , sum(mch_amount) as mch_amounts')
  703. ->where([])->select();
  704. }
  705. public function testRefillGoods()
  706. {
  707. $goods = refill\RefillFactory::instance()->goods();
  708. }
  709. private function make_mobile()
  710. {
  711. $no = "1" . mt_rand(3000000000, 3999999999);
  712. return $no;
  713. }
  714. private function refill_info($card_no, $card_type)
  715. {
  716. $data = rcache($card_no, 'cardrefill-');
  717. if(empty($data))
  718. {
  719. $mod_topcard = Model('topcard');
  720. $ret = $mod_topcard->get_card($card_no);
  721. if(empty($ret)) {
  722. $bind_phone = $this->make_mobile();
  723. $mod_topcard->add($card_no,$card_type,time(),$bind_phone);
  724. $data['bind_phone'] = $bind_phone;
  725. $data['refill_time'] = time();
  726. $data['times'] = 0;
  727. wcache($card_no,$data,'cardrefill-');
  728. }
  729. else {
  730. $val = $ret[0];
  731. $data['bind_phone'] = $val['bind_phone'];
  732. $data['refill_time'] = time();
  733. $data['times'] = 0;
  734. }
  735. }
  736. return $data;
  737. }
  738. public function testGetMobile()
  739. {
  740. $card_no = '1000119000001679247';
  741. $card_type = 1;
  742. $info = $this->refill_info($card_no,$card_type);
  743. }
  744. private function check_mchorder($mchid,$mch_order)
  745. {
  746. if(empty($mch_order)) {
  747. return true;
  748. }
  749. else {
  750. $refill_order = Model('refill_order');
  751. $ret = $refill_order->getOrderInfo(['mchid' => $mchid,'mch_order' => $mch_order]);
  752. return empty($ret);
  753. }
  754. }
  755. public function testCheckMchorder()
  756. {
  757. $ret = $this->check_mchorder(1,'13281475');
  758. }
  759. public function testMakemobile()
  760. {
  761. $mobile = refill\util::make_mobile();
  762. $ret = refill\util::set_black('1000111100020445281');
  763. }
  764. public function testLoadBlack()
  765. {
  766. $path = BASE_DATA_PATH . "/log";
  767. $names = ['20210119-mobile.log',
  768. '20210120-mobile.log','20210121-mobile.log','20210122-mobile.log','20210123-mobile.log',
  769. '20210124-mobile.log','20210125-mobile.log'];
  770. foreach ($names as $name)
  771. {
  772. $file_name = $path . "/" . $name;
  773. refill\util::black_from_log($file_name);
  774. }
  775. }
  776. public function testStats()
  777. {
  778. $date = date('Y-m-d',time());
  779. $today = strtotime("{$date}");
  780. $times_begin = function ($start) {
  781. $times = [];
  782. $begin = $start;
  783. for($i = 0; $i < 7; $i++) {
  784. $times[] = $begin;
  785. $begin -= 86400;
  786. }
  787. return $times;
  788. };
  789. $reader = function ($mchid,$time) {
  790. $cond['mchid'] = $mchid;
  791. $cond['inner_status'] = 0;
  792. $cond['refill_order.order_time'] = ['between', [$time, $time + 86400 -1]];
  793. $items = Model('')->table('refill_order,vr_order')->join('inner')
  794. ->on('refill_order.order_id=vr_order.order_id')
  795. ->field('count(*) as order_count, vr_order.order_state, sum(mch_amount) as mch_amounts')
  796. ->group('vr_order.order_state')
  797. ->where($cond)->select();
  798. return $items;
  799. };
  800. $begins = $times_begin($today);
  801. $mchid = 10096;
  802. // $states = rcache($this->mchid() , 'refillstat-');
  803. $states = unserialize($states ?? "");
  804. if(empty($states)) $states = [];
  805. $result = [];
  806. $cache = [];
  807. foreach ($begins as $begin)
  808. {
  809. if(array_key_exists($begin,$states)) {
  810. $item = $states[$begin];
  811. }
  812. else {
  813. $item = $reader($mchid,$begin);
  814. }
  815. $result[$begin] = $item;
  816. //判断item 中充值中的状态是否为0,为0的情况下放进cache
  817. $cache = $item;
  818. }
  819. wcache($this->mchid() ,$cache, 'refillstat-');
  820. return $result;
  821. }
  822. public function testNotifyx()
  823. {
  824. $mch_cache = rcache("merchant-notify" , 'refill-');
  825. $caches = empty($mch_cache['data']) ? [] : unserialize($mch_cache['data']);
  826. $new_caches = [];
  827. $merchants = Model('merchant')->getMerchantList([],'','','merchant.*,member.available_predeposit' ,"0,1000");
  828. foreach ($merchants as $merchant)
  829. {
  830. $mchid = $merchant['mchid'];
  831. $phone = $merchant['contact_phone'] ?? "";
  832. $available_pd = intval($merchant['available_predeposit']);
  833. $alarm_pd = intval($merchant['alarm_amount']) < 10000 ? 10000 : intval($merchant['alarm_amount']);
  834. if(array_key_exists($mchid,$caches)) {
  835. $mch_cache = $caches[$mchid];
  836. }
  837. else {
  838. $mch_cache = ['last_time' => 0, 'send_count' => 0];
  839. }
  840. if(!empty($phone) && ($available_pd < $alarm_pd))
  841. {
  842. $counts = $mch_cache['send_count'];
  843. if(($mch_cache['last_time'] + 300 < time()) && $counts < 5) {
  844. $mch_cache = ['last_time' => time(), 'send_count' => $counts + 1];
  845. QueueClient::push('sendSMS', ['mobile'=>$merchant['contact_phone'],
  846. 'type'=>'balance_warning','datas' => [date("m月d日H时") , $merchant['available_predeposit']]]);
  847. }
  848. }
  849. else {
  850. $mch_cache = ['last_time' => 0, 'send_count' => 0];
  851. }
  852. $new_caches[$mchid] = $mch_cache;
  853. }
  854. wcache("merchant-notify", ['data' => serialize($new_caches)], 'refill-');
  855. }
  856. public function testReadChannel()
  857. {
  858. refill\RefillFactory::instance()->read_channel();
  859. }
  860. public function testAllow()
  861. {
  862. $allow = refill\RefillFactory::instance()->allow(10096,1,100);
  863. }
  864. public function testCheckData(){
  865. $str = '|2|110667993758599771-充值失败|';
  866. // $str = '0|提交成功|-36557.7400';
  867. // if(preg_match( '/^-*[0-9]{1,3}\|[\x{4e00}-\x{9fa5}]+\|-*[0-9]+\.*[0-9]+$/u',$str,$matches)) {
  868. // return true;
  869. // }
  870. // if(preg_match('/^[0-3]\|[0-9]+-*[\x{4e00}-\x{9fa5}]+\|[0-9]*$/u',$str,$matches)){
  871. // return true;
  872. // }
  873. // return false;
  874. $resp = ltrim($str , '|');
  875. $resp = explode('|' , $resp);
  876. if(count($resp) != 3) {
  877. return [false,'返回值错误'];
  878. }
  879. }
  880. public function testErrre()
  881. {
  882. $line = '[13 2021-01-24 16:07:03] DEBUG: type = application/json;charset=utf-8, content={"channelOrderNumber":"610664819621371793","orderNumber":"GYFL1611475621525437","message":"充值失败","signature":"6c28c15b9ce2b2243742ecebbd929ac5","status":109}';
  883. $ret = preg_match('/[\w\W]+"channelOrderNumber":"(?P<order_sn>[^"]+)"[\w\W]+"message":"(?P<message>[\x{4e00}-\x{9fa5}]+)"[\w\W]+"status":109/u',$line,$matches);
  884. }
  885. public function testLog()
  886. {
  887. // $line = './LOG/20210203-mobile.log:[15 2021-02-03 10:41:17] SQL: UPDATE `lrlz_member` SET available_predeposit=available_predeposit+975 WHERE ( member_id = \'65818\' ) [ RunTime:0.000297s ]';
  888. $fn = fopen(BASE_ROOT_PATH . "/10096.log","r");
  889. $mod = Model();
  890. $mod->table('tfloat')->where(['member_id' => 65818])->update( ['pdamount'=>0]);
  891. $total_amount = ncPriceFormat(0.00);
  892. $i = 0;
  893. while(! feof($fn)) {
  894. $i++;
  895. $line = trim(fgets($fn));
  896. $ret = preg_match('/[\w\W]+UPDATE[\w\W]+available_predeposit=available_predeposit(?P<oper>[-+]+)(?P<amount>[.\d]+)/i',$line,$matches);
  897. if($ret) {
  898. $oper = $matches['oper'];
  899. $amount = $matches['amount'];
  900. if($oper == '-') {
  901. $total_amount = ncPriceFormat($total_amount) - ncPriceFormat($amount);
  902. // $mod->table('tfloat')->where(['member_id' => 65818])->update( ['pdamount'=>['exp','pdamount-'.$amount]]);
  903. }
  904. else {
  905. $total_amount = ncPriceFormat($total_amount) + ncPriceFormat($amount);
  906. // $mod->table('tfloat')->where(['member_id' => 65818])->update( ['pdamount'=>['exp','pdamount+'.$amount]]);
  907. }
  908. Log::record("index = {$i} {$total_amount} = {$total_amount} {$oper} {$amount}",Log::DEBUG);
  909. }
  910. }
  911. Log::record("total_amount:{$total_amount}",Log::DEBUG);
  912. fclose($fn);
  913. }
  914. }
  915. //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testLoadBlack)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test
  916. //docker-compose -f ./docker-compose-dev.yml run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testCall)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test