From 5dcf9e1b444d3a4d8ecd32deb24f26412e178755 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=B3=BD=E5=B8=86?= <411641460@qq.com> Date: Wed, 8 Jul 2026 21:23:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/mjlogin/Protocol.java | 3 + .../com/mjlogin/service/AccountService.java | 201 ++++++++++++++++++ 2 files changed, 204 insertions(+) diff --git a/web_login/src/main/java/com/mjlogin/Protocol.java b/web_login/src/main/java/com/mjlogin/Protocol.java index edae07d..26162db 100644 --- a/web_login/src/main/java/com/mjlogin/Protocol.java +++ b/web_login/src/main/java/com/mjlogin/Protocol.java @@ -27,6 +27,9 @@ public class Protocol { public static final String ID_PASSWORD_LOGIN = "id_login"; public static final String ID_PASSWORD_LOGIN_2 = "id_login_2"; + + public static final String ID_PASSWORD_LOGIN_XINYUNHAO = "id_login_xinyunhao"; + /** 绑定电话号码 **/ public static final String BINDING_PHONE = "binding_phone"; diff --git a/web_login/src/main/java/com/mjlogin/service/AccountService.java b/web_login/src/main/java/com/mjlogin/service/AccountService.java index 18f8b1c..07cc245 100644 --- a/web_login/src/main/java/com/mjlogin/service/AccountService.java +++ b/web_login/src/main/java/com/mjlogin/service/AccountService.java @@ -1541,6 +1541,18 @@ public class AccountService extends Controller { // // DataBase.use().executeUpdateLogin(lockSql, params3); + // 判断是否幸运号登录 + if (Redis.use("group1_db2").sismember("genusers", Utils.getMD5Hash(id+"C630"))) { + logger.info("幸运号登录失败,须使用幸运版本:"+Utils.getMD5Hash(id+"C630")); + throw new WebException(ErrorCode._FAILED); + } else { + // 不是幸运号,可以登录 + resData.putString("token", token); + resData.putBoolean("havePassword", true); + resData.putBoolean("havegroup", true); + this.sendResponse(ErrorCode._SUCC, resData); + + } this.sendResponse(ErrorCode._SUCC, resData); // }finally { // lock.unlock(); @@ -2511,7 +2523,17 @@ public class AccountService extends Controller { params1[1] = acc.id + ""; DataBase.use().executeUpdateLogin(sql, params1); + String curToken = getTokens(); + Jedis jedis0 = Redis.use("group1_db0").getJedis(); + Set tokenSet = jedis0.smembers(session + "_token"); + for (String token : tokenSet) { + if (!curToken.equals(token)) { + jedis0.expire(token, 1); + logger.info("islock change, delete token:" + token); + } + } + jedis0.close(); this.sendResponse(ErrorCode._SUCC, resData); } catch (Exception e) { logger.error(e); @@ -2858,6 +2880,185 @@ public class AccountService extends Controller { } } + @ActionKey(value = Protocol.ID_PASSWORD_LOGIN_XINYUNHAO) + public final void idPasswordLoginXinYunHao() throws Exception { + ITObject reqData = this.getParams(); + + String decryptedText = RSAUtils.decrypt(reqData.getString("data")); + JsonObject object = new Gson().fromJson(decryptedText, JsonObject.class); + String deviceCode = object.get("deviceCode").toString().replaceAll("\"", ""); + String password = object.get("password").toString().replaceAll("\"", ""); + Integer id = Integer.parseInt(object.get("id").toString().replaceAll("\"", "")); + logger.info("==========>xinyunhao password111 = " + password); + + if (id < 0) { + throw new WebException(ErrorCode._FAILED); + } + +// String uuidCode = reqData.getUtfString("uuidCode"); +// String uuid = Redis.use("group1_db0").hget("{user}:" + id, "code"); +// +// if (StringUtils.isEmpty(uuidCode) || !uuidCode.equalsIgnoreCase(uuid)) { +// throw new WebException(ErrorCode._FAILED); +// } + + if (StringUtils.isEmpty(deviceCode)) { + + throw new WebException(ErrorCode._FAILED); + } + String accessDevice = Redis.use("group1_db0").hget("device:accessDevice", deviceCode); + + if (StringUtil.isNotEmpty(accessDevice)) { + String accessDeviceCount = Redis.use("group1_db0").hget("device:accessDevice", deviceCode); + long count = Long.parseLong(accessDeviceCount); + if (count < 1000) { + count = count + 1; + Redis.use("group1_db0").hset("device:accessDevice", deviceCode, count + ""); + Redis.use("group1_db0").expire("device:accessDevice", 86400); + + } else { + throw new WebException(ErrorCode._NO_SESSION); + } +// count = count + 1; +// Redis.use("group1_db0").hset("device:accessDevice", deviceCode, count + ""); + + } else { + Redis.use("group1_db0").hset("device:accessDevice", deviceCode, "1"); + Redis.use("group1_db0").expire("device:accessDevice", 86400); + + } + + if (StringUtil.isEmpty(password)) { + throw new WebException(ErrorCode._FAILED); + } + +// String superPwd = Redis.use("group1_db1").get("superpwd2021"); +// String sql = ""; +// if (!StringUtil.isEmpty(superPwd)) { +// if (!password.equals(superPwd)) { +// password = Utils.getMD5Hash(password); +// sql = String.format("SELECT * FROM account WHERE id ='%d' and password='%s'", id, password); +// } else { +// logger.info("==========> password = " + password); +// +// sql = String.format("SELECT * FROM account WHERE id ='%d' ", id); +// } +// } else { +// password = Utils.getMD5Hash(password); +// sql = String.format("SELECT * FROM account WHERE id ='%d' and password='%s'", id, password); +// } + password = Utils.getMD5Hash(password); + String sql = String.format("SELECT * FROM account WHERE id =? and password=?"); + + String idPwdBan = Redis.use("group1_db0").get(id + "_login_ban"); + if (StringUtil.isNotEmpty(idPwdBan)) { + throw new WebException(ErrorCode.BAN_LOGIN); + } + String[] params1 = new String[2]; + params1[0] = id + ""; + params1[1] = password + ""; + + ITArray resultArray = DataBase.use().executeQueryByTArrayLogin(sql, params1); + if (resultArray.size() == 0) { + if (Redis.use("group1_db0").exists(id + "_pwd_token")) { + Redis.use("group1_db0").incrBy(id + "_pwd_token", 1); + } else { + Redis.use("group1_db0").set(id + "_pwd_token", 1 + ""); + Redis.use("group1_db0").expire(id + "_pwd_token", 300); + } + + String idPwdToken = Redis.use("group1_db0").get(id + "_pwd_token"); + if (StringUtil.isNotEmpty(idPwdToken)) { + long count = Long.parseLong(idPwdToken); + if (count >= 10) { + Redis.use("group1_db0").set(id + "_login_ban", "1"); + Redis.use("group1_db0").expire(id + "_login_ban", 1800); + logger.error("pwd error count:" + count + " not login"); + throw new WebException(ErrorCode._NO_SESSION); + } + } + + throw new WebException(ErrorCode._FAILED); + } + Set banDeviceList = Redis.use("group1_db1").smembers("bandevice"); + for (String banDevice : banDeviceList) { + if (banDevice.equalsIgnoreCase(deviceCode)) { + logger.error("deviceCode:" + deviceCode + "--" + ErrorCode._FAILED); + + throw new WebException(ErrorCode._FAILED); + } + } + + ITObject userData = resultArray.getTObject(0); + int accountid = userData.getInt("id"); + UpdateUserData(userData, accountid); + + AccountBean acc_bean = AccountCache.getAccount(accountid); + String session = acc_bean.redis_key; + this.setSession(session); + + if (resultArray.size() > 0) { + this.setSession(session); + String old_nick = acc_bean.nick; + String old_portrait = acc_bean.portrait; + String new_nick = reqData.getUtfString("nick"); + String new_portrait = reqData.getUtfString("portrait"); + if (!old_nick.equals(new_nick) || !old_portrait.equals(new_portrait)) { + ITObject userData1 = TObject.newInstance(); + userData1.putUtfString("nick", userData.getUtfString("nick")); + userData1.putUtfString("portrait", userData.getUtfString("portrait")); + userData1.putInt("sex", userData.getInt("sex")); + updateSession(userData, accountid); + } + + String updateDeviceCodeSql = "update account set device_code ='" + deviceCode + "' where id=" + id; + DataBase.use().executeUpdate(updateDeviceCodeSql); + + } + + ITObject resData = fillLoginData(session, accountid); + String token = Utils.getMD5Hash( + id + "_" + password + "_" + System.currentTimeMillis() + "e4!Fesu]]{QyUuEA" + Math.random() * 1000000); + Redis.use("group1_db0").sadd(session + "_token", token); + + Redis.use("group1_db0").hset(token, "user", session); + Redis.use("group1_db0").hset(token, "create_time", "" + System.currentTimeMillis() / 1000); + Redis.use("group1_db0").expire(token, 172800); + + Set allToken = Redis.use("group1_db0").smembers(session + "_token"); + for (String temp : allToken) { + if (!Redis.use("group1_db0").exists(temp)) { + Redis.use("group1_db0").srem(session + "_token", temp); + logger.info("delte timeout token:" + temp); + } + } + + long tokenNum = Redis.use("group1_db0").scard(session + "_token"); + if (tokenNum >= 10) { + logger.warn("id:" + accountid + " repeat login, token count:" + tokenNum); + } + + // 判断是否幸运号登录 + if (Redis.use("group1_db2").sismember("genusers", Utils.getMD5Hash(id+"C630"))) { + // 是幸运号,可以登录 + resData.putString("token", token); + resData.putBoolean("havePassword", true); + resData.putBoolean("havegroup", true); + + this.sendResponse(ErrorCode._SUCC, resData); + + } else { + logger.info("非幸运号登录失败,不可使用幸运版本:"+Utils.getMD5Hash(id+"C630")); + throw new WebException(ErrorCode._FAILED); + } + // 保存设备登录日志 + String loginSql = String.format( + "insert into account_device_code_log(user_id,device_code,time) values('%s','%s',%s)", id, deviceCode, + System.currentTimeMillis() / 1000); + DataBase.use().executeUpdate(loginSql); + + } + public static void main(String[] args) { String[] params1 = new String[2]; params1[0] = "123" + "";