TestRefill.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314
  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('13699279618', 4, 50, ['order_sn' => $order_sn]);
  239. $resp = $providers->query(['order_sn' => '28641617178590981824']);
  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.935;
  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 testWantongPhone()
  332. {
  333. $providers = new refill\wantong\RefillPhone([]);
  334. $resp = $providers->add(13699279618, 4, 30, ['order_sn' => $this->make_sn()]);
  335. // $resp = $providers->query(['order_sn' => '50261617199864602428']);
  336. }
  337. public function testXunyinPhone()
  338. {
  339. $providers = new refill\xunyin\RefillPhone([]);
  340. // $resp = $providers->add(17703711950, 6, 30, ['order_sn' => $this->make_sn()]);
  341. // $resp = $providers->query(['order_sn' => '76831617176125893158']);
  342. $params['ext'] = '';
  343. $params['code'] = '8888';
  344. $params['sign'] = '428ac223cf3a1f6f3d382aac754e8e17';
  345. $params['statemes'] = '成功';
  346. $params['id'] = '76831617176125893158';
  347. $params['userid'] = '8417';
  348. $params['operatorid'] = '1000000083421033115583773201';
  349. $params['status'] = 'SUCCESS';
  350. refill\RefillFactory::instance()->notify('xunyin',$params);
  351. }
  352. public function testLingzhPhone()
  353. {
  354. $providers = new refill\lingzh\RefillPhone([]);
  355. // $resp = $providers->add(18500608333, 5, 10, ['order_sn' => $this->make_sn()]);
  356. // $resp = $providers->query(['order_sn' => '59911615124025101286']);
  357. $resp = $providers->balance();
  358. // $input['usr'] = 1;
  359. // $input['ord'] = '52741615119546453690';
  360. // $input['bz'] = '';
  361. // $input['state'] = 2;
  362. // $input['sgn'] = 'FFCBB75C307154DD306F4EC75BB69A6D';
  363. // refill\RefillFactory::instance()->notify('lingzh',$input);
  364. }
  365. public function testAfandnewPhone()
  366. {
  367. $providers = new refill\afandnew\RefillPhone([]);
  368. // $resp = $providers->add(18500608333, 5, 100, ['order_sn' => $this->make_sn()]);
  369. // $resp = $providers->query(['order_sn' => '45371617101073876975', 'ch_trade_no' => '33018443659736309']);
  370. $params = '{"amount":"100","carrierOrderNo":null,"mobile":"18500608333","orderNo":"45371617101073876975","orderStatus":3,"sign":"8DE392AD6B4730AD9EE0FC2B95BBDF17","tradeNo":"33018443659736309"}';
  371. $input = json_decode($params, true);
  372. refill\RefillFactory::instance()->notify('afandnew', $input);
  373. }
  374. public function testYifaPhone()
  375. {
  376. $providers = new refill\yifa\RefillPhone([]);
  377. $resp = $providers->add(15120035568, 5, 50, ['order_sn' => $this->make_sn()]);
  378. }
  379. public function testTianjtOil()
  380. {
  381. $cardno = 1000111100021211884;
  382. $providers = new refill\tianjt\RefillOil([]);
  383. $resp = $providers->add($cardno, 2, 500, ['order_sn' => $this->make_sn()]);
  384. }
  385. public function testWeitPhone()
  386. {
  387. $providers = new refill\weit\RefillPhone([]);
  388. for ($i = 0; $i <= 10; $i++) {
  389. $resp = $providers->add(18500608333, 5, 10, ['order_sn' => $this->make_sn()]);
  390. }
  391. }
  392. public function testWeitCB()
  393. {
  394. $params['sign'] = 'af820c33472f4b571fa0c48483dfb975';
  395. $params['status'] = 0;
  396. $params['price'] = 30;
  397. $params['op_order_id'] = '';
  398. $params['mch_order_id'] = '900664281823957221';
  399. $params['pt_order_id'] = '2021011802434412825405218901';
  400. $params['pay_type'] = '';
  401. $params['tel'] = 18500608333;
  402. $params['mchid'] = 10014;
  403. $resp = http_request($this->mReqHost . "/mobile/refill_weit.php", $params, 'POST');
  404. }
  405. public function testYifaCB()
  406. {
  407. $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"}';
  408. $input = json_decode($body, true);
  409. refill\RefillFactory::instance()->notify('yifa', $input);
  410. }
  411. public function testBjbQuery()
  412. {
  413. $providers = new refill\bjb\RefillPhone([]);
  414. $refill_info = ['order_sn' => 110667993758599771, 'ch_trade_no' => 499, 'card_no' => 1000111200005252927];
  415. $resp = $providers->query($refill_info);
  416. }
  417. public function testXcQuery()
  418. {
  419. $providers = new refill\xc\RefillPhone([]);
  420. $refill_info = ['order_sn' => 950663423236726632, 'ch_trade_no' => 499, 'card_no' => 1000111200005252927];
  421. $resp = $providers->query($refill_info);
  422. }
  423. public function testTianjtQuery()
  424. {
  425. $providers = new refill\tianjt\RefillOil([]);
  426. $refill_info = ['order_sn' => 680665862267622221, 'ch_trade_no' => 499, 'card_no' => 1000111200005252927];
  427. $resp = $providers->query($refill_info);
  428. }
  429. public function testSaihuOil()
  430. {
  431. $providers = new refill\saihu\RefillOil([]);
  432. $resp = $providers->add(1000111100021211884, 2, 100, ['order_sn' => $this->make_sn()]);
  433. }
  434. public function testBdtOil()
  435. {
  436. $providers = new refill\bdt\RefillOil([]);
  437. $resp = $providers->add(1000111100021211884, 2, 100, ['order_sn' => '200229600556618886']);
  438. }
  439. public function testGFTDOil()
  440. {
  441. $providers = new refill\gftd\RefillOil([]);
  442. $resp = $providers->add(1000111100020445281, mtopcard\SinopecCard, 100, ['order_sn' => $this->make_sn()]);
  443. }
  444. public function testGFTDCB()
  445. {
  446. $data = '{"channelOrderNumber":"79091610959059372019","orderNumber":"GYFL1610959060397001","message":"充值成功","signature":"881036222bd8f067ff47d248c75f4c8d","voucher":"","status":101}';
  447. $url = "http://192.168.1.220/mobile/refill_gftd.php?" . $data;
  448. $resp = http_post_data($url, $data, ['Content-Type: application/json;charset=UTF-8;', 'Accept:application/json;charset=UTF-8;']);
  449. }
  450. public function testJiecPhone()
  451. {
  452. $providers = new refill\jiec\RefillPhone([]);
  453. $resp = $providers->add('18500608333', 5, 30, ['order_sn' => $this->make_sn()]);
  454. }
  455. public function testBxtwtCB()
  456. {
  457. $data = '{"order_number":18219726,"shipping_status":4,"shipping_status_desc":"发货失败","shipping_status_message":"","sign":"863b4d972f2a4d39a9af7396879116c4","voucher":"","vouchertype":"","voucherurl":"","tradeNo":"100662475851197741"}';
  458. }
  459. public function testTianjtJDVerify()
  460. {
  461. $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';
  462. $url = "http://192.168.1.220/mobile/refill_tianjt.php?" . $data;
  463. $resp = http_request($url);
  464. }
  465. public function testSuhcPDD()
  466. {
  467. $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';
  468. $url = "https://www.xyzshops.cn/mobile/refill_suhcpdd.php?" . $data;
  469. $resp = http_request($url);
  470. }
  471. public function testSuhcTMVerify()
  472. {
  473. $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';
  474. $url = "https://www.xyzshops.cn/mobile/refill_suhctm.php?" . $data;
  475. $resp = http_request($url);
  476. }
  477. public function testBeixtVerify()
  478. {
  479. $data = '{"order_number":18219726,"shipping_status":4,"shipping_status_desc":"发货失败","shipping_status_message":"","sign":"863b4d972f2a4d39a9af7396879116c4","voucher":"","vouchertype":"","voucherurl":"","tradeNo":"100662475851197741"}';
  480. $url = "https://www.xyzshops.cn/mobile/refill_bxtwt.php";
  481. $headers = ['Content-Type: application/json'];
  482. $resp = http_post_data($url, $data, $headers);
  483. }
  484. public function testInput()
  485. {
  486. $input = fopen("php://input", "rw");
  487. file_put_contents($input, 'xxxx');
  488. $content = file_get_contents('php://input');
  489. }
  490. public function testUrl()
  491. {
  492. $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';
  493. $params = preg_split('/&/', $data);
  494. foreach ($params as $pair) {
  495. $kv = explode('=', $pair);
  496. $count = count($kv);
  497. if ($count === 1) {
  498. $key = $kv[0];
  499. $val = "";
  500. } elseif ($count === 2) {
  501. $key = $kv[0];
  502. $val = $kv[1];
  503. } else {
  504. continue;
  505. }
  506. Log::record("{$key}:{$val}", Log::DEBUG);
  507. }
  508. }
  509. public function testAddoil()
  510. {
  511. $url = $this->mReqHost . "/mobile/index.php";
  512. $notifyurl = 'http://121.89.196.45/mobile/signature.php';
  513. $params = ['mchid' => $this->mMchid,
  514. 'cardno' => '1000111100020445281',
  515. 'amount' => "100",
  516. "act" => "refill",
  517. "op" => "add",
  518. 'order_sn' => $this->make_sn(),
  519. 'notifyurl' => $notifyurl];
  520. $resp = $this->send_md5($url, $params);
  521. Log::record($resp, Log::DEBUG);
  522. }
  523. public function testBalance()
  524. {
  525. $url = $this->mReqHost . "/mobile/index.php";
  526. $params = ['mchid' => 1092,
  527. "act" => "refill",
  528. "op" => "balance"];
  529. $resp = $this->send_md5($url, $params);
  530. Log::record($resp, Log::DEBUG);
  531. }
  532. public function testAddPhoe()
  533. {
  534. $phones = [//13911129867,
  535. 18500608333,
  536. 18510683168,
  537. 18513846008,
  538. 18518237398];
  539. $amount = 10;
  540. for ($i = 0; $i < 3; $i++) {
  541. foreach ($phones as $phone) {
  542. $url = $this->mReqHost . "/mobile/index.php";
  543. $params = ['mchid' => 1092,
  544. 'cardno' => $phone,
  545. 'amount' => $amount,
  546. "act" => "refill",
  547. "op" => "add",
  548. 'order_sn' => $this->make_sn(),
  549. 'notifyurl' => $this->mReqHost . "/mobile/refill_xyz.php"];
  550. $resp = $this->send_md5($url, $params);
  551. Log::record($resp, Log::DEBUG);
  552. }
  553. }
  554. }
  555. public function testProxyHelper()
  556. {
  557. $phone = '13911129867';
  558. $amount = 100;
  559. $url = $this->mReqHost . "/mobile/index.php";
  560. $params = ['mchid' => 1090,
  561. 'cardno' => $phone,
  562. 'amount' => $amount,
  563. "act" => "refill",
  564. "op" => "add",
  565. 'order_sn' => $this->make_sn(),
  566. 'notifyurl' => "https://xxx"];
  567. $proxy = new refill_proxy("xxx");
  568. $resp = $proxy->send($url, $params);
  569. }
  570. public function testGoods()
  571. {
  572. $req_url = $this->mReqHost . '/mobile/index.php';
  573. $params = ['mchid' => $this->mMchid,
  574. "act" => "refill",
  575. "op" => "goods"];
  576. $resp = $this->send_md5($req_url, $params);
  577. }
  578. public function testQueryFactory()
  579. {
  580. refill\RefillFactory::instance()->query(295);
  581. }
  582. public function testQuery()
  583. {
  584. //$req_url = 'https://www.xyzshops.cn/mobile/index.php';
  585. // $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php';
  586. $req_url = BASE_SITE_URL . '/mobile/index.php';
  587. $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php';
  588. $params = ['mchid' => 1,
  589. "act" => "refill",
  590. "op" => "query",
  591. 'order_sn' => "13281476"];
  592. $resp = $this->send_md5($req_url, $params);
  593. }
  594. public function testRemoveSession()
  595. {
  596. $resp = http_request(BASE_SITE_URL . "/mobile/signature.php", [], 'POST');
  597. }
  598. public function testTianjtCB()
  599. {
  600. // $notifyurl = BASE_SITE_URL . "/mobile/refill_tianjt.php";
  601. $notifyurl = "https://www.xyzshops.cn/mobile/refill_tianjt.php";
  602. // $notifyurl = "https%3A%2F%2Fwww.xyzshops.cn%2Fmobile%2Frefill_tianjt.php";
  603. $params = ['onlystr' => '690665858589475818',
  604. 'amt' => 1000,
  605. 'jdno' => '',
  606. 'notifyurl' => $notifyurl,
  607. 'cardtype' => 'Sinoepc',
  608. 'batchid' => 30589,
  609. 'cardno' => '1000113300007993287',
  610. 'orgid' => '1590993600',
  611. 'status' => 3];
  612. $sign = $this->md5_sign($params);
  613. $params['sign'] = $sign;
  614. $resp = http_request($notifyurl, $params, 'POST');
  615. Log::record($resp, Log::DEBUG);
  616. }
  617. public function testBJBCB()
  618. {
  619. $params = [
  620. 'usr' => '13699279618',
  621. 'ord' => '710662733975412771',
  622. 'state' => '2',
  623. 'bz' => '',
  624. 'sgn' => 'AC9AFD254DE682D8440A97CA68B992DA'
  625. ];
  626. $resp = http_request("https://www.xyzshops.cn/mobile/refill_bjb.php", $params, 'POST');
  627. }
  628. public function testJiecCB()
  629. {
  630. $params['result'] = 'fail';
  631. $params['msg'] = '0';
  632. $params['order'] = 'null';
  633. $params['phone_no'] = '18500608333';
  634. $params['amount'] = '30.00';
  635. $params['op_no'] = '800663597981819221';
  636. $params['sign'] = '2510046895e8e12322c8a32547905ee9';
  637. $resp = http_request($this->mReqHost . "/mobile/refill_jiec.php", $params, 'POST');
  638. }
  639. public function testZFKJ()
  640. {
  641. //带签名参数:mchid=1090&act=refill&op=add&cardno=100112121212212133
  642. //&amount=10&order_sn=PH2012261356569433&
  643. //notifyurl=https%3A%2F%2Fqzcz.edusahoo.com.cn%2Findex%2Findex%2Fcallback
  644. //&sign=4a3ac5f9706e64aa70c6cab0fc5839d3
  645. $params = ['mchid' => 1090,
  646. 'cardno' => '100112121212212133',
  647. 'amount' => '10',
  648. "act" => "refill",
  649. "op" => "add",
  650. 'order_sn' => 'PH2012261356569433',
  651. 'notifyurl' => 'https://qzcz.edusahoo.com.cn/index/index/callback'];
  652. $resp = $this->send_md5(BASE_SITE_URL . '/mobile/index.php', $params);
  653. }
  654. protected function check_empty($value)
  655. {
  656. if (!isset($value))
  657. return true;
  658. if ($value === null)
  659. return true;
  660. if (trim($value) === "")
  661. return true;
  662. return false;
  663. }
  664. public function testcreateSign()
  665. {
  666. $params['act'] = 'refill';
  667. $params['amount'] = '100';
  668. $params['cardno'] = '1000111200006005872';
  669. $params['mchid'] = '1092';
  670. $params['notifyurl'] = 'http://202.85.213.156:8080//YeZiYKCallBackOrderServlet';
  671. $params['op'] = 'balance';
  672. $params['order_sn'] = 'jftest0000123';
  673. $sign = $this->md5_sign($params);
  674. }
  675. public function testCheckphone()
  676. {
  677. $check = function ($phone) {
  678. $url = 'https://mobileempty.shumaidata.com/mobileempty';
  679. $params['mobile'] = $phone;
  680. $headers = array();
  681. array_push($headers, "Authorization:APPCODE " . '8f92d951293f4d2ea48ff86d5a70c537');
  682. $resp = http_request($url, $params, 'GET', false, $headers);
  683. $resp = json_decode($resp, true);
  684. if ($resp['success'] == true && $resp['code'] == 200) {
  685. Log::record("data phone:{$phone} , status : {$resp['data']['status']}", Log::DEBUG);
  686. if (in_array($resp['data']['status'], [0, 3, 4, 5])) {
  687. return false;
  688. }
  689. } else {
  690. Log::record("data phone:{$phone} , 不支持的号段", Log::DEBUG);
  691. }
  692. };
  693. $check(17801048874);
  694. }
  695. public function testCtSign()
  696. {
  697. $params['act'] = 'refill';
  698. $params['mchid'] = 12345;
  699. $params['op'] = 'goods';
  700. $sign = $this->md5_sign($params);
  701. }
  702. private function md5_sign($params)
  703. {
  704. ksort($params);
  705. $body = "";
  706. $i = 0;
  707. foreach ($params as $k => $v) {
  708. if (false === $this->check_empty($v) && "@" != substr($v, 0, 1)) {
  709. if ($i == 0) {
  710. $body .= "{$k}" . "=" . urlencode($v);
  711. } else {
  712. $body .= "&" . "{$k}" . "=" . urlencode($v);
  713. }
  714. $i++;
  715. }
  716. }
  717. $body .= "&key=12345";
  718. return md5($body);
  719. }
  720. public function testCallMech()
  721. {
  722. $logic = Logic('queue');
  723. $logic->NotifyMerchantComplete(['order_id' => 18171, 'manual' => true]);
  724. }
  725. //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testCallMech)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test
  726. private function send($url, $params)
  727. {
  728. $mchid = $params['mchid'];
  729. $pri_key = BASE_DATA_PATH . "/api/merchant/key/{$mchid}_pri.pem";
  730. $key = file_get_contents($pri_key);
  731. $pri = openssl_get_privatekey($key);
  732. $body = $this->body($params);
  733. openssl_sign($body, $signed, $pri);
  734. $sign = base64_encode($signed);
  735. $params['sign'] = $sign;
  736. $resp = http_request($url, $params, 'POST');
  737. Log::record("resp:{$resp}", Log::DEBUG);
  738. }
  739. private function send_md5($url, $params)
  740. {
  741. $body = $this->body($params);
  742. $body .= "&key={$this->mKey}";
  743. $params['sign'] = md5($body);
  744. $resp = http_request($url, $params, 'POST');
  745. Log::record("resp:{$resp}", Log::DEBUG);
  746. return $resp;
  747. }
  748. public function testCardType()
  749. {
  750. $cardno = '1000111100021211884';
  751. $ret = preg_match('/^1[0-9]{18}$/', $cardno, $matches);
  752. }
  753. public function testMtrand()
  754. {
  755. }
  756. public function testHttpRefill()
  757. {
  758. $mchid = '000001';
  759. $pri_key = BASE_DATA_PATH . "/api/merchant/key/{$mchid}_pri.pem";
  760. $key = file_get_contents($pri_key);
  761. $pri = openssl_get_privatekey($key);
  762. $params = ['MCHID' => $mchid, 'cardno' => '1000111100021211884', 'amt' => "100", "act" => "refill", "op" => "addoil"];
  763. $body = $this->body($params);
  764. openssl_sign($body, $signed, $pri);
  765. $sign = base64_encode($signed);
  766. $params['sign'] = $sign;
  767. $resp = http_request(BASE_SITE_URL . "/mobile/index.php", $params, 'POST');
  768. }
  769. private function body($params)
  770. {
  771. ksort($params);
  772. $body = "";
  773. $i = 0;
  774. foreach ($params as $k => $v) {
  775. if (false === $this->checkEmpty($v) && "@" != substr($v, 0, 1)) {
  776. if ($i == 0) {
  777. $body .= "{$k}" . "=" . urlencode($v);
  778. } else {
  779. $body .= "&" . "{$k}" . "=" . urlencode($v);
  780. }
  781. $i++;
  782. }
  783. }
  784. return $body;
  785. }
  786. private function checkEmpty($value)
  787. {
  788. if (!isset($value))
  789. return true;
  790. if ($value === null)
  791. return true;
  792. if (trim($value) === "")
  793. return true;
  794. return false;
  795. }
  796. public function testKsort()
  797. {
  798. $age = ["Peter" => "35", "Ben" => "37", "Joe" => "43"];
  799. ksort($age);
  800. foreach ($age as $x => $x_value) {
  801. echo "Key=" . $x . ", Value=" . $x_value;
  802. echo "<br>";
  803. }
  804. }
  805. public function testip()
  806. {
  807. $model_merchant = Model('merchant');
  808. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => 1]);
  809. $ipwhitelist = unserialize($merchant_info['ip_white_list']);
  810. $res = json_encode($ipwhitelist);
  811. }
  812. //测试向内部店提交订单,可先屏蔽其它充值通道
  813. public function testAddoilToInnerStore()
  814. {
  815. $url = $this->mReqHost . "/mobile/index.php";
  816. $notifyurl = BASE_SITE_URL . '/mobile/signature.php';
  817. $params = ['mchid' => 1,
  818. 'cardno' => '1000111100020445281',
  819. 'amount' => "1000",
  820. "act" => "refill",
  821. "op" => "add",
  822. 'order_sn' => $this->make_sn(),
  823. 'notifyurl' => $notifyurl];
  824. $resp = $this->send_md5($url, $params);
  825. Log::record($resp, Log::DEBUG);
  826. }
  827. public function testRefillInnerCB()
  828. {
  829. $params = ['state_type' => 'order_cancel', 'order_id' => 311, 'channel_name' => 'lx'];
  830. $resp = http_request(BASE_SITE_URL . '/mobile/refill_inner.php', $params, 'POST');
  831. }
  832. public function testArgs()
  833. {
  834. Log::record($_SERVER['argv'], Log::DEBUG);
  835. }
  836. public function testCall()
  837. {
  838. $order_id = 14974;
  839. QueueClient::async_push("NotifyMerchantComplete", ['order_id' => $order_id, 'manual' => true], 10);
  840. }
  841. public function testSyncconfig()
  842. {
  843. $name_val_cfg = function ($items) {
  844. $result = [];
  845. foreach ($items as $item) {
  846. $name = $item->name();
  847. $result[$name] = $item;
  848. }
  849. return $result;
  850. };
  851. $name_val_row = function ($items) {
  852. $result = [];
  853. foreach ($items as $item) {
  854. $name = $item['name'];
  855. $result[$name] = $item;
  856. }
  857. return $result;
  858. };
  859. $match = function ($all, $cur) {
  860. $insert = [];
  861. foreach ($all as $key => $value) {
  862. if (!array_key_exists($key, $cur)) {
  863. $insert[] = $key;
  864. }
  865. }
  866. return $insert;
  867. };
  868. $inserter = function ($mod, $type, $names) {
  869. foreach ($names as $name) {
  870. $data = ['name' => $name, 'type' => $type];
  871. $mod->insert($data);
  872. }
  873. };
  874. $providers = refill\RefillFactory::instance()->providers();
  875. $oils = $name_val_cfg($providers['oil']);
  876. $phones = $name_val_cfg($providers['phone']);
  877. $mod_prov = Model('refill_provider');
  878. $oil_items = $mod_prov->getProviderList(['type' => 1]);
  879. $oil_items = $name_val_row($oil_items);
  880. $oil_inserts = $match($oils, $oil_items);
  881. $phone_items = $mod_prov->getProviderList(['type' => 2]);
  882. $phone_items = $name_val_row($phone_items);
  883. $phone_inserts = $match($phones, $phone_items);
  884. $inserter($mod_prov, 1, $oil_inserts);
  885. $inserter($mod_prov, 2, $phone_inserts);
  886. }
  887. public function testStat()
  888. {
  889. $model_refill_order = Model('refill_order');
  890. $stat = Model('')->table('refill_order,vr_order')->join('inner')
  891. ->on('refill_order.order_id=vr_order.order_id')
  892. ->field('sum(refill_amount) as refill_amounts , sum(channel_amount) as channel_amounts , sum(mch_amount) as mch_amounts')
  893. ->where([])->select();
  894. }
  895. public function testRefillGoods()
  896. {
  897. $goods = refill\RefillFactory::instance()->goods();
  898. }
  899. private function make_mobile()
  900. {
  901. $no = "1" . mt_rand(3000000000, 3999999999);
  902. return $no;
  903. }
  904. private function refill_info($card_no, $card_type)
  905. {
  906. $data = rcache($card_no, 'cardrefill-');
  907. if (empty($data)) {
  908. $mod_topcard = Model('topcard');
  909. $ret = $mod_topcard->get_card($card_no);
  910. if (empty($ret)) {
  911. $bind_phone = $this->make_mobile();
  912. $mod_topcard->add($card_no, $card_type, time(), $bind_phone);
  913. $data['bind_phone'] = $bind_phone;
  914. $data['refill_time'] = time();
  915. $data['times'] = 0;
  916. wcache($card_no, $data, 'cardrefill-');
  917. } else {
  918. $val = $ret[0];
  919. $data['bind_phone'] = $val['bind_phone'];
  920. $data['refill_time'] = time();
  921. $data['times'] = 0;
  922. }
  923. }
  924. return $data;
  925. }
  926. public function testGetMobile()
  927. {
  928. $card_no = '1000119000001679247';
  929. $card_type = 1;
  930. $info = $this->refill_info($card_no, $card_type);
  931. }
  932. private function check_mchorder($mchid, $mch_order)
  933. {
  934. if (empty($mch_order)) {
  935. return true;
  936. } else {
  937. $refill_order = Model('refill_order');
  938. $ret = $refill_order->getOrderInfo(['mchid' => $mchid, 'mch_order' => $mch_order]);
  939. return empty($ret);
  940. }
  941. }
  942. public function testCheckMchorder()
  943. {
  944. $ret = $this->check_mchorder(1, '13281475');
  945. }
  946. public function testMakemobile()
  947. {
  948. $mobile = refill\util::make_mobile();
  949. $ret = refill\util::set_black('1000111100020445281');
  950. }
  951. public function testLoadBlack()
  952. {
  953. $path = BASE_DATA_PATH . "/log";
  954. $names = ['20210119-mobile.log',
  955. '20210120-mobile.log', '20210121-mobile.log', '20210122-mobile.log', '20210123-mobile.log',
  956. '20210124-mobile.log', '20210125-mobile.log'];
  957. foreach ($names as $name) {
  958. $file_name = $path . "/" . $name;
  959. refill\util::black_from_log($file_name);
  960. }
  961. }
  962. public function testStats()
  963. {
  964. $date = date('Y-m-d', time());
  965. $today = strtotime("{$date}");
  966. $times_begin = function ($start) {
  967. $times = [];
  968. $begin = $start;
  969. for ($i = 0; $i < 7; $i++) {
  970. $times[] = $begin;
  971. $begin -= 86400;
  972. }
  973. return $times;
  974. };
  975. $reader = function ($mchid, $time) {
  976. $cond['mchid'] = $mchid;
  977. $cond['inner_status'] = 0;
  978. $cond['refill_order.order_time'] = ['between', [$time, $time + 86400 - 1]];
  979. $items = Model('')->table('refill_order,vr_order')->join('inner')
  980. ->on('refill_order.order_id=vr_order.order_id')
  981. ->field('count(*) as order_count, vr_order.order_state, sum(mch_amount) as mch_amounts')
  982. ->group('vr_order.order_state')
  983. ->where($cond)->select();
  984. return $items;
  985. };
  986. $begins = $times_begin($today);
  987. $mchid = 10096;
  988. // $states = rcache($this->mchid() , 'refillstat-');
  989. $states = unserialize($states ?? "");
  990. if (empty($states)) $states = [];
  991. $result = [];
  992. $cache = [];
  993. foreach ($begins as $begin) {
  994. if (array_key_exists($begin, $states)) {
  995. $item = $states[$begin];
  996. } else {
  997. $item = $reader($mchid, $begin);
  998. }
  999. $result[$begin] = $item;
  1000. //判断item 中充值中的状态是否为0,为0的情况下放进cache
  1001. $cache = $item;
  1002. }
  1003. wcache($this->mchid(), $cache, 'refillstat-');
  1004. return $result;
  1005. }
  1006. public function testNotifyx()
  1007. {
  1008. $mch_cache = rcache("merchant-notify", 'refill-');
  1009. $caches = empty($mch_cache['data']) ? [] : unserialize($mch_cache['data']);
  1010. $new_caches = [];
  1011. $merchants = Model('merchant')->getMerchantList([], '', '', 'merchant.*,member.available_predeposit', "0,1000");
  1012. foreach ($merchants as $merchant) {
  1013. $mchid = $merchant['mchid'];
  1014. $phone = $merchant['contact_phone'] ?? "";
  1015. $available_pd = intval($merchant['available_predeposit']);
  1016. $alarm_pd = intval($merchant['alarm_amount']) < 10000 ? 10000 : intval($merchant['alarm_amount']);
  1017. if (array_key_exists($mchid, $caches)) {
  1018. $mch_cache = $caches[$mchid];
  1019. } else {
  1020. $mch_cache = ['last_time' => 0, 'send_count' => 0];
  1021. }
  1022. if (!empty($phone) && ($available_pd < $alarm_pd)) {
  1023. $counts = $mch_cache['send_count'];
  1024. if (($mch_cache['last_time'] + 300 < time()) && $counts < 5) {
  1025. $mch_cache = ['last_time' => time(), 'send_count' => $counts + 1];
  1026. QueueClient::push('sendSMS', ['mobile' => $merchant['contact_phone'],
  1027. 'type' => 'balance_warning', 'datas' => [date("m月d日H时"), $merchant['available_predeposit']]]);
  1028. }
  1029. } else {
  1030. $mch_cache = ['last_time' => 0, 'send_count' => 0];
  1031. }
  1032. $new_caches[$mchid] = $mch_cache;
  1033. }
  1034. wcache("merchant-notify", ['data' => serialize($new_caches)], 'refill-');
  1035. }
  1036. public function testReadChannel()
  1037. {
  1038. refill\RefillFactory::instance()->read_channel();
  1039. }
  1040. public function testAllow()
  1041. {
  1042. $allow = refill\RefillFactory::instance()->allow(10096, 1, 100);
  1043. }
  1044. public function testCheckData()
  1045. {
  1046. $str = '|2|110667993758599771-充值失败|';
  1047. // $str = '0|提交成功|-36557.7400';
  1048. // if(preg_match( '/^-*[0-9]{1,3}\|[\x{4e00}-\x{9fa5}]+\|-*[0-9]+\.*[0-9]+$/u',$str,$matches)) {
  1049. // return true;
  1050. // }
  1051. // if(preg_match('/^[0-3]\|[0-9]+-*[\x{4e00}-\x{9fa5}]+\|[0-9]*$/u',$str,$matches)){
  1052. // return true;
  1053. // }
  1054. // return false;
  1055. $resp = ltrim($str, '|');
  1056. $resp = explode('|', $resp);
  1057. if (count($resp) != 3) {
  1058. return [false, '返回值错误'];
  1059. }
  1060. }
  1061. public function testErrre()
  1062. {
  1063. $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}';
  1064. $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);
  1065. }
  1066. public function testLog()
  1067. {
  1068. // $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 ]';
  1069. $fn = fopen(BASE_ROOT_PATH . "/10096.log", "r");
  1070. $mod = Model();
  1071. $mod->table('tfloat')->where(['member_id' => 65818])->update(['pdamount' => 0]);
  1072. $total_amount = ncPriceFormat(0.00);
  1073. $i = 0;
  1074. while (!feof($fn)) {
  1075. $i++;
  1076. $line = trim(fgets($fn));
  1077. $ret = preg_match('/[\w\W]+UPDATE[\w\W]+available_predeposit=available_predeposit(?P<oper>[-+]+)(?P<amount>[.\d]+)/i', $line, $matches);
  1078. if ($ret) {
  1079. $oper = $matches['oper'];
  1080. $amount = $matches['amount'];
  1081. if ($oper == '-') {
  1082. $total_amount = ncPriceFormat($total_amount) - ncPriceFormat($amount);
  1083. // $mod->table('tfloat')->where(['member_id' => 65818])->update( ['pdamount'=>['exp','pdamount-'.$amount]]);
  1084. } else {
  1085. $total_amount = ncPriceFormat($total_amount) + ncPriceFormat($amount);
  1086. // $mod->table('tfloat')->where(['member_id' => 65818])->update( ['pdamount'=>['exp','pdamount+'.$amount]]);
  1087. }
  1088. Log::record("index = {$i} {$total_amount} = {$total_amount} {$oper} {$amount}", Log::DEBUG);
  1089. }
  1090. }
  1091. Log::record("total_amount:{$total_amount}", Log::DEBUG);
  1092. fclose($fn);
  1093. }
  1094. public function testMchctl()
  1095. {
  1096. $ctl = new refill\mchctl();
  1097. }
  1098. }
  1099. //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testLoadBlack)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test
  1100. //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