TestAccRefill.php 31 KB

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