TestRefill.php 36 KB

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