TestRefill.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  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->mMchid = 1092;
  29. $this->mKey = '210fe406954220f56085997d6a4c5b80';
  30. }
  31. }
  32. public static function setUpBeforeClass(): void
  33. {
  34. Base::run_util();
  35. }
  36. public function testFactory()
  37. {
  38. $providers = refill\RefillFactory::instance();
  39. }
  40. private function make_sn()
  41. {
  42. return mt_rand(1000, 9999)
  43. . sprintf('%010d', time())
  44. . sprintf('%06d', (float)microtime() * 1000000);
  45. }
  46. public function testRandomMobile()
  47. {
  48. $no = "1" . mt_rand(1, 9999999999);
  49. Log::record("phone no={$no}",Log::DEBUG);
  50. }
  51. public function testBJBAddPhone()
  52. {
  53. $providers = new refill\bjb\RefillPhone([]);
  54. for ($i = 3; $i > 0; --$i) {
  55. $resp = $providers->add(13911129867, 4, 10, ['order_sn' => $this->make_sn()]);
  56. $resp = $providers->add(18500608333, 4, 10, ['order_sn' => $this->make_sn()]);
  57. $resp = $providers->add(18510683168, 4, 10, ['order_sn' => $this->make_sn()]);
  58. $resp = $providers->add(18513846008, 4, 10, ['order_sn' => $this->make_sn()]);
  59. $resp = $providers->add(18518237398, 4, 10, ['order_sn' => $this->make_sn()]);
  60. }
  61. }
  62. public function testIpWhiteList()
  63. {
  64. $x = serialize(['47.99.57.105']);
  65. $ips = unserialize('a:1:{i:0;s:12:"47.99.57.105";}');
  66. if (!empty($ips)) {
  67. $addr = '47.99.57.105';
  68. Log::record("request ip:{$addr}", Log::DEBUG);
  69. if (!in_array($addr, $ips)) {
  70. throw new Exception("请求地址不在白名单中");
  71. }
  72. }
  73. }
  74. public function testXcPhone()
  75. {
  76. $providers = new refill\xc\RefillPhone([]);
  77. $resp = $providers->add(18500608333, 5, 100, ['order_sn' => $this->make_sn()]);
  78. }
  79. public function testYifaPhone()
  80. {
  81. $providers = new refill\yifa\RefillPhone([]);
  82. $resp = $providers->add(15120035568, 5, 50, ['order_sn' => $this->make_sn()]);
  83. }
  84. public function testWeitPhone()
  85. {
  86. $providers = new refill\weit\RefillPhone([]);
  87. for ($i = 0;$i<=10;$i++){
  88. $resp = $providers->add(18500608333, 5, 10, ['order_sn' => $this->make_sn()]);
  89. }
  90. }
  91. public function testWeitCB()
  92. {
  93. $params['sign'] = 'af820c33472f4b571fa0c48483dfb975';
  94. $params['status'] = 0;
  95. $params['price'] = 30;
  96. $params['op_order_id'] = '';
  97. $params['mch_order_id'] = '900664281823957221';
  98. $params['pt_order_id'] = '2021011802434412825405218901';
  99. $params['pay_type'] = '';
  100. $params['tel'] = 18500608333;
  101. $params['mchid'] = 10014;
  102. $resp = http_request($this->mReqHost . "/mobile/refill_weit.php", $params , 'POST');
  103. }
  104. public function testYifaCB()
  105. {
  106. $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"}';
  107. // $resp = http_post_data($this->mReqHost . "/mobile/refill_yifa.php", $body);
  108. // $content = $_SERVER['post_content'];
  109. $input = json_decode($body,true);
  110. refill\RefillFactory::instance()->notify('yifa',$input);
  111. }
  112. public function testXcQuery()
  113. {
  114. $providers = new refill\xc\RefillPhone([]);
  115. $refill_info = ['order_sn' => 950663423236726632, 'ch_trade_no' => 499, 'card_no' => 1000111200005252927];
  116. $resp = $providers->query($refill_info);
  117. }
  118. public function testSuhcQuery()
  119. {
  120. $providers = new refill\suhctm\RefillOil([]);
  121. $refill_info = ['order_sn' => 950663423236726632, 'ch_trade_no' => 499, 'card_no' => 1000111200005252927];
  122. $resp = $providers->query($refill_info);
  123. }
  124. public function testSaihuOil()
  125. {
  126. $providers = new refill\saihu\RefillOil([]);
  127. $resp = $providers->add(1000111100021211884, 2, 100, ['order_sn' => $this->make_sn()]);
  128. }
  129. public function testBdtOil()
  130. {
  131. $providers = new refill\bdt\RefillOil([]);
  132. $resp = $providers->add(1000111100021211884, 2, 100, ['order_sn' => '200229600556618886']);
  133. }
  134. public function testGFTDOil()
  135. {
  136. $providers = new refill\gftd\RefillOil([]);
  137. $resp = $providers->add(1000111100020445281, mtopcard\SinopecCard, 100, ['order_sn' => $this->make_sn()]);
  138. }
  139. public function testGFTDCB()
  140. {
  141. $data = '{"channelOrderNumber":"79091610959059372019","orderNumber":"GYFL1610959060397001","message":"充值成功","signature":"881036222bd8f067ff47d248c75f4c8d","voucher":"","status":101}';
  142. $url = "http://192.168.1.220/mobile/refill_gftd.php?" . $data;
  143. $resp = http_post_data($url, $data, ['Content-Type: application/json;charset=UTF-8;','Accept:application/json;charset=UTF-8;']);
  144. }
  145. public function testJiecPhone()
  146. {
  147. $providers = new refill\jiec\RefillPhone([]);
  148. $resp = $providers->add('18500608333', 5, 30, ['order_sn' => $this->make_sn()]);
  149. }
  150. public function testBxtwtCB()
  151. {
  152. $data = '{"order_number":18219726,"shipping_status":4,"shipping_status_desc":"发货失败","shipping_status_message":"","sign":"863b4d972f2a4d39a9af7396879116c4","voucher":"","vouchertype":"","voucherurl":"","tradeNo":"100662475851197741"}';
  153. }
  154. public function testSuhcJDVerify()
  155. {
  156. $data = 'onlystr=920661883198026632&sign=533151e3f0dff5f507786aabc37b18f7&amt=100&notifyurl=https%3A%2F%2Fwww.xyzshops.cn%2Fmobile%2Frefill_suhc.php&jdno&cardtype=Sinoepc&batchid=26106&cardno=1000111100020654226&orgid=1590993600&status=3';
  157. $url = "http://192.168.1.220/mobile/refill_suhc.php?" . $data;
  158. $resp = http_request($url);
  159. }
  160. public function testSuhcPDD()
  161. {
  162. $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';
  163. $url = "https://www.xyzshops.cn/mobile/refill_suhcpdd.php?" . $data;
  164. $resp = http_request($url);
  165. }
  166. public function testSuhcTMVerify()
  167. {
  168. $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';
  169. // $url = "http://192.168.1.220/mobile/refill_suhctm.php?" . $data;
  170. $url = "https://www.xyzshops.cn/mobile/refill_suhctm.php?" . $data;
  171. $resp = http_request($url);
  172. }
  173. public function testBeixtVerify()
  174. {
  175. $data = '{"order_number":18219726,"shipping_status":4,"shipping_status_desc":"发货失败","shipping_status_message":"","sign":"863b4d972f2a4d39a9af7396879116c4","voucher":"","vouchertype":"","voucherurl":"","tradeNo":"100662475851197741"}';
  176. $url = "https://www.xyzshops.cn/mobile/refill_bxtwt.php";
  177. $headers = ['Content-Type: application/json'];
  178. $resp = http_post_data($url, $data, $headers);
  179. }
  180. public function testInput()
  181. {
  182. $input = fopen("php://input", "rw");
  183. file_put_contents($input, 'xxxx');
  184. $content = file_get_contents('php://input');
  185. }
  186. public function testUrl()
  187. {
  188. $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';
  189. $params = preg_split('/&/', $data);
  190. foreach ($params as $pair) {
  191. $kv = explode('=', $pair);
  192. $count = count($kv);
  193. if ($count === 1) {
  194. $key = $kv[0];
  195. $val = "";
  196. } elseif ($count === 2) {
  197. $key = $kv[0];
  198. $val = $kv[1];
  199. } else {
  200. continue;
  201. }
  202. Log::record("{$key}:{$val}", Log::DEBUG);
  203. }
  204. }
  205. public function testAddoil()
  206. {
  207. $url = $this->mReqHost . "/mobile/index.php";
  208. $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php';
  209. $params = ['mchid' => $this->mMchid,
  210. 'cardno' => '1000111100020445281',
  211. 'amount' => "100",
  212. "act" => "refill",
  213. "op" => "add",
  214. 'order_sn' => $this->make_sn(),
  215. 'notifyurl' => $notifyurl];
  216. $resp = $this->send_md5($url, $params);
  217. Log::record($resp, Log::DEBUG);
  218. }
  219. public function testBalance()
  220. {
  221. $url = $this->mReqHost . "/mobile/index.php";
  222. $params = ['mchid' => 1092,
  223. "act" => "refill",
  224. "op" => "balance"];
  225. $resp = $this->send_md5($url, $params);
  226. Log::record($resp, Log::DEBUG);
  227. }
  228. public function testAddPhoe()
  229. {
  230. $phones = [//13911129867,
  231. 18500608333,
  232. 18510683168,
  233. 18513846008,
  234. 18518237398];
  235. $amount = 10;
  236. for ($i = 0; $i < 3; $i++) {
  237. foreach ($phones as $phone) {
  238. $url = $this->mReqHost . "/mobile/index.php";
  239. $params = ['mchid' => 1092,
  240. 'cardno' => $phone,
  241. 'amount' => $amount,
  242. "act" => "refill",
  243. "op" => "add",
  244. 'order_sn' => $this->make_sn(),
  245. 'notifyurl' => $this->mReqHost . "/mobile/refill_xyz.php"];
  246. $resp = $this->send_md5($url, $params);
  247. Log::record($resp, Log::DEBUG);
  248. }
  249. }
  250. }
  251. public function testProxyHelper()
  252. {
  253. $phone = '13911129867';
  254. $amount = 100;
  255. $url = $this->mReqHost . "/mobile/index.php";
  256. $params = ['mchid' => 1090,
  257. 'cardno' => $phone,
  258. 'amount' => $amount,
  259. "act" => "refill",
  260. "op" => "add",
  261. 'order_sn' => $this->make_sn(),
  262. 'notifyurl' => "https://xxx"];
  263. $proxy = new refill_proxy("xxx");
  264. $resp = $proxy->send($url, $params);
  265. }
  266. public function testGoods()
  267. {
  268. $req_url = $this->mReqHost . '/mobile/index.php';
  269. $params = ['mchid' => $this->mMchid,
  270. "act" => "refill",
  271. "op" => "goods"];
  272. $resp = $this->send_md5($req_url, $params);
  273. }
  274. public function testQueryFactory()
  275. {
  276. refill\RefillFactory::instance()->query(295);
  277. }
  278. public function testQuery()
  279. {
  280. //$req_url = 'https://www.xyzshops.cn/mobile/index.php';
  281. // $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php';
  282. $req_url = BASE_SITE_URL . '/mobile/index.php';
  283. $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php';
  284. $params = ['mchid' => 1,
  285. "act" => "refill",
  286. "op" => "query",
  287. 'order_sn' => "13281476"];
  288. $resp = $this->send_md5($req_url, $params);
  289. }
  290. public function testRemoveSession()
  291. {
  292. $resp = http_request(BASE_SITE_URL . "/mobile/signature.php", [], 'POST');
  293. }
  294. public function testSuhcCB()
  295. {
  296. // $notifyurl = BASE_SITE_URL . "/mobile/refill_suhc.php";
  297. $notifyurl = "https://www.xyzshops.cn/mobile/refill_suhc.php";
  298. // $notifyurl = "https%3A%2F%2Fwww.xyzshops.cn%2Fmobile%2Frefill_suhc.php";
  299. $params = ['onlystr' => '920660917672249741',
  300. 'amt' => 100,
  301. 'jdno' => '',
  302. 'notifyurl' => $notifyurl,
  303. 'cardtype' => 'Sinoepc',
  304. 'batchid' => 18512,
  305. 'cardno' => '1000111100020445281',
  306. 'orgid' => '1590993600',
  307. 'status' => 2];
  308. $sign = $this->md5_sign($params);
  309. $params['sign'] = $sign;
  310. $resp = http_request($notifyurl, $params, 'POST');
  311. Log::record($resp, Log::DEBUG);
  312. }
  313. public function testBJBCB()
  314. {
  315. $params = [
  316. 'usr' => '13699279618',
  317. 'ord' => '710662733975412771',
  318. 'state' => '2',
  319. 'bz' => '',
  320. 'sgn' => 'AC9AFD254DE682D8440A97CA68B992DA'
  321. ];
  322. $resp = http_request("https://www.xyzshops.cn/mobile/refill_bjb.php", $params, 'POST');
  323. }
  324. public function testJiecCB()
  325. {
  326. $params['result'] = 'fail';
  327. $params['msg'] = '0';
  328. $params['order'] = 'null';
  329. $params['phone_no'] = '18500608333';
  330. $params['amount'] = '30.00';
  331. $params['op_no'] = '800663597981819221';
  332. $params['sign'] = '2510046895e8e12322c8a32547905ee9';
  333. $resp = http_request($this->mReqHost . "/mobile/refill_jiec.php", $params, 'POST');
  334. }
  335. public function testZFKJ()
  336. {
  337. //带签名参数:mchid=1090&act=refill&op=add&cardno=100112121212212133
  338. //&amount=10&order_sn=PH2012261356569433&
  339. //notifyurl=https%3A%2F%2Fqzcz.edusahoo.com.cn%2Findex%2Findex%2Fcallback
  340. //&sign=4a3ac5f9706e64aa70c6cab0fc5839d3
  341. $params = ['mchid' => 1090,
  342. 'cardno' => '100112121212212133',
  343. 'amount' => '10',
  344. "act" => "refill",
  345. "op" => "add",
  346. 'order_sn' => 'PH2012261356569433',
  347. 'notifyurl' => 'https://qzcz.edusahoo.com.cn/index/index/callback'];
  348. $resp = $this->send_md5(BASE_SITE_URL . '/mobile/index.php', $params);
  349. }
  350. protected function check_empty($value)
  351. {
  352. if (!isset($value))
  353. return true;
  354. if ($value === null)
  355. return true;
  356. if (trim($value) === "")
  357. return true;
  358. return false;
  359. }
  360. private function md5_sign($params)
  361. {
  362. ksort($params);
  363. $body = "";
  364. $i = 0;
  365. foreach ($params as $k => $v) {
  366. if (false === $this->check_empty($v) && "@" != substr($v, 0, 1)) {
  367. if ($i == 0) {
  368. $body .= "{$k}" . "=" . urldecode($v);
  369. } else {
  370. $body .= "&" . "{$k}" . "=" . urldecode($v);
  371. }
  372. $i++;
  373. }
  374. }
  375. $body .= "&key=GG7yDCLS6S2KzSAJQOUc3vsa";
  376. return md5($body);
  377. }
  378. public function testCallMech()
  379. {
  380. $logic = Logic('queue');
  381. $logic->NotifyMerchantComplete(['order_id' => 18171,'manual' => true]);
  382. }
  383. //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testCallMech)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test
  384. private function send($url, $params)
  385. {
  386. $mchid = $params['mchid'];
  387. $pri_key = BASE_DATA_PATH . "/api/merchant/key/{$mchid}_pri.pem";
  388. $key = file_get_contents($pri_key);
  389. $pri = openssl_get_privatekey($key);
  390. $body = $this->body($params);
  391. openssl_sign($body, $signed, $pri);
  392. $sign = base64_encode($signed);
  393. $params['sign'] = $sign;
  394. $resp = http_request($url, $params, 'POST');
  395. Log::record("resp:{$resp}", Log::DEBUG);
  396. }
  397. private function send_md5($url, $params)
  398. {
  399. $body = $this->body($params);
  400. $body .= "&key={$this->mKey}";
  401. $params['sign'] = md5($body);
  402. $resp = http_request($url, $params, 'POST');
  403. Log::record("resp:{$resp}", Log::DEBUG);
  404. return $resp;
  405. }
  406. public function testCardType()
  407. {
  408. $cardno = '1000111100021211884';
  409. $ret = preg_match('/^1[0-9]{18}$/', $cardno, $matches);
  410. }
  411. public function testMtrand()
  412. {
  413. }
  414. public function testHttpRefill()
  415. {
  416. $mchid = '000001';
  417. $pri_key = BASE_DATA_PATH . "/api/merchant/key/{$mchid}_pri.pem";
  418. $key = file_get_contents($pri_key);
  419. $pri = openssl_get_privatekey($key);
  420. $params = ['MCHID' => $mchid, 'cardno' => '1000111100021211884', 'amt' => "100", "act" => "refill", "op" => "addoil"];
  421. $body = $this->body($params);
  422. openssl_sign($body, $signed, $pri);
  423. $sign = base64_encode($signed);
  424. $params['sign'] = $sign;
  425. $resp = http_request(BASE_SITE_URL . "/mobile/index.php", $params, 'POST');
  426. }
  427. private function body($params)
  428. {
  429. ksort($params);
  430. $body = "";
  431. $i = 0;
  432. foreach ($params as $k => $v) {
  433. if (false === $this->checkEmpty($v) && "@" != substr($v, 0, 1)) {
  434. if ($i == 0) {
  435. $body .= "{$k}" . "=" . urlencode($v);
  436. } else {
  437. $body .= "&" . "{$k}" . "=" . urlencode($v);
  438. }
  439. $i++;
  440. }
  441. }
  442. return $body;
  443. }
  444. private function checkEmpty($value)
  445. {
  446. if (!isset($value))
  447. return true;
  448. if ($value === null)
  449. return true;
  450. if (trim($value) === "")
  451. return true;
  452. return false;
  453. }
  454. public function testKsort()
  455. {
  456. $age = ["Peter" => "35", "Ben" => "37", "Joe" => "43"];
  457. ksort($age);
  458. foreach ($age as $x => $x_value) {
  459. echo "Key=" . $x . ", Value=" . $x_value;
  460. echo "<br>";
  461. }
  462. }
  463. public function testip()
  464. {
  465. $model_merchant = Model('merchant');
  466. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => 1]);
  467. $ipwhitelist = unserialize($merchant_info['ip_white_list']);
  468. $res = json_encode($ipwhitelist);
  469. }
  470. //测试向内部店提交订单,可先屏蔽其它充值通道
  471. public function testAddoilToInnerStore()
  472. {
  473. $url = $this->mReqHost . "/mobile/index.php";
  474. $notifyurl = BASE_SITE_URL . '/mobile/signature.php';
  475. $params = ['mchid' => 1,
  476. 'cardno' => '1000111100020445281',
  477. 'amount' => "1000",
  478. "act" => "refill",
  479. "op" => "add",
  480. 'card_name' => '江海苗',
  481. 'order_sn' => $this->make_sn(),
  482. 'notifyurl' => $notifyurl];
  483. $resp = $this->send_md5($url, $params);
  484. Log::record($resp, Log::DEBUG);
  485. }
  486. public function testRefillInnerCB()
  487. {
  488. $params = ['state_type' => 'order_cancel', 'order_id' => 311, 'channel_name' => 'lx'];
  489. $resp = http_request(BASE_SITE_URL . '/mobile/refill_inner.php', $params, 'POST');
  490. }
  491. public function testArgs()
  492. {
  493. Log::record($_SERVER['argv'], Log::DEBUG);
  494. }
  495. public function testCall()
  496. {
  497. $order_id = 14974;
  498. QueueClient::async_push("NotifyMerchantComplete", ['order_id' => $order_id,'manual' => true], 10);
  499. }
  500. public function testSyncconfig()
  501. {
  502. $name_val_cfg = function ($items) {
  503. $result = [];
  504. foreach ($items as $item) {
  505. $name = $item->name();
  506. $result[$name] = $item;
  507. }
  508. return $result;
  509. };
  510. $name_val_row = function ($items) {
  511. $result = [];
  512. foreach ($items as $item) {
  513. $name = $item['name'];
  514. $result[$name] = $item;
  515. }
  516. return $result;
  517. };
  518. $match = function ($all,$cur)
  519. {
  520. $insert = [];
  521. foreach ($all as $key => $value)
  522. {
  523. if(!array_key_exists($key,$cur)) {
  524. $insert[] = $key;
  525. }
  526. }
  527. return $insert;
  528. };
  529. $inserter = function ($mod,$type,$names)
  530. {
  531. foreach ($names as $name) {
  532. $data = ['name' => $name,'type' => $type];
  533. $mod->insert($data);
  534. }
  535. };
  536. $providers = refill\RefillFactory::instance()->providers();
  537. $oils = $name_val_cfg($providers['oil']);
  538. $phones = $name_val_cfg($providers['phone']);
  539. $mod_prov = Model('refill_provider');
  540. $oil_items = $mod_prov->getProviderList(['type' => 1]);
  541. $oil_items = $name_val_row($oil_items);
  542. $oil_inserts = $match($oils,$oil_items);
  543. $phone_items = $mod_prov->getProviderList(['type' => 2]);
  544. $phone_items = $name_val_row($phone_items);
  545. $phone_inserts = $match($phones,$phone_items);
  546. $inserter($mod_prov,1,$oil_inserts);
  547. $inserter($mod_prov,2,$phone_inserts);
  548. }
  549. public function testStat()
  550. {
  551. $model_refill_order = Model('refill_order');
  552. $stat = Model('')->table('refill_order,vr_order')->join('inner')
  553. ->on('refill_order.order_id=vr_order.order_id')
  554. ->field('sum(refill_amount) as refill_amounts , sum(channel_amount) as channel_amounts , sum(mch_amount) as mch_amounts')
  555. ->where([])->select();
  556. }
  557. public function testRefillGoods()
  558. {
  559. $goods = refill\RefillFactory::instance()->goods();
  560. }
  561. private function make_mobile()
  562. {
  563. $no = "1" . mt_rand(3000000000, 3999999999);
  564. return $no;
  565. }
  566. private function refill_info($card_no, $card_type)
  567. {
  568. $data = rcache($card_no, 'cardrefill-');
  569. if(empty($data))
  570. {
  571. $mod_topcard = Model('topcard');
  572. $ret = $mod_topcard->get_card($card_no);
  573. if(empty($ret)) {
  574. $bind_phone = $this->make_mobile();
  575. $mod_topcard->add($card_no,$card_type,time(),$bind_phone);
  576. $data['bind_phone'] = $bind_phone;
  577. $data['refill_time'] = time();
  578. $data['times'] = 0;
  579. wcache($card_no,$data,'cardrefill-');
  580. }
  581. else {
  582. $val = $ret[0];
  583. $data['bind_phone'] = $val['bind_phone'];
  584. $data['refill_time'] = time();
  585. $data['times'] = 0;
  586. }
  587. }
  588. return $data;
  589. }
  590. public function testGetMobile()
  591. {
  592. $card_no = '1000119000001679247';
  593. $card_type = 1;
  594. $info = $this->refill_info($card_no,$card_type);
  595. }
  596. private function check_mchorder($mchid,$mch_order)
  597. {
  598. if(empty($mch_order)) {
  599. return true;
  600. }
  601. else {
  602. $refill_order = Model('refill_order');
  603. $ret = $refill_order->getOrderInfo(['mchid' => $mchid,'mch_order' => $mch_order]);
  604. return empty($ret);
  605. }
  606. }
  607. public function testCheckMchorder()
  608. {
  609. $ret = $this->check_mchorder(1,'13281475');
  610. }
  611. public function testMakemobile()
  612. {
  613. $mobile = refill\util::make_mobile();
  614. $ret = refill\util::set_black('1000111100020445281');
  615. }
  616. public function testLoadBlack()
  617. {
  618. $path = BASE_DATA_PATH . "/log";
  619. $names = ['20210119-mobile.log',
  620. '20210120-mobile.log','20210121-mobile.log','20210122-mobile.log','20210123-mobile.log',
  621. '20210124-mobile.log','20210125-mobile.log'];
  622. foreach ($names as $name)
  623. {
  624. $file_name = $path . "/" . $name;
  625. refill\util::black_from_log($file_name);
  626. }
  627. }
  628. public function testErrre()
  629. {
  630. $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}';
  631. $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);
  632. }
  633. }
  634. //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testLoadBlack)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test
  635. //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