TestRefill.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098
  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 testWeisPhone()
  185. {
  186. $providers = new refill\weisyd\RefillPhone([]);
  187. $resp = $providers->add(17801048874, 4, 10, ['order_sn' => $this->make_sn()]);
  188. }
  189. public function testXcPhone()
  190. {
  191. $providers = new refill\xc\RefillPhone([]);
  192. $resp = $providers->add(18500608333, 5, 100, ['order_sn' => $this->make_sn()]);
  193. }
  194. public function testAfandPhone()
  195. {
  196. $providers = new refill\afand\RefillPhone([]);
  197. for ($i = 3; $i > 0; --$i) {
  198. $resp = $providers->add(18518267398, 4, 30, ['order_sn' => $this->make_sn()]);
  199. }
  200. }
  201. public function testAfandengPhone()
  202. {
  203. $providers = new refill\afandeng\RefillPhone([]);
  204. $resp = $providers->add(13699279618, 4, 30, ['order_sn' => $this->make_sn()]);
  205. }
  206. public function testYifaPhone()
  207. {
  208. $providers = new refill\yifa\RefillPhone([]);
  209. $resp = $providers->add(15120035568, 5, 50, ['order_sn' => $this->make_sn()]);
  210. }
  211. public function testTianjtOil()
  212. {
  213. $cardno = 1000111100021211884;
  214. $providers = new refill\tianjt\RefillOil([]);
  215. $resp = $providers->add($cardno, 2, 500, ['order_sn' => $this->make_sn()]);
  216. }
  217. public function testTianxPhone()
  218. {
  219. $cardno = 13699279618;
  220. $providers = new refill\tianx\RefillPhone([]);
  221. $resp = $providers->add($cardno, 4, 50, ['order_sn' => $this->make_sn()]);
  222. }
  223. public function testWeitPhone()
  224. {
  225. $providers = new refill\weit\RefillPhone([]);
  226. for ($i = 0;$i<=10;$i++){
  227. $resp = $providers->add(18500608333, 5, 10, ['order_sn' => $this->make_sn()]);
  228. }
  229. }
  230. public function testWeitCB()
  231. {
  232. $params['sign'] = 'af820c33472f4b571fa0c48483dfb975';
  233. $params['status'] = 0;
  234. $params['price'] = 30;
  235. $params['op_order_id'] = '';
  236. $params['mch_order_id'] = '900664281823957221';
  237. $params['pt_order_id'] = '2021011802434412825405218901';
  238. $params['pay_type'] = '';
  239. $params['tel'] = 18500608333;
  240. $params['mchid'] = 10014;
  241. $resp = http_request($this->mReqHost . "/mobile/refill_weit.php", $params , 'POST');
  242. }
  243. public function testYifaCB()
  244. {
  245. $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"}';
  246. $input = json_decode($body,true);
  247. refill\RefillFactory::instance()->notify('yifa',$input);
  248. }
  249. public function testBjbQuery()
  250. {
  251. $providers = new refill\bjb\RefillPhone([]);
  252. $refill_info = ['order_sn' => 110667993758599771, 'ch_trade_no' => 499, 'card_no' => 1000111200005252927];
  253. $resp = $providers->query($refill_info);
  254. }
  255. public function testXcQuery()
  256. {
  257. $providers = new refill\xc\RefillPhone([]);
  258. $refill_info = ['order_sn' => 950663423236726632, 'ch_trade_no' => 499, 'card_no' => 1000111200005252927];
  259. $resp = $providers->query($refill_info);
  260. }
  261. public function testTianjtQuery()
  262. {
  263. $providers = new refill\tianjt\RefillOil([]);
  264. $refill_info = ['order_sn' => 680665862267622221, 'ch_trade_no' => 499, 'card_no' => 1000111200005252927];
  265. $resp = $providers->query($refill_info);
  266. }
  267. public function testSaihuOil()
  268. {
  269. $providers = new refill\saihu\RefillOil([]);
  270. $resp = $providers->add(1000111100021211884, 2, 100, ['order_sn' => $this->make_sn()]);
  271. }
  272. public function testBdtOil()
  273. {
  274. $providers = new refill\bdt\RefillOil([]);
  275. $resp = $providers->add(1000111100021211884, 2, 100, ['order_sn' => '200229600556618886']);
  276. }
  277. public function testGFTDOil()
  278. {
  279. $providers = new refill\gftd\RefillOil([]);
  280. $resp = $providers->add(1000111100020445281, mtopcard\SinopecCard, 100, ['order_sn' => $this->make_sn()]);
  281. }
  282. public function testGFTDCB()
  283. {
  284. $data = '{"channelOrderNumber":"79091610959059372019","orderNumber":"GYFL1610959060397001","message":"充值成功","signature":"881036222bd8f067ff47d248c75f4c8d","voucher":"","status":101}';
  285. $url = "http://192.168.1.220/mobile/refill_gftd.php?" . $data;
  286. $resp = http_post_data($url, $data, ['Content-Type: application/json;charset=UTF-8;','Accept:application/json;charset=UTF-8;']);
  287. }
  288. public function testJiecPhone()
  289. {
  290. $providers = new refill\jiec\RefillPhone([]);
  291. $resp = $providers->add('18500608333', 5, 30, ['order_sn' => $this->make_sn()]);
  292. }
  293. public function testBxtwtCB()
  294. {
  295. $data = '{"order_number":18219726,"shipping_status":4,"shipping_status_desc":"发货失败","shipping_status_message":"","sign":"863b4d972f2a4d39a9af7396879116c4","voucher":"","vouchertype":"","voucherurl":"","tradeNo":"100662475851197741"}';
  296. }
  297. public function testTianjtJDVerify()
  298. {
  299. $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';
  300. $url = "http://192.168.1.220/mobile/refill_tianjt.php?" . $data;
  301. $resp = http_request($url);
  302. }
  303. public function testSuhcPDD()
  304. {
  305. $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';
  306. $url = "https://www.xyzshops.cn/mobile/refill_suhcpdd.php?" . $data;
  307. $resp = http_request($url);
  308. }
  309. public function testSuhcTMVerify()
  310. {
  311. $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';
  312. $url = "https://www.xyzshops.cn/mobile/refill_suhctm.php?" . $data;
  313. $resp = http_request($url);
  314. }
  315. public function testBeixtVerify()
  316. {
  317. $data = '{"order_number":18219726,"shipping_status":4,"shipping_status_desc":"发货失败","shipping_status_message":"","sign":"863b4d972f2a4d39a9af7396879116c4","voucher":"","vouchertype":"","voucherurl":"","tradeNo":"100662475851197741"}';
  318. $url = "https://www.xyzshops.cn/mobile/refill_bxtwt.php";
  319. $headers = ['Content-Type: application/json'];
  320. $resp = http_post_data($url, $data, $headers);
  321. }
  322. public function testInput()
  323. {
  324. $input = fopen("php://input", "rw");
  325. file_put_contents($input, 'xxxx');
  326. $content = file_get_contents('php://input');
  327. }
  328. public function testUrl()
  329. {
  330. $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';
  331. $params = preg_split('/&/', $data);
  332. foreach ($params as $pair) {
  333. $kv = explode('=', $pair);
  334. $count = count($kv);
  335. if ($count === 1) {
  336. $key = $kv[0];
  337. $val = "";
  338. } elseif ($count === 2) {
  339. $key = $kv[0];
  340. $val = $kv[1];
  341. } else {
  342. continue;
  343. }
  344. Log::record("{$key}:{$val}", Log::DEBUG);
  345. }
  346. }
  347. public function testAddoil()
  348. {
  349. $url = $this->mReqHost . "/mobile/index.php";
  350. $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php';
  351. $params = ['mchid' => $this->mMchid,
  352. 'cardno' => '1000111100020445281',
  353. 'amount' => "100",
  354. "act" => "refill",
  355. "op" => "add",
  356. 'order_sn' => $this->make_sn(),
  357. 'notifyurl' => $notifyurl];
  358. $resp = $this->send_md5($url, $params);
  359. Log::record($resp, Log::DEBUG);
  360. }
  361. public function testBalance()
  362. {
  363. $url = $this->mReqHost . "/mobile/index.php";
  364. $params = ['mchid' => 1092,
  365. "act" => "refill",
  366. "op" => "balance"];
  367. $resp = $this->send_md5($url, $params);
  368. Log::record($resp, Log::DEBUG);
  369. }
  370. public function testAddPhoe()
  371. {
  372. $phones = [//13911129867,
  373. 18500608333,
  374. 18510683168,
  375. 18513846008,
  376. 18518237398];
  377. $amount = 10;
  378. for ($i = 0; $i < 3; $i++) {
  379. foreach ($phones as $phone) {
  380. $url = $this->mReqHost . "/mobile/index.php";
  381. $params = ['mchid' => 1092,
  382. 'cardno' => $phone,
  383. 'amount' => $amount,
  384. "act" => "refill",
  385. "op" => "add",
  386. 'order_sn' => $this->make_sn(),
  387. 'notifyurl' => $this->mReqHost . "/mobile/refill_xyz.php"];
  388. $resp = $this->send_md5($url, $params);
  389. Log::record($resp, Log::DEBUG);
  390. }
  391. }
  392. }
  393. public function testProxyHelper()
  394. {
  395. $phone = '13911129867';
  396. $amount = 100;
  397. $url = $this->mReqHost . "/mobile/index.php";
  398. $params = ['mchid' => 1090,
  399. 'cardno' => $phone,
  400. 'amount' => $amount,
  401. "act" => "refill",
  402. "op" => "add",
  403. 'order_sn' => $this->make_sn(),
  404. 'notifyurl' => "https://xxx"];
  405. $proxy = new refill_proxy("xxx");
  406. $resp = $proxy->send($url, $params);
  407. }
  408. public function testGoods()
  409. {
  410. $req_url = $this->mReqHost . '/mobile/index.php';
  411. $params = ['mchid' => $this->mMchid,
  412. "act" => "refill",
  413. "op" => "goods"];
  414. $resp = $this->send_md5($req_url, $params);
  415. }
  416. public function testQueryFactory()
  417. {
  418. refill\RefillFactory::instance()->query(295);
  419. }
  420. public function testQuery()
  421. {
  422. //$req_url = 'https://www.xyzshops.cn/mobile/index.php';
  423. // $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php';
  424. $req_url = BASE_SITE_URL . '/mobile/index.php';
  425. $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php';
  426. $params = ['mchid' => 1,
  427. "act" => "refill",
  428. "op" => "query",
  429. 'order_sn' => "13281476"];
  430. $resp = $this->send_md5($req_url, $params);
  431. }
  432. public function testRemoveSession()
  433. {
  434. $resp = http_request(BASE_SITE_URL . "/mobile/signature.php", [], 'POST');
  435. }
  436. public function testTianjtCB()
  437. {
  438. // $notifyurl = BASE_SITE_URL . "/mobile/refill_tianjt.php";
  439. $notifyurl = "https://www.xyzshops.cn/mobile/refill_tianjt.php";
  440. // $notifyurl = "https%3A%2F%2Fwww.xyzshops.cn%2Fmobile%2Frefill_tianjt.php";
  441. $params = ['onlystr' => '690665858589475818',
  442. 'amt' => 1000,
  443. 'jdno' => '',
  444. 'notifyurl' => $notifyurl,
  445. 'cardtype' => 'Sinoepc',
  446. 'batchid' => 30589,
  447. 'cardno' => '1000113300007993287',
  448. 'orgid' => '1590993600',
  449. 'status' => 3];
  450. $sign = $this->md5_sign($params);
  451. $params['sign'] = $sign;
  452. $resp = http_request($notifyurl, $params, 'POST');
  453. Log::record($resp, Log::DEBUG);
  454. }
  455. public function testBJBCB()
  456. {
  457. $params = [
  458. 'usr' => '13699279618',
  459. 'ord' => '710662733975412771',
  460. 'state' => '2',
  461. 'bz' => '',
  462. 'sgn' => 'AC9AFD254DE682D8440A97CA68B992DA'
  463. ];
  464. $resp = http_request("https://www.xyzshops.cn/mobile/refill_bjb.php", $params, 'POST');
  465. }
  466. public function testJiecCB()
  467. {
  468. $params['result'] = 'fail';
  469. $params['msg'] = '0';
  470. $params['order'] = 'null';
  471. $params['phone_no'] = '18500608333';
  472. $params['amount'] = '30.00';
  473. $params['op_no'] = '800663597981819221';
  474. $params['sign'] = '2510046895e8e12322c8a32547905ee9';
  475. $resp = http_request($this->mReqHost . "/mobile/refill_jiec.php", $params, 'POST');
  476. }
  477. public function testZFKJ()
  478. {
  479. //带签名参数:mchid=1090&act=refill&op=add&cardno=100112121212212133
  480. //&amount=10&order_sn=PH2012261356569433&
  481. //notifyurl=https%3A%2F%2Fqzcz.edusahoo.com.cn%2Findex%2Findex%2Fcallback
  482. //&sign=4a3ac5f9706e64aa70c6cab0fc5839d3
  483. $params = ['mchid' => 1090,
  484. 'cardno' => '100112121212212133',
  485. 'amount' => '10',
  486. "act" => "refill",
  487. "op" => "add",
  488. 'order_sn' => 'PH2012261356569433',
  489. 'notifyurl' => 'https://qzcz.edusahoo.com.cn/index/index/callback'];
  490. $resp = $this->send_md5(BASE_SITE_URL . '/mobile/index.php', $params);
  491. }
  492. protected function check_empty($value)
  493. {
  494. if (!isset($value))
  495. return true;
  496. if ($value === null)
  497. return true;
  498. if (trim($value) === "")
  499. return true;
  500. return false;
  501. }
  502. private function md5_sign($params)
  503. {
  504. ksort($params);
  505. $body = "";
  506. $i = 0;
  507. foreach ($params as $k => $v) {
  508. if (false === $this->check_empty($v) && "@" != substr($v, 0, 1)) {
  509. if ($i == 0) {
  510. $body .= "{$k}" . "=" . urldecode($v);
  511. } else {
  512. $body .= "&" . "{$k}" . "=" . urldecode($v);
  513. }
  514. $i++;
  515. }
  516. }
  517. $body .= "&key=7yDCLS6S2KzSAJQOUc3vsa";
  518. return md5($body);
  519. }
  520. public function testCallMech()
  521. {
  522. $logic = Logic('queue');
  523. $logic->NotifyMerchantComplete(['order_id' => 18171,'manual' => true]);
  524. }
  525. //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testCallMech)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test
  526. private function send($url, $params)
  527. {
  528. $mchid = $params['mchid'];
  529. $pri_key = BASE_DATA_PATH . "/api/merchant/key/{$mchid}_pri.pem";
  530. $key = file_get_contents($pri_key);
  531. $pri = openssl_get_privatekey($key);
  532. $body = $this->body($params);
  533. openssl_sign($body, $signed, $pri);
  534. $sign = base64_encode($signed);
  535. $params['sign'] = $sign;
  536. $resp = http_request($url, $params, 'POST');
  537. Log::record("resp:{$resp}", Log::DEBUG);
  538. }
  539. private function send_md5($url, $params)
  540. {
  541. $body = $this->body($params);
  542. $body .= "&key={$this->mKey}";
  543. $params['sign'] = md5($body);
  544. $resp = http_request($url, $params, 'POST');
  545. Log::record("resp:{$resp}", Log::DEBUG);
  546. return $resp;
  547. }
  548. public function testCardType()
  549. {
  550. $cardno = '1000111100021211884';
  551. $ret = preg_match('/^1[0-9]{18}$/', $cardno, $matches);
  552. }
  553. public function testMtrand()
  554. {
  555. }
  556. public function testHttpRefill()
  557. {
  558. $mchid = '000001';
  559. $pri_key = BASE_DATA_PATH . "/api/merchant/key/{$mchid}_pri.pem";
  560. $key = file_get_contents($pri_key);
  561. $pri = openssl_get_privatekey($key);
  562. $params = ['MCHID' => $mchid, 'cardno' => '1000111100021211884', 'amt' => "100", "act" => "refill", "op" => "addoil"];
  563. $body = $this->body($params);
  564. openssl_sign($body, $signed, $pri);
  565. $sign = base64_encode($signed);
  566. $params['sign'] = $sign;
  567. $resp = http_request(BASE_SITE_URL . "/mobile/index.php", $params, 'POST');
  568. }
  569. private function body($params)
  570. {
  571. ksort($params);
  572. $body = "";
  573. $i = 0;
  574. foreach ($params as $k => $v) {
  575. if (false === $this->checkEmpty($v) && "@" != substr($v, 0, 1)) {
  576. if ($i == 0) {
  577. $body .= "{$k}" . "=" . urlencode($v);
  578. } else {
  579. $body .= "&" . "{$k}" . "=" . urlencode($v);
  580. }
  581. $i++;
  582. }
  583. }
  584. return $body;
  585. }
  586. private function checkEmpty($value)
  587. {
  588. if (!isset($value))
  589. return true;
  590. if ($value === null)
  591. return true;
  592. if (trim($value) === "")
  593. return true;
  594. return false;
  595. }
  596. public function testKsort()
  597. {
  598. $age = ["Peter" => "35", "Ben" => "37", "Joe" => "43"];
  599. ksort($age);
  600. foreach ($age as $x => $x_value) {
  601. echo "Key=" . $x . ", Value=" . $x_value;
  602. echo "<br>";
  603. }
  604. }
  605. public function testip()
  606. {
  607. $model_merchant = Model('merchant');
  608. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => 1]);
  609. $ipwhitelist = unserialize($merchant_info['ip_white_list']);
  610. $res = json_encode($ipwhitelist);
  611. }
  612. //测试向内部店提交订单,可先屏蔽其它充值通道
  613. public function testAddoilToInnerStore()
  614. {
  615. $url = $this->mReqHost . "/mobile/index.php";
  616. $notifyurl = BASE_SITE_URL . '/mobile/signature.php';
  617. $params = ['mchid' => 1,
  618. 'cardno' => '1000111100020445281',
  619. 'amount' => "1000",
  620. "act" => "refill",
  621. "op" => "add",
  622. 'order_sn' => $this->make_sn(),
  623. 'notifyurl' => $notifyurl];
  624. $resp = $this->send_md5($url, $params);
  625. Log::record($resp, Log::DEBUG);
  626. }
  627. public function testRefillInnerCB()
  628. {
  629. $params = ['state_type' => 'order_cancel', 'order_id' => 311, 'channel_name' => 'lx'];
  630. $resp = http_request(BASE_SITE_URL . '/mobile/refill_inner.php', $params, 'POST');
  631. }
  632. public function testArgs()
  633. {
  634. Log::record($_SERVER['argv'], Log::DEBUG);
  635. }
  636. public function testCall()
  637. {
  638. $order_id = 14974;
  639. QueueClient::async_push("NotifyMerchantComplete", ['order_id' => $order_id,'manual' => true], 10);
  640. }
  641. public function testSyncconfig()
  642. {
  643. $name_val_cfg = function ($items) {
  644. $result = [];
  645. foreach ($items as $item) {
  646. $name = $item->name();
  647. $result[$name] = $item;
  648. }
  649. return $result;
  650. };
  651. $name_val_row = function ($items) {
  652. $result = [];
  653. foreach ($items as $item) {
  654. $name = $item['name'];
  655. $result[$name] = $item;
  656. }
  657. return $result;
  658. };
  659. $match = function ($all,$cur)
  660. {
  661. $insert = [];
  662. foreach ($all as $key => $value)
  663. {
  664. if(!array_key_exists($key,$cur)) {
  665. $insert[] = $key;
  666. }
  667. }
  668. return $insert;
  669. };
  670. $inserter = function ($mod,$type,$names)
  671. {
  672. foreach ($names as $name) {
  673. $data = ['name' => $name,'type' => $type];
  674. $mod->insert($data);
  675. }
  676. };
  677. $providers = refill\RefillFactory::instance()->providers();
  678. $oils = $name_val_cfg($providers['oil']);
  679. $phones = $name_val_cfg($providers['phone']);
  680. $mod_prov = Model('refill_provider');
  681. $oil_items = $mod_prov->getProviderList(['type' => 1]);
  682. $oil_items = $name_val_row($oil_items);
  683. $oil_inserts = $match($oils,$oil_items);
  684. $phone_items = $mod_prov->getProviderList(['type' => 2]);
  685. $phone_items = $name_val_row($phone_items);
  686. $phone_inserts = $match($phones,$phone_items);
  687. $inserter($mod_prov,1,$oil_inserts);
  688. $inserter($mod_prov,2,$phone_inserts);
  689. }
  690. public function testStat()
  691. {
  692. $model_refill_order = Model('refill_order');
  693. $stat = Model('')->table('refill_order,vr_order')->join('inner')
  694. ->on('refill_order.order_id=vr_order.order_id')
  695. ->field('sum(refill_amount) as refill_amounts , sum(channel_amount) as channel_amounts , sum(mch_amount) as mch_amounts')
  696. ->where([])->select();
  697. }
  698. public function testRefillGoods()
  699. {
  700. $goods = refill\RefillFactory::instance()->goods();
  701. }
  702. private function make_mobile()
  703. {
  704. $no = "1" . mt_rand(3000000000, 3999999999);
  705. return $no;
  706. }
  707. private function refill_info($card_no, $card_type)
  708. {
  709. $data = rcache($card_no, 'cardrefill-');
  710. if(empty($data))
  711. {
  712. $mod_topcard = Model('topcard');
  713. $ret = $mod_topcard->get_card($card_no);
  714. if(empty($ret)) {
  715. $bind_phone = $this->make_mobile();
  716. $mod_topcard->add($card_no,$card_type,time(),$bind_phone);
  717. $data['bind_phone'] = $bind_phone;
  718. $data['refill_time'] = time();
  719. $data['times'] = 0;
  720. wcache($card_no,$data,'cardrefill-');
  721. }
  722. else {
  723. $val = $ret[0];
  724. $data['bind_phone'] = $val['bind_phone'];
  725. $data['refill_time'] = time();
  726. $data['times'] = 0;
  727. }
  728. }
  729. return $data;
  730. }
  731. public function testGetMobile()
  732. {
  733. $card_no = '1000119000001679247';
  734. $card_type = 1;
  735. $info = $this->refill_info($card_no,$card_type);
  736. }
  737. private function check_mchorder($mchid,$mch_order)
  738. {
  739. if(empty($mch_order)) {
  740. return true;
  741. }
  742. else {
  743. $refill_order = Model('refill_order');
  744. $ret = $refill_order->getOrderInfo(['mchid' => $mchid,'mch_order' => $mch_order]);
  745. return empty($ret);
  746. }
  747. }
  748. public function testCheckMchorder()
  749. {
  750. $ret = $this->check_mchorder(1,'13281475');
  751. }
  752. public function testMakemobile()
  753. {
  754. $mobile = refill\util::make_mobile();
  755. $ret = refill\util::set_black('1000111100020445281');
  756. }
  757. public function testLoadBlack()
  758. {
  759. $path = BASE_DATA_PATH . "/log";
  760. $names = ['20210119-mobile.log',
  761. '20210120-mobile.log','20210121-mobile.log','20210122-mobile.log','20210123-mobile.log',
  762. '20210124-mobile.log','20210125-mobile.log'];
  763. foreach ($names as $name)
  764. {
  765. $file_name = $path . "/" . $name;
  766. refill\util::black_from_log($file_name);
  767. }
  768. }
  769. public function testStats()
  770. {
  771. $date = date('Y-m-d',time());
  772. $today = strtotime("{$date}");
  773. $times_begin = function ($start) {
  774. $times = [];
  775. $begin = $start;
  776. for($i = 0; $i < 7; $i++) {
  777. $times[] = $begin;
  778. $begin -= 86400;
  779. }
  780. return $times;
  781. };
  782. $reader = function ($mchid,$time) {
  783. $cond['mchid'] = $mchid;
  784. $cond['inner_status'] = 0;
  785. $cond['refill_order.order_time'] = ['between', [$time, $time + 86400 -1]];
  786. $items = Model('')->table('refill_order,vr_order')->join('inner')
  787. ->on('refill_order.order_id=vr_order.order_id')
  788. ->field('count(*) as order_count, vr_order.order_state, sum(mch_amount) as mch_amounts')
  789. ->group('vr_order.order_state')
  790. ->where($cond)->select();
  791. return $items;
  792. };
  793. $begins = $times_begin($today);
  794. $mchid = 10096;
  795. // $states = rcache($this->mchid() , 'refillstat-');
  796. $states = unserialize($states ?? "");
  797. if(empty($states)) $states = [];
  798. $result = [];
  799. $cache = [];
  800. foreach ($begins as $begin)
  801. {
  802. if(array_key_exists($begin,$states)) {
  803. $item = $states[$begin];
  804. }
  805. else {
  806. $item = $reader($mchid,$begin);
  807. }
  808. $result[$begin] = $item;
  809. //判断item 中充值中的状态是否为0,为0的情况下放进cache
  810. $cache = $item;
  811. }
  812. wcache($this->mchid() ,$cache, 'refillstat-');
  813. return $result;
  814. }
  815. public function testNotifyx()
  816. {
  817. $mch_cache = rcache("merchant-notify" , 'refill-');
  818. $caches = empty($mch_cache['data']) ? [] : unserialize($mch_cache['data']);
  819. $new_caches = [];
  820. $merchants = Model('merchant')->getMerchantList([],'','','merchant.*,member.available_predeposit' ,"0,1000");
  821. foreach ($merchants as $merchant)
  822. {
  823. $mchid = $merchant['mchid'];
  824. $phone = $merchant['contact_phone'] ?? "";
  825. $available_pd = intval($merchant['available_predeposit']);
  826. $alarm_pd = intval($merchant['alarm_amount']) < 10000 ? 10000 : intval($merchant['alarm_amount']);
  827. if(array_key_exists($mchid,$caches)) {
  828. $mch_cache = $caches[$mchid];
  829. }
  830. else {
  831. $mch_cache = ['last_time' => 0, 'send_count' => 0];
  832. }
  833. if(!empty($phone) && ($available_pd < $alarm_pd))
  834. {
  835. $counts = $mch_cache['send_count'];
  836. if(($mch_cache['last_time'] + 300 < time()) && $counts < 5) {
  837. $mch_cache = ['last_time' => time(), 'send_count' => $counts + 1];
  838. QueueClient::push('sendSMS', ['mobile'=>$merchant['contact_phone'],
  839. 'type'=>'balance_warning','datas' => [date("m月d日H时") , $merchant['available_predeposit']]]);
  840. }
  841. }
  842. else {
  843. $mch_cache = ['last_time' => 0, 'send_count' => 0];
  844. }
  845. $new_caches[$mchid] = $mch_cache;
  846. }
  847. wcache("merchant-notify", ['data' => serialize($new_caches)], 'refill-');
  848. }
  849. public function testReadChannel()
  850. {
  851. refill\RefillFactory::instance()->read_channel();
  852. }
  853. public function testAllow()
  854. {
  855. $allow = refill\RefillFactory::instance()->allow(10096,1,100);
  856. }
  857. public function testCheckData(){
  858. $str = '|2|110667993758599771-充值失败|';
  859. // $str = '0|提交成功|-36557.7400';
  860. // if(preg_match( '/^-*[0-9]{1,3}\|[\x{4e00}-\x{9fa5}]+\|-*[0-9]+\.*[0-9]+$/u',$str,$matches)) {
  861. // return true;
  862. // }
  863. // if(preg_match('/^[0-3]\|[0-9]+-*[\x{4e00}-\x{9fa5}]+\|[0-9]*$/u',$str,$matches)){
  864. // return true;
  865. // }
  866. // return false;
  867. $resp = ltrim($str , '|');
  868. $resp = explode('|' , $resp);
  869. if(count($resp) != 3) {
  870. return [false,'返回值错误'];
  871. }
  872. }
  873. public function testErrre()
  874. {
  875. $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}';
  876. $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);
  877. }
  878. public function testLog()
  879. {
  880. // $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 ]';
  881. $fn = fopen(BASE_ROOT_PATH . "/10096.log","r");
  882. $mod = Model();
  883. $mod->table('tfloat')->where(['member_id' => 65818])->update( ['pdamount'=>0]);
  884. $total_amount = ncPriceFormat(0.00);
  885. $i = 0;
  886. while(! feof($fn)) {
  887. $i++;
  888. $line = trim(fgets($fn));
  889. $ret = preg_match('/[\w\W]+UPDATE[\w\W]+available_predeposit=available_predeposit(?P<oper>[-+]+)(?P<amount>[.\d]+)/i',$line,$matches);
  890. if($ret) {
  891. $oper = $matches['oper'];
  892. $amount = $matches['amount'];
  893. if($oper == '-') {
  894. $total_amount = ncPriceFormat($total_amount) - ncPriceFormat($amount);
  895. // $mod->table('tfloat')->where(['member_id' => 65818])->update( ['pdamount'=>['exp','pdamount-'.$amount]]);
  896. }
  897. else {
  898. $total_amount = ncPriceFormat($total_amount) + ncPriceFormat($amount);
  899. // $mod->table('tfloat')->where(['member_id' => 65818])->update( ['pdamount'=>['exp','pdamount+'.$amount]]);
  900. }
  901. Log::record("index = {$i} {$total_amount} = {$total_amount} {$oper} {$amount}",Log::DEBUG);
  902. }
  903. }
  904. Log::record("total_amount:{$total_amount}",Log::DEBUG);
  905. fclose($fn);
  906. }
  907. }
  908. //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testLoadBlack)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test
  909. //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