From 363774138ab4b11a11c7741d450b5bb2a0507bdd Mon Sep 17 00:00:00 2001 From: Akkariin Meiko Date: Tue, 21 Jan 2020 11:26:09 +0800 Subject: [PATCH] Tool: Generate random invite code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 可以随机生成指定数量的邀请码并储存到数据库 --- gencode.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 gencode.php diff --git a/gencode.php b/gencode.php new file mode 100644 index 0000000..b289e27 --- /dev/null +++ b/gencode.php @@ -0,0 +1,30 @@ + "; +$num = trim(fgets(STDIN)); +$conn = mysqli_connect($_config['db_host'], $_config['db_user'], $_config['db_pass'], $_config['db_name'], $_config['db_port']); +if(preg_match("/^[\d]{1,8}$/", $num)) { + $num = Intval($num); + for($i = 0;$i < $num;$i++) { + $code = getRandomText(32); + mysqli_query($conn, "INSERT INTO `invitecode` (`code`, `user`) VALUES ('{$code}', NULL)"); + echo "已添加:{$code}\n"; + } + exit("已生成指定数量激活码至数据库!\n"); +} else { + exit("数量不合法\n"); +}