TestRefill.php 31 KB

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