TestRefill.php 35 KB

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