TestRefill.php 34 KB

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