TestRefill.php 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433
  1. <?php
  2. use PHPUnit\Framework\TestCase;
  3. define('APP_ID', 'test');
  4. define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
  5. require_once(BASE_ROOT_PATH . '/global.php');
  6. require_once(BASE_CORE_PATH . '/lrlz.php');
  7. require_once(BASE_ROOT_PATH . '/fooder.php');
  8. require_once(BASE_CORE_PATH . '/framework/function/http.php');
  9. require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
  10. require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
  11. const LocalTest = 1;
  12. const NetTest = 2;
  13. const CurrentTest = LocalTest;
  14. class TestRefill extends TestCase
  15. {
  16. private $mReqHost;
  17. private $mKey;
  18. private $mMchid;
  19. public function __construct(?string $name = null, array $data = [], $dataName = '')
  20. {
  21. parent::__construct($name, $data, $dataName);
  22. if (CurrentTest == LocalTest) {
  23. $this->mReqHost = BASE_SITE_URL;
  24. $this->mMchid = 1;
  25. $this->mKey = '1ff02223b771c0414468c8892151c602';
  26. } else {
  27. // $this->mReqHost = 'https://www.xyzshops.cn';
  28. $this->mReqHost = 'http://121.89.196.45';
  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 testMerchantPrice()
  39. {
  40. $price = new refill\merchant_price();
  41. }
  42. public function testCallBack()
  43. {
  44. }
  45. public function testFactory()
  46. {
  47. $providers = refill\RefillFactory::instance();
  48. }
  49. private function make_sn()
  50. {
  51. return mt_rand(1000, 9999)
  52. . sprintf('%010d', time())
  53. . sprintf('%06d', (float)microtime() * 1000000);
  54. }
  55. public function testRandomMobile()
  56. {
  57. $no = "1" . mt_rand(1, 9999999999);
  58. Log::record("phone no={$no}", Log::DEBUG);
  59. }
  60. public function testBJBAddPhone()
  61. {
  62. $providers = new refill\bjb\RefillPhone([]);
  63. for ($i = 3; $i > 0; --$i) {
  64. $resp = $providers->add(13911129867, 4, 10, ['order_sn' => $this->make_sn()]);
  65. $resp = $providers->add(18500608333, 4, 10, ['order_sn' => $this->make_sn()]);
  66. $resp = $providers->add(18510683168, 4, 10, ['order_sn' => $this->make_sn()]);
  67. $resp = $providers->add(18513846008, 4, 10, ['order_sn' => $this->make_sn()]);
  68. $resp = $providers->add(18518237398, 4, 10, ['order_sn' => $this->make_sn()]);
  69. }
  70. }
  71. public function testOilticket()
  72. {
  73. $providers = new refill\bjb\RefillPhone([]);
  74. }
  75. public function testBjbRet()
  76. {
  77. $resp = '0|提交成功|14936.8600';
  78. $resp = explode('|', $resp);
  79. }
  80. public function testIpWhiteList()
  81. {
  82. $x = serialize(['47.99.57.105']);
  83. $ips = unserialize('a:1:{i:0;s:12:"47.99.57.105";}');
  84. if (!empty($ips)) {
  85. $addr = '47.99.57.105';
  86. Log::record("request ip:{$addr}", Log::DEBUG);
  87. if (!in_array($addr, $ips)) {
  88. throw new Exception("请求地址不在白名单中");
  89. }
  90. }
  91. }
  92. public function testBaizePhone()
  93. {
  94. $providers = new refill\baizeyd\RefillPhone([]);
  95. // $resp = $providers->add(17801048874, 5, 10, ['order_sn' => $this->make_sn()]);
  96. $resp = $providers->query(['order_sn' => '930668700375312006']);
  97. // $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';
  98. // $input = $this->parse_request($str);
  99. // $input['amount'] = 10.00;
  100. // $input['orderId'] = '92391614943913061206';
  101. // $input['phone'] = 17801048874;
  102. // $input['payTime'] = '2021-03-05 19:31:55';
  103. // $input['sign'] = 'bef6ae50319fb1e8cb3f21302f0abef8';
  104. // $input['appKey'] = 'uECmTOFAY6RPCTtI';
  105. // $input['payUrl'] = '';
  106. // $input['statusDes'] = '支付失败';
  107. // $input['status'] = 7;
  108. // refill\RefillFactory::instance()->notify('baizeyd',$input);
  109. }
  110. private function parse_request($squery)
  111. {
  112. if (empty($squery)) return [];
  113. $result = [];
  114. $params = preg_split('/&/', $squery);
  115. foreach ($params as $pair) {
  116. if (empty($pair)) continue;
  117. $kv = explode('=', $pair);
  118. $count = count($kv);
  119. if ($count === 1) {
  120. $key = $kv[0];
  121. $val = "";
  122. } elseif ($count === 2) {
  123. $key = $kv[0];
  124. $val = urldecode($kv[1]);
  125. } else {
  126. continue;
  127. }
  128. if (!empty($key)) {
  129. $result[$key] = $val;
  130. }
  131. }
  132. return $result;
  133. }
  134. public function testAmPhone()
  135. {
  136. // $providers = new refill\aming\RefillPhone([]);
  137. // $resp = $providers->add(18500608333, 5, 10, ['order_sn' => $this->make_sn()]);
  138. $input['result'] = 'fail';
  139. $input['msg'] = 0;
  140. $input['order'] = 'null';
  141. $input['phone_no'] = 18500608333;
  142. $input['sign'] = 'c925ad19c63c3eb36ffc52d938e24604';
  143. $input['amount'] = '10.00';
  144. $input['op_no'] = '42601615096072517841';
  145. refill\RefillFactory::instance()->notify('aming', $input);
  146. }
  147. public function testBhcPhone()
  148. {
  149. $providers = new refill\binghc\RefillPhone([]);
  150. $resp = $providers->query(['order_sn' => 250668618955902006]);
  151. // $input['result'] = 'fail';
  152. // $input['msg'] = 0;
  153. // $input['order'] = 'null';
  154. // $input['phone_no'] = 18500608333;
  155. // $input['sign'] = 'c3aa38ee07cd1b69bfd5ead56f6da8d6';
  156. // $input['amount'] = '10.00';
  157. // $input['op_no'] = '24061615096361999002';
  158. // refill\RefillFactory::instance()->notify('binghc',$input);
  159. }
  160. public function testRuishunPhone()
  161. {
  162. // $providers = new refill\ruishun\RefillPhone([]);
  163. // $resp = $providers->add(18500608333, 5, 10, ['order_sn' => $this->make_sn()]);
  164. $input['result'] = 'fail';
  165. $input['msg'] = 0;
  166. $input['order'] = null;
  167. $input['phone_no'] = 18500608333;
  168. $input['sign'] = 'e234f7d1c0458ca236f53a0008436b46';
  169. $input['amount'] = "10.00";
  170. $input['op_no'] = '76361615095403188513';
  171. refill\RefillFactory::instance()->notify('ruishun', $input);
  172. }
  173. public function testWuchenPhone()
  174. {
  175. $providers = new refill\wuchen\RefillPhone([]);
  176. // $resp = $providers->add('13699279618', 5, 30, ['order_sn' => $this->make_sn()]);
  177. $resp = $providers->query(['order_sn' => '790668630498425006']);
  178. // $input['app_id'] = '70016';
  179. // $input['message'] = 'fail';
  180. // $input['order_sn'] = '43101615277293035501';
  181. // $input['platform_order_id'] = '';
  182. // $input['sign'] = '5ea59f8ac51a518f2c622824d7db2a04';
  183. // $input['state'] = "fail";
  184. // $input['sys_sn'] = '202103091608231836913889';
  185. // $input['timestamp'] = '1615277361';
  186. // refill\RefillFactory::instance()->notify('wuchen',$input);
  187. }
  188. public function testYibaoPhone()
  189. {
  190. $providers = new refill\yibao\RefillPhone([]);
  191. // $resp = $providers->add('13699279618', 5, 30, ['order_sn' => $this->make_sn()]);
  192. $resp = $providers->query(['ch_trade_no' => '31215002972142736']);
  193. // $str = '{"amount":"30","carrierOrderNo":null,"mobile":"13699279618","orderNo":"27961615532426088043","orderStatus":3,"sign":"012BA0B093A0473D7DD1634A8356DCB1","tradeNo":"31215002972142736"}';
  194. // $data = json_decode($str,true);
  195. // refill\RefillFactory::instance()->notify('yibao',$data);
  196. }
  197. public function testAmingydPhone()
  198. {
  199. $providers = new refill\amingyd\RefillPhone([]);
  200. // $resp = $providers->add('13699279618', 5, 30, ['order_sn' => $this->make_sn()]);
  201. $resp = $providers->query(['order_sn' => '15421615627436792938']);
  202. // $str = '{"orderId":"15421615627436792938","amount":3000,"appKey":"40695059","timestamp":1615627503,"status":3,"operatorId":"508353854027968617","sign":"2A0562319ED4845AB9E3812A58F0B425"}';
  203. // $data = json_decode($str,true);
  204. // refill\RefillFactory::instance()->notify('amingyd',$data);
  205. }
  206. public function testChukaPhone()
  207. {
  208. $providers = new refill\chuka\RefillPhone([]);
  209. // $resp = $providers->add('18500608333', 5, 20, ['order_sn' => $this->make_sn()]);
  210. // $resp = $providers->query(['order_sn' => '92161616314884175179']);
  211. $params['customerId'] = '101787';
  212. $params['orderno'] = 'C1616314888506705492';
  213. $params['tmporder'] = '92161616314884175179';
  214. $params['code'] = '1';
  215. $params['number'] = '18500608333';
  216. $params['money'] = '20';
  217. $params['amount'] = '0';
  218. refill\RefillFactory::instance()->notify('chuka', $params);
  219. }
  220. public function testLegouPhone()
  221. {
  222. $providers = new refill\legou\RefillPhone([]);
  223. // $resp = $providers->add('18500608333', 5, 30, ['order_sn' => '200649600557718881' , 'order_id' => 247 , 'buyer_id' => 52667]);
  224. $resp = $providers->query(['order_sn' => '200649600557718881', 'order_id' => 247]);
  225. $params['username'] = 'lzdc';
  226. $params['orderNumber'] = '690653407667699667';
  227. $params['cardNumber'] = '18500608333';
  228. $params['orderMoney'] = '30.0';
  229. $params['orderPay'] = '1.0';
  230. $params['resultCode'] = '2';
  231. $params['rechargeDesc'] = '{"rechargeStatus":600200,"rechargeDesc":"充值成功"}';
  232. $params['rechargeVoucher'] = '100407307092103291444050244599';
  233. $params['sign'] = 'c054884422a8c3749cbfda0e82b9af70';
  234. // refill\RefillFactory::instance()->notify('legou',$params);
  235. }
  236. public function testFeiniaoPhone()
  237. {
  238. $providers = new refill\feiniao\RefillPhone([]);
  239. // $order_sn = $this->make_sn();
  240. // Log::record($order_sn, Log::DEBUG);
  241. // $resp = $providers->add('13699279618', 4, 50, ['order_sn' => $order_sn]);
  242. $resp = $providers->query(['order_sn' => '28641617178590981824']);
  243. $params['result'] = 'fail';
  244. $params['msg'] = '0';
  245. $params['order'] = 'null';
  246. $params['phone_no'] = '18500608333';
  247. $params['amount'] = '100.00';
  248. $params['op_no'] = '64591617090761169983';
  249. $params['settle'] = '0';
  250. $params['sign'] = '907d2640f96e8d78d59202d090ddb470';
  251. // refill\RefillFactory::instance()->notify('feiniao',$params);
  252. }
  253. public function testTongyPhone()
  254. {
  255. $providers = new refill\tongy\RefillPhone([]);
  256. $resp = $providers->add('18500608333', 5, 30, ['order_sn' => '690653407667699667', 'order_id' => 248, 'buyer_id' => 52667]);
  257. }
  258. public function testWeiyiPhone()
  259. {
  260. $providers = new refill\weiyi\RefillPhone([]);
  261. // $resp = $providers->add(18500608333, 5, 100, ['order_sn' => $this->make_sn()]);
  262. // $resp = $providers->query(['order_sn' => '59031616396534854303']);
  263. // $body = '{"userid":"8177b4b1d0254c0699bc","ordernum":"59031616396534854303","mobile":"18500608333","timestamp":"20210322150437","state":"3","desc":"%E5%A4%B1%E8%B4%A5%3A%E5%A4%B1%E8%B4%A5","sign":"1d412f956c041bf4454357b209c93df6"}';
  264. // $params = json_decode($body , true);
  265. // refill\RefillFactory::instance()->notify('weiyi',$params);
  266. }
  267. public function testTongluPhone()
  268. {
  269. $providers = new refill\tonglu\RefillPhone([]);
  270. // $resp = $providers->add(18500608333, 5, 50, ['order_sn' => $this->make_sn()]);
  271. $resp = $providers->query(['order_sn' => '22961616468561936356']);
  272. // $body = '{"order_no":"22961616468561936356","order_status":"5","phone_no":"18500608333","amount":5000,"time_paid":1616468856287,"order_cert_no":"","paid":false,"order_id":"20210323966497008"}';
  273. // $sign = '9E41F52F612D60EBB654B3A5D1E2F1E5';
  274. // $params = json_decode($body , true);
  275. // $params['sign'] = $sign;
  276. // refill\RefillFactory::instance()->notify('tonglu',$params);
  277. }
  278. public function testAmingjd()
  279. {
  280. // $providers = new refill\amingjd\RefillPhone([]);
  281. // $resp = $providers->add(13699279618, 5, 30, ['order_sn' => $this->make_sn()]);
  282. // $resp = $providers->query(['order_sn' => '42301616475989518588']);
  283. $body = '{"order_id":"83321616478215494884","mchid":"10003","tel":"13699279618","price":"30.00","sign":"01c49620c155a80bc43cecc2b1651868","status":"0","out_order_id":"0"}';
  284. $params = json_decode($body, true);
  285. refill\RefillFactory::instance()->notify('amingjd', $params);
  286. }
  287. public function testPrice()
  288. {
  289. $amounts = [10, 20, 30, 50, 100, 200, 300, 500];
  290. $rate = 0.94;
  291. foreach ($amounts as $amount) {
  292. $price[] = $amount * $rate;
  293. }
  294. }
  295. public function testWeisPhone()
  296. {
  297. $providers = new refill\weisyd\RefillPhone([]);
  298. $resp = $providers->add(17801048874, 4, 10, ['order_sn' => $this->make_sn()]);
  299. }
  300. public function testXcPhone()
  301. {
  302. $providers = new refill\xc\RefillPhone([]);
  303. $resp = $providers->add(13699279618, 5, 100, ['order_sn' => $this->make_sn()]);
  304. // $resp = $providers->query(['order_sn' => '87961616926444043617']);
  305. $params['pay_orderid'] = '87961616926444043617';
  306. $params['pay_iphone'] = '18500608333';
  307. $params['pay_money'] = '100';
  308. $params['wt_orderid'] = '202103281816121070';
  309. $params['status'] = '1';
  310. $params['sign'] = 'f7be2e859a5a6dc7b1a8273361617752';
  311. // refill\RefillFactory::instance()->notify('xc',$params);
  312. }
  313. public function testAfandPhone()
  314. {
  315. $providers = new refill\afand\RefillPhone([]);
  316. // for ($i = 3; $i > 0; --$i) {
  317. $resp = $providers->query(['order_sn' => '540668612768904780']);
  318. // }
  319. }
  320. public function testAfandengPhone()
  321. {
  322. $providers = new refill\afandeng\RefillPhone([]);
  323. // for ($i = 5; $i > 0; --$i) {
  324. $resp = $providers->add(13699279618, 4, 50, ['order_sn' => $this->make_sn()]);
  325. // }
  326. // $resp = $providers->query(['order_sn' => '20941616115610023539']);
  327. // $params['usr'] = 'afandeng';
  328. // $params['ord'] = '20941616115610023539';
  329. // $params['state'] = '2';
  330. // $params['bz'] = '';
  331. // $params['sgn'] = 'BA2C9D379C3EB648A0B7AAB3A21A3F6A';
  332. // refill\RefillFactory::instance()->notify('afandeng',$params);
  333. }
  334. public function testWantongPhone()
  335. {
  336. $providers = new refill\wantong\RefillPhone([]);
  337. // $resp = $providers->add(13699279618, 4, 30, ['order_sn' => $this->make_sn()]);
  338. // $resp = $providers->add(18500608333, 5, 30, ['order_sn' => $this->make_sn()]);
  339. $resp = $providers->query(['order_sn' => '26061618988575301841']);
  340. $data = '{"uid":"97396885","order_no":"26061618988575301841","mobile_order_no":"","phone_number":"13699279618","face_value":"3000","status":"9","sign":"1a019202656cf4feffe715025fab01bf"}';
  341. $input = json_decode($data, true);
  342. // refill\RefillFactory::instance()->notify('wantong',$input);
  343. }
  344. public function testXunyinPhone()
  345. {
  346. $providers = new refill\xunyin\RefillPhone([]);
  347. // $resp = $providers->add(17703711950, 6, 30, ['order_sn' => $this->make_sn()]);
  348. $resp = $providers->query(['order_sn' => '76831617176125893158']);
  349. $xml = '<Order><cpid>8417</cpid><orderid>40591617173295524057</orderid><order_no>14784226</order_no><msg>充值中</msg><Code>0000</Code><Cards/></Order>';
  350. $resp = $providers->xmlToArray($xml);
  351. if ($resp['Code'] === '0000') {
  352. return [true, $resp['order_no'], false];
  353. } else {
  354. return [false, $resp['msg'], false];
  355. }
  356. // $params['ext'] = '';
  357. // $params['code'] = '8888';
  358. // $params['sign'] = '428ac223cf3a1f6f3d382aac754e8e17';
  359. // $params['statemes'] = '成功';
  360. // $params['id'] = '76831617176125893158';
  361. // $params['userid'] = '8417';
  362. // $params['operatorid'] = '1000000083421033115583773201';
  363. // $params['status'] = 'SUCCESS';
  364. // refill\RefillFactory::instance()->notify('xunyin',$params);
  365. }
  366. public function testFenshengPhone()
  367. {
  368. $providers = new refill\fensheng\RefillPhone([]);
  369. // $resp = $providers->add(13699279618, 4, 30, ['order_sn' => $this->make_sn()]);
  370. $resp = $providers->query(['order_sn' => '27511617764278021035']);
  371. // $datas = '[{"orderNo":"F2104071058069438461","status":"001","consumerNo":"27511617764278021035","voucherNo":"510490688023364042","mobile":"13699279618"}]';
  372. // $datas = json_decode($datas,true);
  373. // foreach ($datas as $data) {
  374. // refill\RefillFactory::instance()->notify('fensheng',$data);
  375. // }
  376. }
  377. public function testRiyingPhone()
  378. {
  379. $providers = new refill\riying\RefillPhone([]);
  380. // $resp = $providers->add(13699279618, 4, 30, ['order_sn' => $this->make_sn()]);
  381. $resp = $providers->query(['ch_trade_no' => '2021041311120213187423105022']);
  382. $data = '{"UserId":"10050","SysOrderId":"2021041311120213187423105022","OrderId":"15641618283518423567","State":"4","Timestamp":"1618283565746","VoucherType":"1","VoucherContent":"511009928000087852","Sign":"a6ec70a3ea42baae941528398c6d0a43"}';
  383. $input = json_decode($data, true);
  384. // refill\RefillFactory::instance()->notify('riying',$input);
  385. }
  386. public function testWeishengyPhone()
  387. {
  388. $providers = new refill\weishengy\RefillPhone([]);
  389. // $resp = $providers->add(18500608333, 5, 30, ['order_sn' => $this->make_sn()]);
  390. // $resp = $providers->query(['order_sn' => '15551618590601301527']);
  391. $data = '{"masId":"699270071532654592","oids":"158877719094,166090529155,158887187476","orderNo":"62411618635377880788","orderPrice":"150.00","phone":"18500608333","sign":"3EC10A32FC4CCC976048E1164D0FCBF6","status":"1","time":"1618643281063","type":"2"}';
  392. $input = json_decode($data, true);
  393. refill\RefillFactory::instance()->notify('weishengy',$input);
  394. }
  395. public function testWailingPhone()
  396. {
  397. $providers = new refill\wailing\RefillPhone([]);
  398. // $resp = $providers->add(13699279618, 4, 30, ['order_sn' => $this->make_sn()]);
  399. $resp = $providers->query(['order_sn' => '73241618543784045618']);
  400. $data = '{"order_id":"73241618543784045618","mchid":"10045","tel":"13699279618","price":"30.00","sign":"4991de3e40f14c198b8c194455ea021b","status":"0","out_order_id":"0"}';
  401. $input = json_decode($data, true);
  402. // refill\RefillFactory::instance()->notify('wailing',$input);
  403. }
  404. public function testShengyingPhone()
  405. {
  406. $providers = new refill\shengying\RefillPhone([]);
  407. // $resp = $providers->add(13699279618, 4, 30, ['order_sn' => $this->make_sn()]);
  408. $resp = $providers->query(['order_sn' => '37571618805115582483']);
  409. $data = '{"TaskID":"129636","Mobile":"13699279618","Status":"4","ReportTime":"2021-04-19T12:06:16.050","ReportCode":"1:511531522026586295","OutTradeNo":"37571618805115582483","ReceiptNum":"511531522026586295","Sign":"a7f46a988bc8483091d94130804e5078"}';
  410. $input = json_decode($data, true);
  411. // refill\RefillFactory::instance()->notify('shengying',$input);
  412. }
  413. public function testYunlingPhone()
  414. {
  415. $providers = new refill\yunling\RefillPhone([]);
  416. $resp = $providers->add(13699279618, 4, 50, ['order_sn' => $this->make_sn()]);
  417. // $resp = $providers->query(['order_sn' => '40241617777847227476']);
  418. // $data = '{"userid":"10073505","sporderid":"7761230671186470456129","orderid":"8BE7B813A399AD2173505","resultno":"1","merchantsubmittime":"20210408084145","ordermoney":"28.68","verifystring":"28711bba302fadf95387b1d863d47a98","sign":"2e49e034ead64880f4fd605e378dd42b","supnumber":"510568880044465061"}';
  419. // $input = json_decode($data, true);
  420. // refill\RefillFactory::instance()->notify('yunling',$input);
  421. }
  422. public function testZhongstPhone()
  423. {
  424. $providers = new refill\zhongst\RefillPhone([]);
  425. // $resp = $providers->add(18500608333, 5, 30, ['order_sn' => $this->make_sn()]);
  426. // $resp = $providers->query(['order_sn' => '48941618981770389271']);
  427. $data = ' {"szOrderId":"66571619060147539784","fSalePrice":"46.5","szAgentId":"200030","nFlag":"2","szVerifyString":"c1e88701b89a4887996822d708bed5f5","szPhoneNum":"13699279618","szRtnMsg":"161122673971","nDemo":"50"}';
  428. $input = json_decode($data, true);
  429. refill\RefillFactory::instance()->notify('zhongst',$input);
  430. }
  431. public function testLuqianPhone()
  432. {
  433. $providers = new refill\luqian\RefillPhone([]);
  434. // $resp = $providers->add(18500608333, 5, 100, ['order_sn' => $this->make_sn()]);
  435. $resp = $providers->query(['order_sn' => '2829660672500596314764']);
  436. $data = '{"amount":"100","charge_type":"0","code":"1","partner_id":"38","phone":"18500608333","sign":"c2c86cccc73fa991a63c369e683c91f2","partner_order_no":"34101618897099329575","official_order_id":"110103308072104201338340278420"}';
  437. $input = json_decode($data, true);
  438. // refill\RefillFactory::instance()->notify('luqian',$input);
  439. }
  440. public function testAfandfsPhone()
  441. {
  442. $providers = new refill\afandfs\RefillPhone([]);
  443. // $resp = $providers->add(15139608757, 4, 30, ['order_sn' => $this->make_sn()]);
  444. $resp = $providers->query(['order_sn' => '65101618975926761630']);
  445. $data = '{"amount":"30","charge_type":"2","code":"1","partner_id":"52","phone":"15139608757","sign":"a7f54c1ac3e1af72f9fc849086cc4bec","partner_order_no":"65101618975926761630","official_order_id":"20210421113256628350"}';
  446. $input = json_decode($data, true);
  447. // refill\RefillFactory::instance()->notify('afandfs',$input);
  448. }
  449. public function testYunlingfsPhone()
  450. {
  451. $providers = new refill\yunlingfs\RefillPhone([]);
  452. // $resp = $providers->add(15139608757, 4, 30, ['order_sn' => $this->make_sn()]);
  453. $resp = $providers->query(['order_sn' => '89451618975609262234']);
  454. $data = '{"userid":"10073527","sporderid":"89451618975609262234","orderid":"02D8A7D2ADD7F4DC73527","resultno":"1","merchantsubmittime":"20210421112737","ordermoney":"28.68","verifystring":"95e3fe834a25cc8c524e09480354d9ba","sign":"b4fb11138a9f883749be320772965add","supnumber":"20210421112716840298"}';
  455. $input = json_decode($data, true);
  456. // refill\RefillFactory::instance()->notify('yunlingfs',$input);
  457. }
  458. public function testLingzhPhone()
  459. {
  460. $providers = new refill\lingzh\RefillPhone([]);
  461. // $resp = $providers->add(18500608333, 5, 10, ['order_sn' => $this->make_sn()]);
  462. // $resp = $providers->query(['order_sn' => '59911615124025101286']);
  463. $resp = $providers->balance();
  464. // $input['usr'] = 1;
  465. // $input['ord'] = '52741615119546453690';
  466. // $input['bz'] = '';
  467. // $input['state'] = 2;
  468. // $input['sgn'] = 'FFCBB75C307154DD306F4EC75BB69A6D';
  469. // refill\RefillFactory::instance()->notify('lingzh',$input);
  470. }
  471. public function testAfandnewPhone()
  472. {
  473. $providers = new refill\afandnew\RefillPhone([]);
  474. // $resp = $providers->add(18500608333, 5, 100, ['order_sn' => $this->make_sn()]);
  475. // $resp = $providers->query(['order_sn' => '45371617101073876975', 'ch_trade_no' => '33018443659736309']);
  476. $params = '{"amount":"100","carrierOrderNo":null,"mobile":"18500608333","orderNo":"45371617101073876975","orderStatus":3,"sign":"8DE392AD6B4730AD9EE0FC2B95BBDF17","tradeNo":"33018443659736309"}';
  477. $input = json_decode($params, true);
  478. refill\RefillFactory::instance()->notify('afandnew', $input);
  479. }
  480. public function testYifaPhone()
  481. {
  482. $providers = new refill\yifa\RefillPhone([]);
  483. $resp = $providers->add(15120035568, 5, 50, ['order_sn' => $this->make_sn()]);
  484. }
  485. public function testTianjtOil()
  486. {
  487. $cardno = 1000111100021211884;
  488. $providers = new refill\tianjt\RefillOil([]);
  489. $resp = $providers->add($cardno, 2, 500, ['order_sn' => $this->make_sn()]);
  490. }
  491. public function testWeitPhone()
  492. {
  493. $providers = new refill\weit\RefillPhone([]);
  494. for ($i = 0; $i <= 10; $i++) {
  495. $resp = $providers->add(18500608333, 5, 10, ['order_sn' => $this->make_sn()]);
  496. }
  497. }
  498. public function testWeitCB()
  499. {
  500. $params['sign'] = 'af820c33472f4b571fa0c48483dfb975';
  501. $params['status'] = 0;
  502. $params['price'] = 30;
  503. $params['op_order_id'] = '';
  504. $params['mch_order_id'] = '900664281823957221';
  505. $params['pt_order_id'] = '2021011802434412825405218901';
  506. $params['pay_type'] = '';
  507. $params['tel'] = 18500608333;
  508. $params['mchid'] = 10014;
  509. $resp = http_request($this->mReqHost . "/mobile/refill_weit.php", $params, 'POST');
  510. }
  511. public function testYifaCB()
  512. {
  513. $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"}';
  514. $input = json_decode($body, true);
  515. refill\RefillFactory::instance()->notify('yifa', $input);
  516. }
  517. public function testBjbQuery()
  518. {
  519. $providers = new refill\bjb\RefillPhone([]);
  520. $refill_info = ['order_sn' => 110667993758599771, 'ch_trade_no' => 499, 'card_no' => 1000111200005252927];
  521. $resp = $providers->query($refill_info);
  522. }
  523. public function testXcQuery()
  524. {
  525. $providers = new refill\xc\RefillPhone([]);
  526. $refill_info = ['order_sn' => 950663423236726632, 'ch_trade_no' => 499, 'card_no' => 1000111200005252927];
  527. $resp = $providers->query($refill_info);
  528. }
  529. public function testTianjtQuery()
  530. {
  531. $providers = new refill\tianjt\RefillOil([]);
  532. $refill_info = ['order_sn' => 680665862267622221, 'ch_trade_no' => 499, 'card_no' => 1000111200005252927];
  533. $resp = $providers->query($refill_info);
  534. }
  535. public function testSaihuOil()
  536. {
  537. $providers = new refill\saihu\RefillOil([]);
  538. $resp = $providers->add(1000111100021211884, 2, 100, ['order_sn' => $this->make_sn()]);
  539. }
  540. public function testBdtOil()
  541. {
  542. $providers = new refill\bdt\RefillOil([]);
  543. $resp = $providers->add(1000111100021211884, 2, 100, ['order_sn' => '200229600556618886']);
  544. }
  545. public function testGFTDOil()
  546. {
  547. $providers = new refill\gftd\RefillOil([]);
  548. $resp = $providers->add(1000111100020445281, mtopcard\SinopecCard, 100, ['order_sn' => $this->make_sn()]);
  549. }
  550. public function testGFTDCB()
  551. {
  552. $data = '{"channelOrderNumber":"79091610959059372019","orderNumber":"GYFL1610959060397001","message":"充值成功","signature":"881036222bd8f067ff47d248c75f4c8d","voucher":"","status":101}';
  553. $url = "http://192.168.1.220/mobile/refill_gftd.php?" . $data;
  554. $resp = http_post_data($url, $data, ['Content-Type: application/json;charset=UTF-8;', 'Accept:application/json;charset=UTF-8;']);
  555. }
  556. public function testJiecPhone()
  557. {
  558. $providers = new refill\jiec\RefillPhone([]);
  559. $resp = $providers->add('18500608333', 5, 30, ['order_sn' => $this->make_sn()]);
  560. }
  561. public function testBxtwtCB()
  562. {
  563. $data = '{"order_number":18219726,"shipping_status":4,"shipping_status_desc":"发货失败","shipping_status_message":"","sign":"863b4d972f2a4d39a9af7396879116c4","voucher":"","vouchertype":"","voucherurl":"","tradeNo":"100662475851197741"}';
  564. }
  565. public function testTianjtJDVerify()
  566. {
  567. $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';
  568. $url = "http://192.168.1.220/mobile/refill_tianjt.php?" . $data;
  569. $resp = http_request($url);
  570. }
  571. public function testSuhcPDD()
  572. {
  573. $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';
  574. $url = "https://www.xyzshops.cn/mobile/refill_suhcpdd.php?" . $data;
  575. $resp = http_request($url);
  576. }
  577. public function testSuhcTMVerify()
  578. {
  579. $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';
  580. $url = "https://www.xyzshops.cn/mobile/refill_suhctm.php?" . $data;
  581. $resp = http_request($url);
  582. }
  583. public function testBeixtVerify()
  584. {
  585. $data = '{"order_number":18219726,"shipping_status":4,"shipping_status_desc":"发货失败","shipping_status_message":"","sign":"863b4d972f2a4d39a9af7396879116c4","voucher":"","vouchertype":"","voucherurl":"","tradeNo":"100662475851197741"}';
  586. $url = "https://www.xyzshops.cn/mobile/refill_bxtwt.php";
  587. $headers = ['Content-Type: application/json'];
  588. $resp = http_post_data($url, $data, $headers);
  589. }
  590. public function testInput()
  591. {
  592. $input = fopen("php://input", "rw");
  593. file_put_contents($input, 'xxxx');
  594. $content = file_get_contents('php://input');
  595. }
  596. public function testUrl()
  597. {
  598. $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';
  599. $params = preg_split('/&/', $data);
  600. foreach ($params as $pair) {
  601. $kv = explode('=', $pair);
  602. $count = count($kv);
  603. if ($count === 1) {
  604. $key = $kv[0];
  605. $val = "";
  606. } elseif ($count === 2) {
  607. $key = $kv[0];
  608. $val = $kv[1];
  609. } else {
  610. continue;
  611. }
  612. Log::record("{$key}:{$val}", Log::DEBUG);
  613. }
  614. }
  615. public function testAddoil()
  616. {
  617. $url = $this->mReqHost . "/mobile/index.php";
  618. $notifyurl = 'http://121.89.196.45/mobile/signature.php';
  619. $params = ['mchid' => $this->mMchid,
  620. 'cardno' => '1000111100020445281',
  621. 'amount' => "100",
  622. "act" => "refill",
  623. "op" => "add",
  624. 'order_sn' => $this->make_sn(),
  625. 'notifyurl' => $notifyurl];
  626. $resp = $this->send_md5($url, $params);
  627. Log::record($resp, Log::DEBUG);
  628. }
  629. public function testBalance()
  630. {
  631. $url = $this->mReqHost . "/mobile/index.php";
  632. $params = ['mchid' => 1092,
  633. "act" => "refill",
  634. "op" => "balance"];
  635. $resp = $this->send_md5($url, $params);
  636. Log::record($resp, Log::DEBUG);
  637. }
  638. public function testAddPhoe()
  639. {
  640. $phones = [//13911129867,
  641. 18500608333,
  642. 18510683168,
  643. 18513846008,
  644. 18518237398];
  645. $amount = 10;
  646. for ($i = 0; $i < 3; $i++) {
  647. foreach ($phones as $phone) {
  648. $url = $this->mReqHost . "/mobile/index.php";
  649. $params = ['mchid' => 1092,
  650. 'cardno' => $phone,
  651. 'amount' => $amount,
  652. "act" => "refill",
  653. "op" => "add",
  654. 'order_sn' => $this->make_sn(),
  655. 'notifyurl' => $this->mReqHost . "/mobile/refill_xyz.php"];
  656. $resp = $this->send_md5($url, $params);
  657. Log::record($resp, Log::DEBUG);
  658. }
  659. }
  660. }
  661. public function testProxyHelper()
  662. {
  663. $phone = '13911129867';
  664. $amount = 100;
  665. $url = $this->mReqHost . "/mobile/index.php";
  666. $params = ['mchid' => 1090,
  667. 'cardno' => $phone,
  668. 'amount' => $amount,
  669. "act" => "refill",
  670. "op" => "add",
  671. 'order_sn' => $this->make_sn(),
  672. 'notifyurl' => "https://xxx"];
  673. $proxy = new refill_proxy("xxx");
  674. $resp = $proxy->send($url, $params);
  675. }
  676. public function testGoods()
  677. {
  678. $req_url = $this->mReqHost . '/mobile/index.php';
  679. $params = ['mchid' => $this->mMchid,
  680. "act" => "refill",
  681. "op" => "goods"];
  682. $resp = $this->send_md5($req_url, $params);
  683. }
  684. public function testQueryFactory()
  685. {
  686. refill\RefillFactory::instance()->query(295);
  687. }
  688. public function testQuery()
  689. {
  690. //$req_url = 'https://www.xyzshops.cn/mobile/index.php';
  691. // $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php';
  692. $req_url = BASE_SITE_URL . '/mobile/index.php';
  693. $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php';
  694. $params = ['mchid' => 1,
  695. "act" => "refill",
  696. "op" => "query",
  697. 'order_sn' => "13281476"];
  698. $resp = $this->send_md5($req_url, $params);
  699. }
  700. public function testRemoveSession()
  701. {
  702. $resp = http_request(BASE_SITE_URL . "/mobile/signature.php", [], 'POST');
  703. }
  704. public function testTianjtCB()
  705. {
  706. // $notifyurl = BASE_SITE_URL . "/mobile/refill_tianjt.php";
  707. $notifyurl = "https://www.xyzshops.cn/mobile/refill_tianjt.php";
  708. // $notifyurl = "https%3A%2F%2Fwww.xyzshops.cn%2Fmobile%2Frefill_tianjt.php";
  709. $params = ['onlystr' => '690665858589475818',
  710. 'amt' => 1000,
  711. 'jdno' => '',
  712. 'notifyurl' => $notifyurl,
  713. 'cardtype' => 'Sinoepc',
  714. 'batchid' => 30589,
  715. 'cardno' => '1000113300007993287',
  716. 'orgid' => '1590993600',
  717. 'status' => 3];
  718. $sign = $this->md5_sign($params);
  719. $params['sign'] = $sign;
  720. $resp = http_request($notifyurl, $params, 'POST');
  721. Log::record($resp, Log::DEBUG);
  722. }
  723. public function testBJBCB()
  724. {
  725. $params = [
  726. 'usr' => '13699279618',
  727. 'ord' => '710662733975412771',
  728. 'state' => '2',
  729. 'bz' => '',
  730. 'sgn' => 'AC9AFD254DE682D8440A97CA68B992DA'
  731. ];
  732. $resp = http_request("https://www.xyzshops.cn/mobile/refill_bjb.php", $params, 'POST');
  733. }
  734. public function testJiecCB()
  735. {
  736. $params['result'] = 'fail';
  737. $params['msg'] = '0';
  738. $params['order'] = 'null';
  739. $params['phone_no'] = '18500608333';
  740. $params['amount'] = '30.00';
  741. $params['op_no'] = '800663597981819221';
  742. $params['sign'] = '2510046895e8e12322c8a32547905ee9';
  743. $resp = http_request($this->mReqHost . "/mobile/refill_jiec.php", $params, 'POST');
  744. }
  745. public function testZFKJ()
  746. {
  747. //带签名参数:mchid=1090&act=refill&op=add&cardno=100112121212212133
  748. //&amount=10&order_sn=PH2012261356569433&
  749. //notifyurl=https%3A%2F%2Fqzcz.edusahoo.com.cn%2Findex%2Findex%2Fcallback
  750. //&sign=4a3ac5f9706e64aa70c6cab0fc5839d3
  751. $params = ['mchid' => 1090,
  752. 'cardno' => '100112121212212133',
  753. 'amount' => '10',
  754. "act" => "refill",
  755. "op" => "add",
  756. 'order_sn' => 'PH2012261356569433',
  757. 'notifyurl' => 'https://qzcz.edusahoo.com.cn/index/index/callback'];
  758. $resp = $this->send_md5(BASE_SITE_URL . '/mobile/index.php', $params);
  759. }
  760. protected function check_empty($value)
  761. {
  762. if (!isset($value))
  763. return true;
  764. if ($value === null)
  765. return true;
  766. if (trim($value) === "")
  767. return true;
  768. return false;
  769. }
  770. public function testcreateSign()
  771. {
  772. $params['act'] = 'refill';
  773. $params['amount'] = '100';
  774. $params['cardno'] = '1000111200006005872';
  775. $params['mchid'] = '1092';
  776. $params['notifyurl'] = 'http://202.85.213.156:8080//YeZiYKCallBackOrderServlet';
  777. $params['op'] = 'balance';
  778. $params['order_sn'] = 'jftest0000123';
  779. $sign = $this->md5_sign($params);
  780. }
  781. public function testCheckphone()
  782. {
  783. $check = function ($phone) {
  784. $url = 'https://mobileempty.shumaidata.com/mobileempty';
  785. $params['mobile'] = $phone;
  786. $headers = array();
  787. array_push($headers, "Authorization:APPCODE " . '8f92d951293f4d2ea48ff86d5a70c537');
  788. $resp = http_request($url, $params, 'GET', false, $headers);
  789. $resp = json_decode($resp, true);
  790. if ($resp['success'] == true && $resp['code'] == 200) {
  791. Log::record("data phone:{$phone} , status : {$resp['data']['status']}", Log::DEBUG);
  792. if (in_array($resp['data']['status'], [0, 3, 4, 5])) {
  793. return false;
  794. }
  795. } else {
  796. Log::record("data phone:{$phone} , 不支持的号段", Log::DEBUG);
  797. }
  798. };
  799. $check(17801048874);
  800. }
  801. public function testCtSign()
  802. {
  803. $params['act'] = 'refill';
  804. $params['mchid'] = 12345;
  805. $params['op'] = 'goods';
  806. $sign = $this->md5_sign($params);
  807. }
  808. private function md5_sign($params)
  809. {
  810. ksort($params);
  811. $body = "";
  812. $i = 0;
  813. foreach ($params as $k => $v) {
  814. if (false === $this->check_empty($v) && "@" != substr($v, 0, 1)) {
  815. if ($i == 0) {
  816. $body .= "{$k}" . "=" . urlencode($v);
  817. } else {
  818. $body .= "&" . "{$k}" . "=" . urlencode($v);
  819. }
  820. $i++;
  821. }
  822. }
  823. $body .= "&key=12345";
  824. return md5($body);
  825. }
  826. public function testCallMech()
  827. {
  828. $logic = Logic('queue');
  829. $logic->NotifyMerchantComplete(['order_id' => 18171, 'manual' => true]);
  830. }
  831. //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testCallMech)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test
  832. private function send($url, $params)
  833. {
  834. $mchid = $params['mchid'];
  835. $pri_key = BASE_DATA_PATH . "/api/merchant/key/{$mchid}_pri.pem";
  836. $key = file_get_contents($pri_key);
  837. $pri = openssl_get_privatekey($key);
  838. $body = $this->body($params);
  839. openssl_sign($body, $signed, $pri);
  840. $sign = base64_encode($signed);
  841. $params['sign'] = $sign;
  842. $resp = http_request($url, $params, 'POST');
  843. Log::record("resp:{$resp}", Log::DEBUG);
  844. }
  845. private function send_md5($url, $params)
  846. {
  847. $body = $this->body($params);
  848. $body .= "&key={$this->mKey}";
  849. $params['sign'] = md5($body);
  850. $resp = http_request($url, $params, 'POST');
  851. Log::record("resp:{$resp}", Log::DEBUG);
  852. return $resp;
  853. }
  854. public function testCardType()
  855. {
  856. $cardno = '1000111100021211884';
  857. $ret = preg_match('/^1[0-9]{18}$/', $cardno, $matches);
  858. }
  859. public function testMtrand()
  860. {
  861. }
  862. public function testHttpRefill()
  863. {
  864. $mchid = '000001';
  865. $pri_key = BASE_DATA_PATH . "/api/merchant/key/{$mchid}_pri.pem";
  866. $key = file_get_contents($pri_key);
  867. $pri = openssl_get_privatekey($key);
  868. $params = ['MCHID' => $mchid, 'cardno' => '1000111100021211884', 'amt' => "100", "act" => "refill", "op" => "addoil"];
  869. $body = $this->body($params);
  870. openssl_sign($body, $signed, $pri);
  871. $sign = base64_encode($signed);
  872. $params['sign'] = $sign;
  873. $resp = http_request(BASE_SITE_URL . "/mobile/index.php", $params, 'POST');
  874. }
  875. private function body($params)
  876. {
  877. ksort($params);
  878. $body = "";
  879. $i = 0;
  880. foreach ($params as $k => $v) {
  881. if (false === $this->checkEmpty($v) && "@" != substr($v, 0, 1)) {
  882. if ($i == 0) {
  883. $body .= "{$k}" . "=" . urlencode($v);
  884. } else {
  885. $body .= "&" . "{$k}" . "=" . urlencode($v);
  886. }
  887. $i++;
  888. }
  889. }
  890. return $body;
  891. }
  892. private function checkEmpty($value)
  893. {
  894. if (!isset($value))
  895. return true;
  896. if ($value === null)
  897. return true;
  898. if (trim($value) === "")
  899. return true;
  900. return false;
  901. }
  902. public function testKsort()
  903. {
  904. $age = ["Peter" => "35", "Ben" => "37", "Joe" => "43"];
  905. ksort($age);
  906. foreach ($age as $x => $x_value) {
  907. echo "Key=" . $x . ", Value=" . $x_value;
  908. echo "<br>";
  909. }
  910. }
  911. public function testip()
  912. {
  913. $model_merchant = Model('merchant');
  914. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => 1]);
  915. $ipwhitelist = unserialize($merchant_info['ip_white_list']);
  916. $res = json_encode($ipwhitelist);
  917. }
  918. //测试向内部店提交订单,可先屏蔽其它充值通道
  919. public function testAddoilToInnerStore()
  920. {
  921. $url = $this->mReqHost . "/mobile/index.php";
  922. $notifyurl = BASE_SITE_URL . '/mobile/signature.php';
  923. $params = ['mchid' => 1,
  924. 'cardno' => '1000111100020445281',
  925. 'amount' => "1000",
  926. "act" => "refill",
  927. "op" => "add",
  928. 'order_sn' => $this->make_sn(),
  929. 'notifyurl' => $notifyurl];
  930. $resp = $this->send_md5($url, $params);
  931. Log::record($resp, Log::DEBUG);
  932. }
  933. public function testRefillInnerCB()
  934. {
  935. $params = ['state_type' => 'order_cancel', 'order_id' => 311, 'channel_name' => 'lx'];
  936. $resp = http_request(BASE_SITE_URL . '/mobile/refill_inner.php', $params, 'POST');
  937. }
  938. public function testArgs()
  939. {
  940. Log::record($_SERVER['argv'], Log::DEBUG);
  941. }
  942. public function testCall()
  943. {
  944. $order_id = 14974;
  945. QueueClient::async_push("NotifyMerchantComplete", ['order_id' => $order_id, 'manual' => true], 10);
  946. }
  947. public function testSyncconfig()
  948. {
  949. $name_val_cfg = function ($items) {
  950. $result = [];
  951. foreach ($items as $item) {
  952. $name = $item->name();
  953. $result[$name] = $item;
  954. }
  955. return $result;
  956. };
  957. $name_val_row = function ($items) {
  958. $result = [];
  959. foreach ($items as $item) {
  960. $name = $item['name'];
  961. $result[$name] = $item;
  962. }
  963. return $result;
  964. };
  965. $match = function ($all, $cur) {
  966. $insert = [];
  967. foreach ($all as $key => $value) {
  968. if (!array_key_exists($key, $cur)) {
  969. $insert[] = $key;
  970. }
  971. }
  972. return $insert;
  973. };
  974. $inserter = function ($mod, $type, $names) {
  975. foreach ($names as $name) {
  976. $data = ['name' => $name, 'type' => $type];
  977. $mod->insert($data);
  978. }
  979. };
  980. $providers = refill\RefillFactory::instance()->providers();
  981. $oils = $name_val_cfg($providers['oil']);
  982. $phones = $name_val_cfg($providers['phone']);
  983. $mod_prov = Model('refill_provider');
  984. $oil_items = $mod_prov->getProviderList(['type' => 1]);
  985. $oil_items = $name_val_row($oil_items);
  986. $oil_inserts = $match($oils, $oil_items);
  987. $phone_items = $mod_prov->getProviderList(['type' => 2]);
  988. $phone_items = $name_val_row($phone_items);
  989. $phone_inserts = $match($phones, $phone_items);
  990. $inserter($mod_prov, 1, $oil_inserts);
  991. $inserter($mod_prov, 2, $phone_inserts);
  992. }
  993. public function testStat()
  994. {
  995. $model_refill_order = Model('refill_order');
  996. $stat = Model('')->table('refill_order,vr_order')->join('inner')
  997. ->on('refill_order.order_id=vr_order.order_id')
  998. ->field('sum(refill_amount) as refill_amounts , sum(channel_amount) as channel_amounts , sum(mch_amount) as mch_amounts')
  999. ->where([])->select();
  1000. }
  1001. public function testRefillGoods()
  1002. {
  1003. $goods = refill\RefillFactory::instance()->goods();
  1004. }
  1005. private function make_mobile()
  1006. {
  1007. $no = "1" . mt_rand(3000000000, 3999999999);
  1008. return $no;
  1009. }
  1010. private function refill_info($card_no, $card_type)
  1011. {
  1012. $data = rcache($card_no, 'cardrefill-');
  1013. if (empty($data)) {
  1014. $mod_topcard = Model('topcard');
  1015. $ret = $mod_topcard->get_card($card_no);
  1016. if (empty($ret)) {
  1017. $bind_phone = $this->make_mobile();
  1018. $mod_topcard->add($card_no, $card_type, time(), $bind_phone);
  1019. $data['bind_phone'] = $bind_phone;
  1020. $data['refill_time'] = time();
  1021. $data['times'] = 0;
  1022. wcache($card_no, $data, 'cardrefill-');
  1023. } else {
  1024. $val = $ret[0];
  1025. $data['bind_phone'] = $val['bind_phone'];
  1026. $data['refill_time'] = time();
  1027. $data['times'] = 0;
  1028. }
  1029. }
  1030. return $data;
  1031. }
  1032. public function testGetMobile()
  1033. {
  1034. $card_no = '1000119000001679247';
  1035. $card_type = 1;
  1036. $info = $this->refill_info($card_no, $card_type);
  1037. }
  1038. private function check_mchorder($mchid, $mch_order)
  1039. {
  1040. if (empty($mch_order)) {
  1041. return true;
  1042. } else {
  1043. $refill_order = Model('refill_order');
  1044. $ret = $refill_order->getOrderInfo(['mchid' => $mchid, 'mch_order' => $mch_order]);
  1045. return empty($ret);
  1046. }
  1047. }
  1048. public function testCheckMchorder()
  1049. {
  1050. $ret = $this->check_mchorder(1, '13281475');
  1051. }
  1052. public function testMakemobile()
  1053. {
  1054. $mobile = refill\util::make_mobile();
  1055. $ret = refill\util::set_black('1000111100020445281');
  1056. }
  1057. public function testLoadBlack()
  1058. {
  1059. $path = BASE_DATA_PATH . "/log";
  1060. $names = ['20210119-mobile.log',
  1061. '20210120-mobile.log', '20210121-mobile.log', '20210122-mobile.log', '20210123-mobile.log',
  1062. '20210124-mobile.log', '20210125-mobile.log'];
  1063. foreach ($names as $name) {
  1064. $file_name = $path . "/" . $name;
  1065. refill\util::black_from_log($file_name);
  1066. }
  1067. }
  1068. public function testStats()
  1069. {
  1070. $date = date('Y-m-d', time());
  1071. $today = strtotime("{$date}");
  1072. $times_begin = function ($start) {
  1073. $times = [];
  1074. $begin = $start;
  1075. for ($i = 0; $i < 7; $i++) {
  1076. $times[] = $begin;
  1077. $begin -= 86400;
  1078. }
  1079. return $times;
  1080. };
  1081. $reader = function ($mchid, $time) {
  1082. $cond['mchid'] = $mchid;
  1083. $cond['inner_status'] = 0;
  1084. $cond['refill_order.order_time'] = ['between', [$time, $time + 86400 - 1]];
  1085. $items = Model('')->table('refill_order,vr_order')->join('inner')
  1086. ->on('refill_order.order_id=vr_order.order_id')
  1087. ->field('count(*) as order_count, vr_order.order_state, sum(mch_amount) as mch_amounts')
  1088. ->group('vr_order.order_state')
  1089. ->where($cond)->select();
  1090. return $items;
  1091. };
  1092. $begins = $times_begin($today);
  1093. $mchid = 10096;
  1094. // $states = rcache($this->mchid() , 'refillstat-');
  1095. $states = unserialize($states ?? "");
  1096. if (empty($states)) $states = [];
  1097. $result = [];
  1098. $cache = [];
  1099. foreach ($begins as $begin) {
  1100. if (array_key_exists($begin, $states)) {
  1101. $item = $states[$begin];
  1102. } else {
  1103. $item = $reader($mchid, $begin);
  1104. }
  1105. $result[$begin] = $item;
  1106. //判断item 中充值中的状态是否为0,为0的情况下放进cache
  1107. $cache = $item;
  1108. }
  1109. wcache($this->mchid(), $cache, 'refillstat-');
  1110. return $result;
  1111. }
  1112. public function testNotifyx()
  1113. {
  1114. $mch_cache = rcache("merchant-notify", 'refill-');
  1115. $caches = empty($mch_cache['data']) ? [] : unserialize($mch_cache['data']);
  1116. $new_caches = [];
  1117. $merchants = Model('merchant')->getMerchantList([], '', '', 'merchant.*,member.available_predeposit', "0,1000");
  1118. foreach ($merchants as $merchant) {
  1119. $mchid = $merchant['mchid'];
  1120. $phone = $merchant['contact_phone'] ?? "";
  1121. $available_pd = intval($merchant['available_predeposit']);
  1122. $alarm_pd = intval($merchant['alarm_amount']) < 10000 ? 10000 : intval($merchant['alarm_amount']);
  1123. if (array_key_exists($mchid, $caches)) {
  1124. $mch_cache = $caches[$mchid];
  1125. } else {
  1126. $mch_cache = ['last_time' => 0, 'send_count' => 0];
  1127. }
  1128. if (!empty($phone) && ($available_pd < $alarm_pd)) {
  1129. $counts = $mch_cache['send_count'];
  1130. if (($mch_cache['last_time'] + 300 < time()) && $counts < 5) {
  1131. $mch_cache = ['last_time' => time(), 'send_count' => $counts + 1];
  1132. QueueClient::push('sendSMS', ['mobile' => $merchant['contact_phone'],
  1133. 'type' => 'balance_warning', 'datas' => [date("m月d日H时"), $merchant['available_predeposit']]]);
  1134. }
  1135. } else {
  1136. $mch_cache = ['last_time' => 0, 'send_count' => 0];
  1137. }
  1138. $new_caches[$mchid] = $mch_cache;
  1139. }
  1140. wcache("merchant-notify", ['data' => serialize($new_caches)], 'refill-');
  1141. }
  1142. public function testReadChannel()
  1143. {
  1144. refill\RefillFactory::instance()->read_channel();
  1145. }
  1146. public function testAllow()
  1147. {
  1148. $allow = refill\RefillFactory::instance()->allow(10096, 1, 100);
  1149. }
  1150. public function testCheckData()
  1151. {
  1152. $str = '|2|110667993758599771-充值失败|';
  1153. // $str = '0|提交成功|-36557.7400';
  1154. // if(preg_match( '/^-*[0-9]{1,3}\|[\x{4e00}-\x{9fa5}]+\|-*[0-9]+\.*[0-9]+$/u',$str,$matches)) {
  1155. // return true;
  1156. // }
  1157. // if(preg_match('/^[0-3]\|[0-9]+-*[\x{4e00}-\x{9fa5}]+\|[0-9]*$/u',$str,$matches)){
  1158. // return true;
  1159. // }
  1160. // return false;
  1161. $resp = ltrim($str, '|');
  1162. $resp = explode('|', $resp);
  1163. if (count($resp) != 3) {
  1164. return [false, '返回值错误'];
  1165. }
  1166. }
  1167. public function testErrre()
  1168. {
  1169. $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}';
  1170. $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);
  1171. }
  1172. public function testLog()
  1173. {
  1174. // $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 ]';
  1175. $fn = fopen(BASE_ROOT_PATH . "/10096.log", "r");
  1176. $mod = Model();
  1177. $mod->table('tfloat')->where(['member_id' => 65818])->update(['pdamount' => 0]);
  1178. $total_amount = ncPriceFormat(0.00);
  1179. $i = 0;
  1180. while (!feof($fn)) {
  1181. $i++;
  1182. $line = trim(fgets($fn));
  1183. $ret = preg_match('/[\w\W]+UPDATE[\w\W]+available_predeposit=available_predeposit(?P<oper>[-+]+)(?P<amount>[.\d]+)/i', $line, $matches);
  1184. if ($ret) {
  1185. $oper = $matches['oper'];
  1186. $amount = $matches['amount'];
  1187. if ($oper == '-') {
  1188. $total_amount = ncPriceFormat($total_amount) - ncPriceFormat($amount);
  1189. // $mod->table('tfloat')->where(['member_id' => 65818])->update( ['pdamount'=>['exp','pdamount-'.$amount]]);
  1190. } else {
  1191. $total_amount = ncPriceFormat($total_amount) + ncPriceFormat($amount);
  1192. // $mod->table('tfloat')->where(['member_id' => 65818])->update( ['pdamount'=>['exp','pdamount+'.$amount]]);
  1193. }
  1194. Log::record("index = {$i} {$total_amount} = {$total_amount} {$oper} {$amount}", Log::DEBUG);
  1195. }
  1196. }
  1197. Log::record("total_amount:{$total_amount}", Log::DEBUG);
  1198. fclose($fn);
  1199. }
  1200. public function testMchctl()
  1201. {
  1202. $ctl = new refill\mchctl();
  1203. }
  1204. public function testAsyncadd()
  1205. {
  1206. $x = \refill\util::async_add(['xxxx' => 1],4);
  1207. }
  1208. }
  1209. //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testLoadBlack)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test
  1210. //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