TestRefill.php 32 KB

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