TestRefill.php 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291
  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->mReqHost = 'http://121.89.196.45';
  30. $this->mMchid = 1092;
  31. $this->mKey = '210fe406954220f56085997d6a4c5b80';
  32. }
  33. }
  34. public static function setUpBeforeClass(): void
  35. {
  36. Base::run_util();
  37. refill\RefillFactory::instance();
  38. }
  39. public function testCallBack()
  40. {
  41. }
  42. public function testFactory()
  43. {
  44. $providers = refill\RefillFactory::instance();
  45. }
  46. private function make_sn()
  47. {
  48. return mt_rand(1000, 9999)
  49. . sprintf('%010d', time())
  50. . sprintf('%06d', (float)microtime() * 1000000);
  51. }
  52. public function testRandomMobile()
  53. {
  54. $no = "1" . mt_rand(1, 9999999999);
  55. Log::record("phone no={$no}", Log::DEBUG);
  56. }
  57. public function testBJBAddPhone()
  58. {
  59. $providers = new refill\bjb\RefillPhone([]);
  60. for ($i = 3; $i > 0; --$i) {
  61. $resp = $providers->add(13911129867, 4, 10, ['order_sn' => $this->make_sn()]);
  62. $resp = $providers->add(18500608333, 4, 10, ['order_sn' => $this->make_sn()]);
  63. $resp = $providers->add(18510683168, 4, 10, ['order_sn' => $this->make_sn()]);
  64. $resp = $providers->add(18513846008, 4, 10, ['order_sn' => $this->make_sn()]);
  65. $resp = $providers->add(18518237398, 4, 10, ['order_sn' => $this->make_sn()]);
  66. }
  67. }
  68. public function testOilticket()
  69. {
  70. $providers = new refill\bjb\RefillPhone([]);
  71. }
  72. public function testBjbRet()
  73. {
  74. $resp = '0|提交成功|14936.8600';
  75. $resp = explode('|', $resp);
  76. }
  77. public function testIpWhiteList()
  78. {
  79. $x = serialize(['47.99.57.105']);
  80. $ips = unserialize('a:1:{i:0;s:12:"47.99.57.105";}');
  81. if (!empty($ips)) {
  82. $addr = '47.99.57.105';
  83. Log::record("request ip:{$addr}", Log::DEBUG);
  84. if (!in_array($addr, $ips)) {
  85. throw new Exception("请求地址不在白名单中");
  86. }
  87. }
  88. }
  89. public function testBaizePhone()
  90. {
  91. $providers = new refill\baizeyd\RefillPhone([]);
  92. // $resp = $providers->add(17801048874, 5, 10, ['order_sn' => $this->make_sn()]);
  93. $resp = $providers->query(['order_sn' => '930668700375312006']);
  94. // $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';
  95. // $input = $this->parse_request($str);
  96. // $input['amount'] = 10.00;
  97. // $input['orderId'] = '92391614943913061206';
  98. // $input['phone'] = 17801048874;
  99. // $input['payTime'] = '2021-03-05 19:31:55';
  100. // $input['sign'] = 'bef6ae50319fb1e8cb3f21302f0abef8';
  101. // $input['appKey'] = 'uECmTOFAY6RPCTtI';
  102. // $input['payUrl'] = '';
  103. // $input['statusDes'] = '支付失败';
  104. // $input['status'] = 7;
  105. // refill\RefillFactory::instance()->notify('baizeyd',$input);
  106. }
  107. private function parse_request($squery)
  108. {
  109. if (empty($squery)) return [];
  110. $result = [];
  111. $params = preg_split('/&/', $squery);
  112. foreach ($params as $pair) {
  113. if (empty($pair)) continue;
  114. $kv = explode('=', $pair);
  115. $count = count($kv);
  116. if ($count === 1) {
  117. $key = $kv[0];
  118. $val = "";
  119. } elseif ($count === 2) {
  120. $key = $kv[0];
  121. $val = urldecode($kv[1]);
  122. } else {
  123. continue;
  124. }
  125. if (!empty($key)) {
  126. $result[$key] = $val;
  127. }
  128. }
  129. return $result;
  130. }
  131. public function testAmPhone()
  132. {
  133. // $providers = new refill\aming\RefillPhone([]);
  134. // $resp = $providers->add(18500608333, 5, 10, ['order_sn' => $this->make_sn()]);
  135. $input['result'] = 'fail';
  136. $input['msg'] = 0;
  137. $input['order'] = 'null';
  138. $input['phone_no'] = 18500608333;
  139. $input['sign'] = 'c925ad19c63c3eb36ffc52d938e24604';
  140. $input['amount'] = '10.00';
  141. $input['op_no'] = '42601615096072517841';
  142. refill\RefillFactory::instance()->notify('aming', $input);
  143. }
  144. public function testBhcPhone()
  145. {
  146. $providers = new refill\binghc\RefillPhone([]);
  147. $resp = $providers->query(['order_sn' => 250668618955902006]);
  148. // $input['result'] = 'fail';
  149. // $input['msg'] = 0;
  150. // $input['order'] = 'null';
  151. // $input['phone_no'] = 18500608333;
  152. // $input['sign'] = 'c3aa38ee07cd1b69bfd5ead56f6da8d6';
  153. // $input['amount'] = '10.00';
  154. // $input['op_no'] = '24061615096361999002';
  155. // refill\RefillFactory::instance()->notify('binghc',$input);
  156. }
  157. public function testRuishunPhone()
  158. {
  159. // $providers = new refill\ruishun\RefillPhone([]);
  160. // $resp = $providers->add(18500608333, 5, 10, ['order_sn' => $this->make_sn()]);
  161. $input['result'] = 'fail';
  162. $input['msg'] = 0;
  163. $input['order'] = null;
  164. $input['phone_no'] = 18500608333;
  165. $input['sign'] = 'e234f7d1c0458ca236f53a0008436b46';
  166. $input['amount'] = "10.00";
  167. $input['op_no'] = '76361615095403188513';
  168. refill\RefillFactory::instance()->notify('ruishun', $input);
  169. }
  170. public function testWuchenPhone()
  171. {
  172. $providers = new refill\wuchen\RefillPhone([]);
  173. // $resp = $providers->add('13699279618', 5, 30, ['order_sn' => $this->make_sn()]);
  174. $resp = $providers->query(['order_sn' => '790668630498425006']);
  175. // $input['app_id'] = '70016';
  176. // $input['message'] = 'fail';
  177. // $input['order_sn'] = '43101615277293035501';
  178. // $input['platform_order_id'] = '';
  179. // $input['sign'] = '5ea59f8ac51a518f2c622824d7db2a04';
  180. // $input['state'] = "fail";
  181. // $input['sys_sn'] = '202103091608231836913889';
  182. // $input['timestamp'] = '1615277361';
  183. // refill\RefillFactory::instance()->notify('wuchen',$input);
  184. }
  185. public function testYibaoPhone()
  186. {
  187. $providers = new refill\yibao\RefillPhone([]);
  188. // $resp = $providers->add('13699279618', 5, 30, ['order_sn' => $this->make_sn()]);
  189. $resp = $providers->query(['ch_trade_no' => '31215002972142736']);
  190. // $str = '{"amount":"30","carrierOrderNo":null,"mobile":"13699279618","orderNo":"27961615532426088043","orderStatus":3,"sign":"012BA0B093A0473D7DD1634A8356DCB1","tradeNo":"31215002972142736"}';
  191. // $data = json_decode($str,true);
  192. // refill\RefillFactory::instance()->notify('yibao',$data);
  193. }
  194. public function testAmingydPhone()
  195. {
  196. $providers = new refill\amingyd\RefillPhone([]);
  197. // $resp = $providers->add('13699279618', 5, 30, ['order_sn' => $this->make_sn()]);
  198. $resp = $providers->query(['order_sn' => '15421615627436792938']);
  199. // $str = '{"orderId":"15421615627436792938","amount":3000,"appKey":"40695059","timestamp":1615627503,"status":3,"operatorId":"508353854027968617","sign":"2A0562319ED4845AB9E3812A58F0B425"}';
  200. // $data = json_decode($str,true);
  201. // refill\RefillFactory::instance()->notify('amingyd',$data);
  202. }
  203. public function testChukaPhone()
  204. {
  205. $providers = new refill\chuka\RefillPhone([]);
  206. // $resp = $providers->add('18500608333', 5, 20, ['order_sn' => $this->make_sn()]);
  207. // $resp = $providers->query(['order_sn' => '92161616314884175179']);
  208. $params['customerId'] = '101787';
  209. $params['orderno'] = 'C1616314888506705492';
  210. $params['tmporder'] = '92161616314884175179';
  211. $params['code'] = '1';
  212. $params['number'] = '18500608333';
  213. $params['money'] = '20';
  214. $params['amount'] = '0';
  215. refill\RefillFactory::instance()->notify('chuka', $params);
  216. }
  217. public function testLegouPhone()
  218. {
  219. $providers = new refill\legou\RefillPhone([]);
  220. // $resp = $providers->add('18500608333', 5, 30, ['order_sn' => '200649600557718881' , 'order_id' => 247 , 'buyer_id' => 52667]);
  221. $resp = $providers->query(['order_sn' => '200649600557718881', 'order_id' => 247]);
  222. $params['username'] = 'lzdc';
  223. $params['orderNumber'] = '690653407667699667';
  224. $params['cardNumber'] = '18500608333';
  225. $params['orderMoney'] = '30.0';
  226. $params['orderPay'] = '1.0';
  227. $params['resultCode'] = '2';
  228. $params['rechargeDesc'] = '{"rechargeStatus":600200,"rechargeDesc":"充值成功"}';
  229. $params['rechargeVoucher'] = '100407307092103291444050244599';
  230. $params['sign'] = 'c054884422a8c3749cbfda0e82b9af70';
  231. // refill\RefillFactory::instance()->notify('legou',$params);
  232. }
  233. public function testFeiniaoPhone()
  234. {
  235. $providers = new refill\feiniao\RefillPhone([]);
  236. // $order_sn = $this->make_sn();
  237. // Log::record($order_sn, Log::DEBUG);
  238. // $resp = $providers->add('18500608333', 5, 100, ['order_sn' => $order_sn]);
  239. $resp = $providers->query(['order_sn' => '15441617095424773754']);
  240. $params['result'] = 'fail';
  241. $params['msg'] = '0';
  242. $params['order'] = 'null';
  243. $params['phone_no'] = '18500608333';
  244. $params['amount'] = '100.00';
  245. $params['op_no'] = '64591617090761169983';
  246. $params['settle'] = '0';
  247. $params['sign'] = '907d2640f96e8d78d59202d090ddb470';
  248. // refill\RefillFactory::instance()->notify('feiniao',$params);
  249. }
  250. public function testTongyPhone()
  251. {
  252. $providers = new refill\tongy\RefillPhone([]);
  253. $resp = $providers->add('18500608333', 5, 30, ['order_sn' => '690653407667699667', 'order_id' => 248, 'buyer_id' => 52667]);
  254. }
  255. public function testWeiyiPhone()
  256. {
  257. $providers = new refill\weiyi\RefillPhone([]);
  258. // $resp = $providers->add(18500608333, 5, 100, ['order_sn' => $this->make_sn()]);
  259. // $resp = $providers->query(['order_sn' => '59031616396534854303']);
  260. // $body = '{"userid":"8177b4b1d0254c0699bc","ordernum":"59031616396534854303","mobile":"18500608333","timestamp":"20210322150437","state":"3","desc":"%E5%A4%B1%E8%B4%A5%3A%E5%A4%B1%E8%B4%A5","sign":"1d412f956c041bf4454357b209c93df6"}';
  261. // $params = json_decode($body , true);
  262. // refill\RefillFactory::instance()->notify('weiyi',$params);
  263. }
  264. public function testTongluPhone()
  265. {
  266. $providers = new refill\tonglu\RefillPhone([]);
  267. // $resp = $providers->add(18500608333, 5, 50, ['order_sn' => $this->make_sn()]);
  268. $resp = $providers->query(['order_sn' => '22961616468561936356']);
  269. // $body = '{"order_no":"22961616468561936356","order_status":"5","phone_no":"18500608333","amount":5000,"time_paid":1616468856287,"order_cert_no":"","paid":false,"order_id":"20210323966497008"}';
  270. // $sign = '9E41F52F612D60EBB654B3A5D1E2F1E5';
  271. // $params = json_decode($body , true);
  272. // $params['sign'] = $sign;
  273. // refill\RefillFactory::instance()->notify('tonglu',$params);
  274. }
  275. public function testAmingjd()
  276. {
  277. // $providers = new refill\amingjd\RefillPhone([]);
  278. // $resp = $providers->add(13699279618, 5, 30, ['order_sn' => $this->make_sn()]);
  279. // $resp = $providers->query(['order_sn' => '42301616475989518588']);
  280. $body = '{"order_id":"83321616478215494884","mchid":"10003","tel":"13699279618","price":"30.00","sign":"01c49620c155a80bc43cecc2b1651868","status":"0","out_order_id":"0"}';
  281. $params = json_decode($body, true);
  282. refill\RefillFactory::instance()->notify('amingjd', $params);
  283. }
  284. public function testPrice()
  285. {
  286. $amounts = [10, 20, 30, 50, 100, 200, 300, 500];
  287. $rate = 0.97;
  288. foreach ($amounts as $amount) {
  289. $price[] = $amount * $rate;
  290. }
  291. }
  292. public function testWeisPhone()
  293. {
  294. $providers = new refill\weisyd\RefillPhone([]);
  295. $resp = $providers->add(17801048874, 4, 10, ['order_sn' => $this->make_sn()]);
  296. }
  297. public function testXcPhone()
  298. {
  299. $providers = new refill\xc\RefillPhone([]);
  300. $resp = $providers->add(13699279618, 5, 100, ['order_sn' => $this->make_sn()]);
  301. // $resp = $providers->query(['order_sn' => '87961616926444043617']);
  302. $params['pay_orderid'] = '87961616926444043617';
  303. $params['pay_iphone'] = '18500608333';
  304. $params['pay_money'] = '100';
  305. $params['wt_orderid'] = '202103281816121070';
  306. $params['status'] = '1';
  307. $params['sign'] = 'f7be2e859a5a6dc7b1a8273361617752';
  308. // refill\RefillFactory::instance()->notify('xc',$params);
  309. }
  310. public function testAfandPhone()
  311. {
  312. $providers = new refill\afand\RefillPhone([]);
  313. // for ($i = 3; $i > 0; --$i) {
  314. $resp = $providers->query(['order_sn' => '540668612768904780']);
  315. // }
  316. }
  317. public function testAfandengPhone()
  318. {
  319. $providers = new refill\afandeng\RefillPhone([]);
  320. // for ($i = 5; $i > 0; --$i) {
  321. $resp = $providers->add(13699279618, 4, 50, ['order_sn' => $this->make_sn()]);
  322. // }
  323. // $resp = $providers->query(['order_sn' => '20941616115610023539']);
  324. // $params['usr'] = 'afandeng';
  325. // $params['ord'] = '20941616115610023539';
  326. // $params['state'] = '2';
  327. // $params['bz'] = '';
  328. // $params['sgn'] = 'BA2C9D379C3EB648A0B7AAB3A21A3F6A';
  329. // refill\RefillFactory::instance()->notify('afandeng',$params);
  330. }
  331. public function testLingzhPhone()
  332. {
  333. $providers = new refill\lingzh\RefillPhone([]);
  334. // $resp = $providers->add(18500608333, 5, 10, ['order_sn' => $this->make_sn()]);
  335. // $resp = $providers->query(['order_sn' => '59911615124025101286']);
  336. $resp = $providers->balance();
  337. // $input['usr'] = 1;
  338. // $input['ord'] = '52741615119546453690';
  339. // $input['bz'] = '';
  340. // $input['state'] = 2;
  341. // $input['sgn'] = 'FFCBB75C307154DD306F4EC75BB69A6D';
  342. // refill\RefillFactory::instance()->notify('lingzh',$input);
  343. }
  344. public function testAfandnewPhone()
  345. {
  346. $providers = new refill\afandnew\RefillPhone([]);
  347. // $resp = $providers->add(18500608333, 5, 100, ['order_sn' => $this->make_sn()]);
  348. // $resp = $providers->query(['order_sn' => '45371617101073876975', 'ch_trade_no' => '33018443659736309']);
  349. $params = '{"amount":"100","carrierOrderNo":null,"mobile":"18500608333","orderNo":"45371617101073876975","orderStatus":3,"sign":"8DE392AD6B4730AD9EE0FC2B95BBDF17","tradeNo":"33018443659736309"}';
  350. $input = json_decode($params, true);
  351. refill\RefillFactory::instance()->notify('afandnew', $input);
  352. }
  353. public function testYifaPhone()
  354. {
  355. $providers = new refill\yifa\RefillPhone([]);
  356. $resp = $providers->add(15120035568, 5, 50, ['order_sn' => $this->make_sn()]);
  357. }
  358. public function testTianjtOil()
  359. {
  360. $cardno = 1000111100021211884;
  361. $providers = new refill\tianjt\RefillOil([]);
  362. $resp = $providers->add($cardno, 2, 500, ['order_sn' => $this->make_sn()]);
  363. }
  364. public function testWeitPhone()
  365. {
  366. $providers = new refill\weit\RefillPhone([]);
  367. for ($i = 0; $i <= 10; $i++) {
  368. $resp = $providers->add(18500608333, 5, 10, ['order_sn' => $this->make_sn()]);
  369. }
  370. }
  371. public function testWeitCB()
  372. {
  373. $params['sign'] = 'af820c33472f4b571fa0c48483dfb975';
  374. $params['status'] = 0;
  375. $params['price'] = 30;
  376. $params['op_order_id'] = '';
  377. $params['mch_order_id'] = '900664281823957221';
  378. $params['pt_order_id'] = '2021011802434412825405218901';
  379. $params['pay_type'] = '';
  380. $params['tel'] = 18500608333;
  381. $params['mchid'] = 10014;
  382. $resp = http_request($this->mReqHost . "/mobile/refill_weit.php", $params, 'POST');
  383. }
  384. public function testYifaCB()
  385. {
  386. $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"}';
  387. $input = json_decode($body, true);
  388. refill\RefillFactory::instance()->notify('yifa', $input);
  389. }
  390. public function testBjbQuery()
  391. {
  392. $providers = new refill\bjb\RefillPhone([]);
  393. $refill_info = ['order_sn' => 110667993758599771, 'ch_trade_no' => 499, 'card_no' => 1000111200005252927];
  394. $resp = $providers->query($refill_info);
  395. }
  396. public function testXcQuery()
  397. {
  398. $providers = new refill\xc\RefillPhone([]);
  399. $refill_info = ['order_sn' => 950663423236726632, 'ch_trade_no' => 499, 'card_no' => 1000111200005252927];
  400. $resp = $providers->query($refill_info);
  401. }
  402. public function testTianjtQuery()
  403. {
  404. $providers = new refill\tianjt\RefillOil([]);
  405. $refill_info = ['order_sn' => 680665862267622221, 'ch_trade_no' => 499, 'card_no' => 1000111200005252927];
  406. $resp = $providers->query($refill_info);
  407. }
  408. public function testSaihuOil()
  409. {
  410. $providers = new refill\saihu\RefillOil([]);
  411. $resp = $providers->add(1000111100021211884, 2, 100, ['order_sn' => $this->make_sn()]);
  412. }
  413. public function testBdtOil()
  414. {
  415. $providers = new refill\bdt\RefillOil([]);
  416. $resp = $providers->add(1000111100021211884, 2, 100, ['order_sn' => '200229600556618886']);
  417. }
  418. public function testGFTDOil()
  419. {
  420. $providers = new refill\gftd\RefillOil([]);
  421. $resp = $providers->add(1000111100020445281, mtopcard\SinopecCard, 100, ['order_sn' => $this->make_sn()]);
  422. }
  423. public function testGFTDCB()
  424. {
  425. $data = '{"channelOrderNumber":"79091610959059372019","orderNumber":"GYFL1610959060397001","message":"充值成功","signature":"881036222bd8f067ff47d248c75f4c8d","voucher":"","status":101}';
  426. $url = "http://192.168.1.220/mobile/refill_gftd.php?" . $data;
  427. $resp = http_post_data($url, $data, ['Content-Type: application/json;charset=UTF-8;', 'Accept:application/json;charset=UTF-8;']);
  428. }
  429. public function testJiecPhone()
  430. {
  431. $providers = new refill\jiec\RefillPhone([]);
  432. $resp = $providers->add('18500608333', 5, 30, ['order_sn' => $this->make_sn()]);
  433. }
  434. public function testBxtwtCB()
  435. {
  436. $data = '{"order_number":18219726,"shipping_status":4,"shipping_status_desc":"发货失败","shipping_status_message":"","sign":"863b4d972f2a4d39a9af7396879116c4","voucher":"","vouchertype":"","voucherurl":"","tradeNo":"100662475851197741"}';
  437. }
  438. public function testTianjtJDVerify()
  439. {
  440. $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';
  441. $url = "http://192.168.1.220/mobile/refill_tianjt.php?" . $data;
  442. $resp = http_request($url);
  443. }
  444. public function testSuhcPDD()
  445. {
  446. $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';
  447. $url = "https://www.xyzshops.cn/mobile/refill_suhcpdd.php?" . $data;
  448. $resp = http_request($url);
  449. }
  450. public function testSuhcTMVerify()
  451. {
  452. $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';
  453. $url = "https://www.xyzshops.cn/mobile/refill_suhctm.php?" . $data;
  454. $resp = http_request($url);
  455. }
  456. public function testBeixtVerify()
  457. {
  458. $data = '{"order_number":18219726,"shipping_status":4,"shipping_status_desc":"发货失败","shipping_status_message":"","sign":"863b4d972f2a4d39a9af7396879116c4","voucher":"","vouchertype":"","voucherurl":"","tradeNo":"100662475851197741"}';
  459. $url = "https://www.xyzshops.cn/mobile/refill_bxtwt.php";
  460. $headers = ['Content-Type: application/json'];
  461. $resp = http_post_data($url, $data, $headers);
  462. }
  463. public function testInput()
  464. {
  465. $input = fopen("php://input", "rw");
  466. file_put_contents($input, 'xxxx');
  467. $content = file_get_contents('php://input');
  468. }
  469. public function testUrl()
  470. {
  471. $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';
  472. $params = preg_split('/&/', $data);
  473. foreach ($params as $pair) {
  474. $kv = explode('=', $pair);
  475. $count = count($kv);
  476. if ($count === 1) {
  477. $key = $kv[0];
  478. $val = "";
  479. } elseif ($count === 2) {
  480. $key = $kv[0];
  481. $val = $kv[1];
  482. } else {
  483. continue;
  484. }
  485. Log::record("{$key}:{$val}", Log::DEBUG);
  486. }
  487. }
  488. public function testAddoil()
  489. {
  490. $url = $this->mReqHost . "/mobile/index.php";
  491. $notifyurl = 'http://121.89.196.45/mobile/signature.php';
  492. $params = ['mchid' => $this->mMchid,
  493. 'cardno' => '1000111100020445281',
  494. 'amount' => "100",
  495. "act" => "refill",
  496. "op" => "add",
  497. 'order_sn' => $this->make_sn(),
  498. 'notifyurl' => $notifyurl];
  499. $resp = $this->send_md5($url, $params);
  500. Log::record($resp, Log::DEBUG);
  501. }
  502. public function testBalance()
  503. {
  504. $url = $this->mReqHost . "/mobile/index.php";
  505. $params = ['mchid' => 1092,
  506. "act" => "refill",
  507. "op" => "balance"];
  508. $resp = $this->send_md5($url, $params);
  509. Log::record($resp, Log::DEBUG);
  510. }
  511. public function testAddPhoe()
  512. {
  513. $phones = [//13911129867,
  514. 18500608333,
  515. 18510683168,
  516. 18513846008,
  517. 18518237398];
  518. $amount = 10;
  519. for ($i = 0; $i < 3; $i++) {
  520. foreach ($phones as $phone) {
  521. $url = $this->mReqHost . "/mobile/index.php";
  522. $params = ['mchid' => 1092,
  523. 'cardno' => $phone,
  524. 'amount' => $amount,
  525. "act" => "refill",
  526. "op" => "add",
  527. 'order_sn' => $this->make_sn(),
  528. 'notifyurl' => $this->mReqHost . "/mobile/refill_xyz.php"];
  529. $resp = $this->send_md5($url, $params);
  530. Log::record($resp, Log::DEBUG);
  531. }
  532. }
  533. }
  534. public function testProxyHelper()
  535. {
  536. $phone = '13911129867';
  537. $amount = 100;
  538. $url = $this->mReqHost . "/mobile/index.php";
  539. $params = ['mchid' => 1090,
  540. 'cardno' => $phone,
  541. 'amount' => $amount,
  542. "act" => "refill",
  543. "op" => "add",
  544. 'order_sn' => $this->make_sn(),
  545. 'notifyurl' => "https://xxx"];
  546. $proxy = new refill_proxy("xxx");
  547. $resp = $proxy->send($url, $params);
  548. }
  549. public function testGoods()
  550. {
  551. $req_url = $this->mReqHost . '/mobile/index.php';
  552. $params = ['mchid' => $this->mMchid,
  553. "act" => "refill",
  554. "op" => "goods"];
  555. $resp = $this->send_md5($req_url, $params);
  556. }
  557. public function testQueryFactory()
  558. {
  559. refill\RefillFactory::instance()->query(295);
  560. }
  561. public function testQuery()
  562. {
  563. //$req_url = 'https://www.xyzshops.cn/mobile/index.php';
  564. // $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php';
  565. $req_url = BASE_SITE_URL . '/mobile/index.php';
  566. $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php';
  567. $params = ['mchid' => 1,
  568. "act" => "refill",
  569. "op" => "query",
  570. 'order_sn' => "13281476"];
  571. $resp = $this->send_md5($req_url, $params);
  572. }
  573. public function testRemoveSession()
  574. {
  575. $resp = http_request(BASE_SITE_URL . "/mobile/signature.php", [], 'POST');
  576. }
  577. public function testTianjtCB()
  578. {
  579. // $notifyurl = BASE_SITE_URL . "/mobile/refill_tianjt.php";
  580. $notifyurl = "https://www.xyzshops.cn/mobile/refill_tianjt.php";
  581. // $notifyurl = "https%3A%2F%2Fwww.xyzshops.cn%2Fmobile%2Frefill_tianjt.php";
  582. $params = ['onlystr' => '690665858589475818',
  583. 'amt' => 1000,
  584. 'jdno' => '',
  585. 'notifyurl' => $notifyurl,
  586. 'cardtype' => 'Sinoepc',
  587. 'batchid' => 30589,
  588. 'cardno' => '1000113300007993287',
  589. 'orgid' => '1590993600',
  590. 'status' => 3];
  591. $sign = $this->md5_sign($params);
  592. $params['sign'] = $sign;
  593. $resp = http_request($notifyurl, $params, 'POST');
  594. Log::record($resp, Log::DEBUG);
  595. }
  596. public function testBJBCB()
  597. {
  598. $params = [
  599. 'usr' => '13699279618',
  600. 'ord' => '710662733975412771',
  601. 'state' => '2',
  602. 'bz' => '',
  603. 'sgn' => 'AC9AFD254DE682D8440A97CA68B992DA'
  604. ];
  605. $resp = http_request("https://www.xyzshops.cn/mobile/refill_bjb.php", $params, 'POST');
  606. }
  607. public function testJiecCB()
  608. {
  609. $params['result'] = 'fail';
  610. $params['msg'] = '0';
  611. $params['order'] = 'null';
  612. $params['phone_no'] = '18500608333';
  613. $params['amount'] = '30.00';
  614. $params['op_no'] = '800663597981819221';
  615. $params['sign'] = '2510046895e8e12322c8a32547905ee9';
  616. $resp = http_request($this->mReqHost . "/mobile/refill_jiec.php", $params, 'POST');
  617. }
  618. public function testZFKJ()
  619. {
  620. //带签名参数:mchid=1090&act=refill&op=add&cardno=100112121212212133
  621. //&amount=10&order_sn=PH2012261356569433&
  622. //notifyurl=https%3A%2F%2Fqzcz.edusahoo.com.cn%2Findex%2Findex%2Fcallback
  623. //&sign=4a3ac5f9706e64aa70c6cab0fc5839d3
  624. $params = ['mchid' => 1090,
  625. 'cardno' => '100112121212212133',
  626. 'amount' => '10',
  627. "act" => "refill",
  628. "op" => "add",
  629. 'order_sn' => 'PH2012261356569433',
  630. 'notifyurl' => 'https://qzcz.edusahoo.com.cn/index/index/callback'];
  631. $resp = $this->send_md5(BASE_SITE_URL . '/mobile/index.php', $params);
  632. }
  633. protected function check_empty($value)
  634. {
  635. if (!isset($value))
  636. return true;
  637. if ($value === null)
  638. return true;
  639. if (trim($value) === "")
  640. return true;
  641. return false;
  642. }
  643. public function testcreateSign()
  644. {
  645. $params['act'] = 'refill';
  646. $params['amount'] = '100';
  647. $params['cardno'] = '1000111200006005872';
  648. $params['mchid'] = '1092';
  649. $params['notifyurl'] = 'http://202.85.213.156:8080//YeZiYKCallBackOrderServlet';
  650. $params['op'] = 'balance';
  651. $params['order_sn'] = 'jftest0000123';
  652. $sign = $this->md5_sign($params);
  653. }
  654. public function testCheckphone()
  655. {
  656. $check = function ($phone) {
  657. $url = 'https://mobileempty.shumaidata.com/mobileempty';
  658. $params['mobile'] = $phone;
  659. $headers = array();
  660. array_push($headers, "Authorization:APPCODE " . '8f92d951293f4d2ea48ff86d5a70c537');
  661. $resp = http_request($url, $params, 'GET', false, $headers);
  662. $resp = json_decode($resp, true);
  663. if ($resp['success'] == true && $resp['code'] == 200) {
  664. Log::record("data phone:{$phone} , status : {$resp['data']['status']}", Log::DEBUG);
  665. if (in_array($resp['data']['status'], [0, 3, 4, 5])) {
  666. return false;
  667. }
  668. } else {
  669. Log::record("data phone:{$phone} , 不支持的号段", Log::DEBUG);
  670. }
  671. };
  672. $check(17801048874);
  673. }
  674. public function testCtSign()
  675. {
  676. $params['act'] = 'refill';
  677. $params['mchid'] = 12345;
  678. $params['op'] = 'goods';
  679. $sign = $this->md5_sign($params);
  680. }
  681. private function md5_sign($params)
  682. {
  683. ksort($params);
  684. $body = "";
  685. $i = 0;
  686. foreach ($params as $k => $v) {
  687. if (false === $this->check_empty($v) && "@" != substr($v, 0, 1)) {
  688. if ($i == 0) {
  689. $body .= "{$k}" . "=" . urlencode($v);
  690. } else {
  691. $body .= "&" . "{$k}" . "=" . urlencode($v);
  692. }
  693. $i++;
  694. }
  695. }
  696. $body .= "&key=12345";
  697. return md5($body);
  698. }
  699. public function testCallMech()
  700. {
  701. $logic = Logic('queue');
  702. $logic->NotifyMerchantComplete(['order_id' => 18171, 'manual' => true]);
  703. }
  704. //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testCallMech)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test
  705. private function send($url, $params)
  706. {
  707. $mchid = $params['mchid'];
  708. $pri_key = BASE_DATA_PATH . "/api/merchant/key/{$mchid}_pri.pem";
  709. $key = file_get_contents($pri_key);
  710. $pri = openssl_get_privatekey($key);
  711. $body = $this->body($params);
  712. openssl_sign($body, $signed, $pri);
  713. $sign = base64_encode($signed);
  714. $params['sign'] = $sign;
  715. $resp = http_request($url, $params, 'POST');
  716. Log::record("resp:{$resp}", Log::DEBUG);
  717. }
  718. private function send_md5($url, $params)
  719. {
  720. $body = $this->body($params);
  721. $body .= "&key={$this->mKey}";
  722. $params['sign'] = md5($body);
  723. $resp = http_request($url, $params, 'POST');
  724. Log::record("resp:{$resp}", Log::DEBUG);
  725. return $resp;
  726. }
  727. public function testCardType()
  728. {
  729. $cardno = '1000111100021211884';
  730. $ret = preg_match('/^1[0-9]{18}$/', $cardno, $matches);
  731. }
  732. public function testMtrand()
  733. {
  734. }
  735. public function testHttpRefill()
  736. {
  737. $mchid = '000001';
  738. $pri_key = BASE_DATA_PATH . "/api/merchant/key/{$mchid}_pri.pem";
  739. $key = file_get_contents($pri_key);
  740. $pri = openssl_get_privatekey($key);
  741. $params = ['MCHID' => $mchid, 'cardno' => '1000111100021211884', 'amt' => "100", "act" => "refill", "op" => "addoil"];
  742. $body = $this->body($params);
  743. openssl_sign($body, $signed, $pri);
  744. $sign = base64_encode($signed);
  745. $params['sign'] = $sign;
  746. $resp = http_request(BASE_SITE_URL . "/mobile/index.php", $params, 'POST');
  747. }
  748. private function body($params)
  749. {
  750. ksort($params);
  751. $body = "";
  752. $i = 0;
  753. foreach ($params as $k => $v) {
  754. if (false === $this->checkEmpty($v) && "@" != substr($v, 0, 1)) {
  755. if ($i == 0) {
  756. $body .= "{$k}" . "=" . urlencode($v);
  757. } else {
  758. $body .= "&" . "{$k}" . "=" . urlencode($v);
  759. }
  760. $i++;
  761. }
  762. }
  763. return $body;
  764. }
  765. private function checkEmpty($value)
  766. {
  767. if (!isset($value))
  768. return true;
  769. if ($value === null)
  770. return true;
  771. if (trim($value) === "")
  772. return true;
  773. return false;
  774. }
  775. public function testKsort()
  776. {
  777. $age = ["Peter" => "35", "Ben" => "37", "Joe" => "43"];
  778. ksort($age);
  779. foreach ($age as $x => $x_value) {
  780. echo "Key=" . $x . ", Value=" . $x_value;
  781. echo "<br>";
  782. }
  783. }
  784. public function testip()
  785. {
  786. $model_merchant = Model('merchant');
  787. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => 1]);
  788. $ipwhitelist = unserialize($merchant_info['ip_white_list']);
  789. $res = json_encode($ipwhitelist);
  790. }
  791. //测试向内部店提交订单,可先屏蔽其它充值通道
  792. public function testAddoilToInnerStore()
  793. {
  794. $url = $this->mReqHost . "/mobile/index.php";
  795. $notifyurl = BASE_SITE_URL . '/mobile/signature.php';
  796. $params = ['mchid' => 1,
  797. 'cardno' => '1000111100020445281',
  798. 'amount' => "1000",
  799. "act" => "refill",
  800. "op" => "add",
  801. 'order_sn' => $this->make_sn(),
  802. 'notifyurl' => $notifyurl];
  803. $resp = $this->send_md5($url, $params);
  804. Log::record($resp, Log::DEBUG);
  805. }
  806. public function testRefillInnerCB()
  807. {
  808. $params = ['state_type' => 'order_cancel', 'order_id' => 311, 'channel_name' => 'lx'];
  809. $resp = http_request(BASE_SITE_URL . '/mobile/refill_inner.php', $params, 'POST');
  810. }
  811. public function testArgs()
  812. {
  813. Log::record($_SERVER['argv'], Log::DEBUG);
  814. }
  815. public function testCall()
  816. {
  817. $order_id = 14974;
  818. QueueClient::async_push("NotifyMerchantComplete", ['order_id' => $order_id, 'manual' => true], 10);
  819. }
  820. public function testSyncconfig()
  821. {
  822. $name_val_cfg = function ($items) {
  823. $result = [];
  824. foreach ($items as $item) {
  825. $name = $item->name();
  826. $result[$name] = $item;
  827. }
  828. return $result;
  829. };
  830. $name_val_row = function ($items) {
  831. $result = [];
  832. foreach ($items as $item) {
  833. $name = $item['name'];
  834. $result[$name] = $item;
  835. }
  836. return $result;
  837. };
  838. $match = function ($all, $cur) {
  839. $insert = [];
  840. foreach ($all as $key => $value) {
  841. if (!array_key_exists($key, $cur)) {
  842. $insert[] = $key;
  843. }
  844. }
  845. return $insert;
  846. };
  847. $inserter = function ($mod, $type, $names) {
  848. foreach ($names as $name) {
  849. $data = ['name' => $name, 'type' => $type];
  850. $mod->insert($data);
  851. }
  852. };
  853. $providers = refill\RefillFactory::instance()->providers();
  854. $oils = $name_val_cfg($providers['oil']);
  855. $phones = $name_val_cfg($providers['phone']);
  856. $mod_prov = Model('refill_provider');
  857. $oil_items = $mod_prov->getProviderList(['type' => 1]);
  858. $oil_items = $name_val_row($oil_items);
  859. $oil_inserts = $match($oils, $oil_items);
  860. $phone_items = $mod_prov->getProviderList(['type' => 2]);
  861. $phone_items = $name_val_row($phone_items);
  862. $phone_inserts = $match($phones, $phone_items);
  863. $inserter($mod_prov, 1, $oil_inserts);
  864. $inserter($mod_prov, 2, $phone_inserts);
  865. }
  866. public function testStat()
  867. {
  868. $model_refill_order = Model('refill_order');
  869. $stat = Model('')->table('refill_order,vr_order')->join('inner')
  870. ->on('refill_order.order_id=vr_order.order_id')
  871. ->field('sum(refill_amount) as refill_amounts , sum(channel_amount) as channel_amounts , sum(mch_amount) as mch_amounts')
  872. ->where([])->select();
  873. }
  874. public function testRefillGoods()
  875. {
  876. $goods = refill\RefillFactory::instance()->goods();
  877. }
  878. private function make_mobile()
  879. {
  880. $no = "1" . mt_rand(3000000000, 3999999999);
  881. return $no;
  882. }
  883. private function refill_info($card_no, $card_type)
  884. {
  885. $data = rcache($card_no, 'cardrefill-');
  886. if (empty($data)) {
  887. $mod_topcard = Model('topcard');
  888. $ret = $mod_topcard->get_card($card_no);
  889. if (empty($ret)) {
  890. $bind_phone = $this->make_mobile();
  891. $mod_topcard->add($card_no, $card_type, time(), $bind_phone);
  892. $data['bind_phone'] = $bind_phone;
  893. $data['refill_time'] = time();
  894. $data['times'] = 0;
  895. wcache($card_no, $data, 'cardrefill-');
  896. } else {
  897. $val = $ret[0];
  898. $data['bind_phone'] = $val['bind_phone'];
  899. $data['refill_time'] = time();
  900. $data['times'] = 0;
  901. }
  902. }
  903. return $data;
  904. }
  905. public function testGetMobile()
  906. {
  907. $card_no = '1000119000001679247';
  908. $card_type = 1;
  909. $info = $this->refill_info($card_no, $card_type);
  910. }
  911. private function check_mchorder($mchid, $mch_order)
  912. {
  913. if (empty($mch_order)) {
  914. return true;
  915. } else {
  916. $refill_order = Model('refill_order');
  917. $ret = $refill_order->getOrderInfo(['mchid' => $mchid, 'mch_order' => $mch_order]);
  918. return empty($ret);
  919. }
  920. }
  921. public function testCheckMchorder()
  922. {
  923. $ret = $this->check_mchorder(1, '13281475');
  924. }
  925. public function testMakemobile()
  926. {
  927. $mobile = refill\util::make_mobile();
  928. $ret = refill\util::set_black('1000111100020445281');
  929. }
  930. public function testLoadBlack()
  931. {
  932. $path = BASE_DATA_PATH . "/log";
  933. $names = ['20210119-mobile.log',
  934. '20210120-mobile.log', '20210121-mobile.log', '20210122-mobile.log', '20210123-mobile.log',
  935. '20210124-mobile.log', '20210125-mobile.log'];
  936. foreach ($names as $name) {
  937. $file_name = $path . "/" . $name;
  938. refill\util::black_from_log($file_name);
  939. }
  940. }
  941. public function testStats()
  942. {
  943. $date = date('Y-m-d', time());
  944. $today = strtotime("{$date}");
  945. $times_begin = function ($start) {
  946. $times = [];
  947. $begin = $start;
  948. for ($i = 0; $i < 7; $i++) {
  949. $times[] = $begin;
  950. $begin -= 86400;
  951. }
  952. return $times;
  953. };
  954. $reader = function ($mchid, $time) {
  955. $cond['mchid'] = $mchid;
  956. $cond['inner_status'] = 0;
  957. $cond['refill_order.order_time'] = ['between', [$time, $time + 86400 - 1]];
  958. $items = Model('')->table('refill_order,vr_order')->join('inner')
  959. ->on('refill_order.order_id=vr_order.order_id')
  960. ->field('count(*) as order_count, vr_order.order_state, sum(mch_amount) as mch_amounts')
  961. ->group('vr_order.order_state')
  962. ->where($cond)->select();
  963. return $items;
  964. };
  965. $begins = $times_begin($today);
  966. $mchid = 10096;
  967. // $states = rcache($this->mchid() , 'refillstat-');
  968. $states = unserialize($states ?? "");
  969. if (empty($states)) $states = [];
  970. $result = [];
  971. $cache = [];
  972. foreach ($begins as $begin) {
  973. if (array_key_exists($begin, $states)) {
  974. $item = $states[$begin];
  975. } else {
  976. $item = $reader($mchid, $begin);
  977. }
  978. $result[$begin] = $item;
  979. //判断item 中充值中的状态是否为0,为0的情况下放进cache
  980. $cache = $item;
  981. }
  982. wcache($this->mchid(), $cache, 'refillstat-');
  983. return $result;
  984. }
  985. public function testNotifyx()
  986. {
  987. $mch_cache = rcache("merchant-notify", 'refill-');
  988. $caches = empty($mch_cache['data']) ? [] : unserialize($mch_cache['data']);
  989. $new_caches = [];
  990. $merchants = Model('merchant')->getMerchantList([], '', '', 'merchant.*,member.available_predeposit', "0,1000");
  991. foreach ($merchants as $merchant) {
  992. $mchid = $merchant['mchid'];
  993. $phone = $merchant['contact_phone'] ?? "";
  994. $available_pd = intval($merchant['available_predeposit']);
  995. $alarm_pd = intval($merchant['alarm_amount']) < 10000 ? 10000 : intval($merchant['alarm_amount']);
  996. if (array_key_exists($mchid, $caches)) {
  997. $mch_cache = $caches[$mchid];
  998. } else {
  999. $mch_cache = ['last_time' => 0, 'send_count' => 0];
  1000. }
  1001. if (!empty($phone) && ($available_pd < $alarm_pd)) {
  1002. $counts = $mch_cache['send_count'];
  1003. if (($mch_cache['last_time'] + 300 < time()) && $counts < 5) {
  1004. $mch_cache = ['last_time' => time(), 'send_count' => $counts + 1];
  1005. QueueClient::push('sendSMS', ['mobile' => $merchant['contact_phone'],
  1006. 'type' => 'balance_warning', 'datas' => [date("m月d日H时"), $merchant['available_predeposit']]]);
  1007. }
  1008. } else {
  1009. $mch_cache = ['last_time' => 0, 'send_count' => 0];
  1010. }
  1011. $new_caches[$mchid] = $mch_cache;
  1012. }
  1013. wcache("merchant-notify", ['data' => serialize($new_caches)], 'refill-');
  1014. }
  1015. public function testReadChannel()
  1016. {
  1017. refill\RefillFactory::instance()->read_channel();
  1018. }
  1019. public function testAllow()
  1020. {
  1021. $allow = refill\RefillFactory::instance()->allow(10096, 1, 100);
  1022. }
  1023. public function testCheckData()
  1024. {
  1025. $str = '|2|110667993758599771-充值失败|';
  1026. // $str = '0|提交成功|-36557.7400';
  1027. // if(preg_match( '/^-*[0-9]{1,3}\|[\x{4e00}-\x{9fa5}]+\|-*[0-9]+\.*[0-9]+$/u',$str,$matches)) {
  1028. // return true;
  1029. // }
  1030. // if(preg_match('/^[0-3]\|[0-9]+-*[\x{4e00}-\x{9fa5}]+\|[0-9]*$/u',$str,$matches)){
  1031. // return true;
  1032. // }
  1033. // return false;
  1034. $resp = ltrim($str, '|');
  1035. $resp = explode('|', $resp);
  1036. if (count($resp) != 3) {
  1037. return [false, '返回值错误'];
  1038. }
  1039. }
  1040. public function testErrre()
  1041. {
  1042. $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}';
  1043. $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);
  1044. }
  1045. public function testLog()
  1046. {
  1047. // $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 ]';
  1048. $fn = fopen(BASE_ROOT_PATH . "/10096.log", "r");
  1049. $mod = Model();
  1050. $mod->table('tfloat')->where(['member_id' => 65818])->update(['pdamount' => 0]);
  1051. $total_amount = ncPriceFormat(0.00);
  1052. $i = 0;
  1053. while (!feof($fn)) {
  1054. $i++;
  1055. $line = trim(fgets($fn));
  1056. $ret = preg_match('/[\w\W]+UPDATE[\w\W]+available_predeposit=available_predeposit(?P<oper>[-+]+)(?P<amount>[.\d]+)/i', $line, $matches);
  1057. if ($ret) {
  1058. $oper = $matches['oper'];
  1059. $amount = $matches['amount'];
  1060. if ($oper == '-') {
  1061. $total_amount = ncPriceFormat($total_amount) - ncPriceFormat($amount);
  1062. // $mod->table('tfloat')->where(['member_id' => 65818])->update( ['pdamount'=>['exp','pdamount-'.$amount]]);
  1063. } else {
  1064. $total_amount = ncPriceFormat($total_amount) + ncPriceFormat($amount);
  1065. // $mod->table('tfloat')->where(['member_id' => 65818])->update( ['pdamount'=>['exp','pdamount+'.$amount]]);
  1066. }
  1067. Log::record("index = {$i} {$total_amount} = {$total_amount} {$oper} {$amount}", Log::DEBUG);
  1068. }
  1069. }
  1070. Log::record("total_amount:{$total_amount}", Log::DEBUG);
  1071. fclose($fn);
  1072. }
  1073. public function testMchctl()
  1074. {
  1075. $ctl = new refill\mchctl();
  1076. }
  1077. }
  1078. //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testLoadBlack)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test
  1079. //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