surroundingCompanies = DaoFactory.getUserDaoInstance().getSurroundingCompanies(conn);
+ message = "共查询到"+surroundingCompanies.size()+"条记录";
+ respWrite(code,message,surroundingCompanies,respWriter);
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ doGet(request,response);
+ }
+}
diff --git a/src/main/java/servlet/socialServ/RegisterAsAMerchServlet.java b/src/main/java/servlet/socialServ/RegisterAsAMerchServlet.java
new file mode 100644
index 0000000000000000000000000000000000000000..535771e600adaf71c7b715900f3f93ab82d8ca3d
--- /dev/null
+++ b/src/main/java/servlet/socialServ/RegisterAsAMerchServlet.java
@@ -0,0 +1,96 @@
+package servlet.socialServ;
+
+import bean.Merch;
+import factory.DaoFactory;
+import log.CusLogger;
+import org.json.JSONObject;
+import utils.CodeMsg;
+import utils.JDBCUtils;
+
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.sql.Connection;
+
+import static utils.ServletUtils.getJsonData;
+import static utils.ServletUtils.respWrite;
+
+
+/**
+ * @author zdy
+ */
+@WebServlet(name = "RegisterAsAMerchServlet", value = "/serve/registerAsAMerch")
+public class RegisterAsAMerchServlet extends HttpServlet {
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ doPost(request,response);
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ Merch merch = null;
+ // 状态码
+ String code = CodeMsg.success;
+ // 提示信息
+ String message = CodeMsg.successMsg;
+ PrintWriter respWriter = null;
+ try {
+ respWriter = response.getWriter();
+ } catch (IOException e) {
+ CusLogger.saveError(e.getMessage());
+ return;
+ }
+ // 获取请求数据
+ JSONObject registerData = getJsonData(request);
+ String name = "";
+ String icoUrl = "";
+ String introduction = "";
+ String details = "";
+ int type = 0;
+ try {
+ name = registerData.getString("name");
+ icoUrl = registerData.getString("icoUrl");
+ introduction = registerData.getString("introduction");
+ details = registerData.getString("details");
+ type = registerData.getInt("type");
+ } catch (NumberFormatException e) {
+ code = CodeMsg.fieldIsMissing;
+ message = CodeMsg.fieldIsMissingMsg;
+ CusLogger.saveInfo(CodeMsg.fieldIsMissingMsg);
+ respWrite(code, message, null, respWriter);
+ return;
+ }
+ // 数据验证
+ if (type != 1 && type !=2 && type !=3 ) {
+ code = CodeMsg.wrongBusTyp;
+ message = CodeMsg.wrongBusTypMsg;
+ CusLogger.saveInfo(CodeMsg.wrongBusTypMsg);
+ respWrite(code, message, null, respWriter);
+ return;
+ } else {
+ merch = new Merch(name,icoUrl,introduction,details,type);
+ Connection conn = JDBCUtils.getConnectionDruid();
+ int res = DaoFactory.getUserDaoInstance().registerAsAMerch(conn,merch);
+ switch (res) {
+ case 0:
+ CusLogger.saveUserLog(merch.toString() + "注册成功");
+ break;
+ case 2:
+ code = CodeMsg.merchAlreadyExists;
+ message = CodeMsg.merchAlreadyExistsMsg;
+ CusLogger.saveInfo(name + message);
+ break;
+ default:
+ code = CodeMsg.registerAsMerchFailed;
+ message = CodeMsg.registerAsMerchFailedMsg;
+ CusLogger.saveInfo(merch.toString()+message);
+ }
+ JDBCUtils.close(conn,null,null);
+ }
+ respWrite(code,message,merch,respWriter);
+ }
+}
diff --git a/src/main/java/servlet/usrManagement/DeleteServlet.java b/src/main/java/servlet/usrManagement/DeleteServlet.java
new file mode 100644
index 0000000000000000000000000000000000000000..98eebddca8c23fb80cdfd932c58b55212f62bf97
--- /dev/null
+++ b/src/main/java/servlet/usrManagement/DeleteServlet.java
@@ -0,0 +1,80 @@
+package servlet.usrManagement;
+
+import bean.User;
+import factory.DaoFactory;
+import log.CusLogger;
+import org.json.JSONObject;
+import utils.CodeMsg;
+import utils.EncryptUtil;
+import utils.JDBCUtils;
+
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.sql.Connection;
+
+import static utils.ServletUtils.getJsonData;
+import static utils.ServletUtils.respWrite;
+
+@WebServlet(name = "DeleteServlet", value = "/user/delete")
+public class DeleteServlet extends HttpServlet {
+
+ @Override
+ protected void doDelete(HttpServletRequest request, HttpServletResponse response){
+ // 状态码
+ String code = CodeMsg.success;
+ // 提示信息
+ String message = CodeMsg.successMsg;
+ PrintWriter respWriter = null;
+ try {
+ respWriter = response.getWriter();
+ } catch (IOException e) {
+ CusLogger.saveError(e.getMessage());
+ return;
+ }
+ JSONObject loginData = getJsonData(request);
+ String tel = loginData.getString("tel");
+ String pwd = loginData.getString("pwd");
+ if ("".equals(tel) || "".equals(pwd)) {
+ code = CodeMsg.fieldIsMissing;
+ message = CodeMsg.fieldIsMissingMsg;
+ respWrite(code, message, null, respWriter);
+ return;
+ }
+ pwd = EncryptUtil.encrypt(pwd);
+ Connection conn = JDBCUtils.getConnectionDruid();
+ User user = DaoFactory.getUserDaoInstance().login(conn, tel);
+ if (user == null) {
+ code = CodeMsg.usrDoesNotExist;
+ message = CodeMsg.usrDoesNotExistMsg;
+ } else if (!user.getPwd().equals(pwd)) {
+ code = CodeMsg.wrongPwd;
+ message = CodeMsg.wrongPwdMsg;
+ } else {
+ int delete = DaoFactory.getUserDaoInstance().delete(conn, tel);
+ if(delete > 0) {
+ code = CodeMsg.success;
+ message = CodeMsg.successMsg;
+ respWrite(code, message, user, respWriter);
+ return;
+ }
+ code = CodeMsg.deleteFailed;
+ message = CodeMsg.deleteFailedMsg;
+ }
+ respWrite(code, message, null, respWriter);
+ }
+
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ doPost(request, response);
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ doDelete(request, response);
+ }
+}
diff --git a/src/main/java/servlet/usrManagement/LoginServlet.java b/src/main/java/servlet/usrManagement/LoginServlet.java
new file mode 100644
index 0000000000000000000000000000000000000000..d56ec51d1dda92ccfe66fc0f357eb5acc37536ef
--- /dev/null
+++ b/src/main/java/servlet/usrManagement/LoginServlet.java
@@ -0,0 +1,71 @@
+package servlet.usrManagement;
+
+import bean.User;
+import factory.DaoFactory;
+import log.CusLogger;
+import org.json.JSONObject;
+import utils.CodeMsg;
+import utils.EncryptUtil;
+import utils.JDBCUtils;
+
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.sql.Connection;
+
+import static utils.ServletUtils.getJsonData;
+import static utils.ServletUtils.respWrite;
+
+@WebServlet(name = "LoginServlet", value = "/user/login")
+public class LoginServlet extends HttpServlet {
+
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ doPost(request, response);
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ // 状态码
+ String code = CodeMsg.success;
+ // 提示信息
+ String message = CodeMsg.successMsg;
+ PrintWriter respWriter = null;
+ try {
+ respWriter = response.getWriter();
+ } catch (IOException e) {
+ CusLogger.saveError(e.getMessage());
+ return;
+ }
+ JSONObject loginData = getJsonData(request);
+ String tel = loginData.getString("tel");
+ String pwd = loginData.getString("pwd");
+ if ("".equals(tel) || "".equals(pwd)) {
+ code = CodeMsg.fieldIsMissing;
+ message = CodeMsg.fieldIsMissingMsg;
+ respWrite(code,message,null,respWriter);
+ return;
+ }
+ pwd = EncryptUtil.encrypt(pwd);
+ Connection conn = JDBCUtils.getConnectionDruid();
+ User user = DaoFactory.getUserDaoInstance().login(conn,tel);
+ if (user == null) {
+ code = CodeMsg.usrDoesNotExist;
+ message = CodeMsg.usrDoesNotExistMsg;
+ } else if (!user.getPwd().equals(pwd)) {
+ code = CodeMsg.wrongPwd;
+ message = CodeMsg.wrongPwdMsg;
+ } else {
+ code = CodeMsg.success;
+ message = CodeMsg.successMsg;
+ respWrite(code,message,user,respWriter);
+ return;
+ }
+ respWrite(code,message,null,respWriter);
+
+ }
+}
diff --git a/src/main/java/servlet/usrManagement/RegisterServlet.java b/src/main/java/servlet/usrManagement/RegisterServlet.java
new file mode 100644
index 0000000000000000000000000000000000000000..d3f3380c69dbc1f90234f19311b4bd3b5ed5dcdd
--- /dev/null
+++ b/src/main/java/servlet/usrManagement/RegisterServlet.java
@@ -0,0 +1,116 @@
+package servlet.usrManagement;
+
+import bean.User;
+import factory.DaoFactory;
+import log.CusLogger;
+import org.json.JSONObject;
+import utils.CodeMsg;
+import utils.EncryptUtil;
+import utils.JDBCUtils;
+
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.sql.Connection;
+
+import static utils.ServletUtils.getJsonData;
+import static utils.ServletUtils.respWrite;
+
+/**
+ * @author zdy
+ */
+@WebServlet(name = "RegisterServlet", value = "/user/register")
+public class RegisterServlet extends HttpServlet {
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) {
+ doPost(request, response);
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) {
+ User user = new User();
+ // 状态码
+ String code = CodeMsg.success;
+ // 提示信息
+ String message = CodeMsg.successMsg;
+ PrintWriter respWriter = null;
+ try {
+ respWriter = response.getWriter();
+ } catch (IOException e) {
+ CusLogger.saveError(e.getMessage());
+ return;
+ }
+ // 获取请求参数(json类型)
+ JSONObject registerData = getJsonData(request);
+ String tel = "";
+ String name = "";
+ String pwd = "";
+ String gender = "";
+ int age = 0;
+ int emplmtState = 1;
+ String profession = "";
+ int incm = 0;
+ int whetherTheFloatingPopulation = 1;
+ String address = "";
+ try {
+ tel = registerData.getString("tel");
+ name = registerData.getString("name");
+ pwd = registerData.getString("pwd");
+ gender = registerData.getString("gender");
+ age = registerData.getInt("age");
+ emplmtState = registerData.getInt("emplmtState");
+ profession = registerData.getString("profession");
+ incm = registerData.getInt("incm");
+ whetherTheFloatingPopulation = registerData.getInt("whetherTheFloatingPopulation");
+ address = registerData.getString("address");
+ } catch (NumberFormatException e) {
+ code = CodeMsg.fieldIsMissing;
+ message = CodeMsg.fieldIsMissingMsg;
+ CusLogger.saveInfo(CodeMsg.fieldIsMissingMsg);
+ respWrite(code, message, null, respWriter);
+ return;
+ } catch (Exception e) {
+ code = CodeMsg.addFailed;
+ message = CodeMsg.addFailedMsg;
+ CusLogger.saveInfo(message);
+ respWrite(code, message, null, respWriter);
+ return;
+ }
+ // 数据验证
+ if ("".equals(tel) || "".equals(name) || "".equals(pwd) || "".equals(gender) || "".equals(profession)) {
+ code = CodeMsg.fieldIsMissing;
+ message = CodeMsg.fieldIsMissingMsg;
+ CusLogger.saveInfo(CodeMsg.fieldIsMissingMsg);
+ } else if (age < 0 || incm < 0) {
+ code = CodeMsg.addFailed;
+ message = CodeMsg.addFailedMsg;
+ CusLogger.saveInfo(message);
+ } else {
+ // 密码加密
+ pwd = EncryptUtil.encrypt(pwd);
+ // user
+ user = new User(tel, name, pwd, gender, age, emplmtState, profession, incm,whetherTheFloatingPopulation,address);
+ Connection conn = JDBCUtils.getConnectionDruid();
+ int res = DaoFactory.getUserDaoInstance().register(conn, user);
+ switch (res) {
+ case 0:
+ CusLogger.saveUserLog(user + "注册成功");
+ break;
+ case 1:
+ code = CodeMsg.existingPhnNum;
+ message = CodeMsg.existingPhnNumMsg;
+ CusLogger.saveInfo(tel + message);
+ break;
+ default:
+ code = CodeMsg.addFailed;
+ message = CodeMsg.addFailedMsg;
+ CusLogger.saveInfo(user + message);
+ }
+ JDBCUtils.close(conn, null, null);
+ }
+ respWrite(code, message, user, respWriter);
+ }
+}
diff --git a/src/main/java/servlet/usrManagement/UpdateServlet.java b/src/main/java/servlet/usrManagement/UpdateServlet.java
new file mode 100644
index 0000000000000000000000000000000000000000..e11efff7a6165a05c0a6d72edeb937796f4ec832
--- /dev/null
+++ b/src/main/java/servlet/usrManagement/UpdateServlet.java
@@ -0,0 +1,108 @@
+package servlet.usrManagement;
+
+import bean.User;
+import factory.DaoFactory;
+import log.CusLogger;
+import org.json.JSONObject;
+import utils.CodeMsg;
+import utils.EncryptUtil;
+import utils.JDBCUtils;
+
+import javax.servlet.*;
+import javax.servlet.http.*;
+import javax.servlet.annotation.*;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.sql.Connection;
+
+import static utils.ServletUtils.getJsonData;
+import static utils.ServletUtils.respWrite;
+
+@WebServlet(name = "UpdateServlet", value = "/user/update")
+public class UpdateServlet extends HttpServlet {
+ @Override
+ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ doPost(req,resp);
+ }
+
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ doPost(request,response);
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ User user;
+ // 状态码
+ String code = CodeMsg.success;
+ // 提示信息
+ String message = CodeMsg.successMsg;
+ PrintWriter respWriter = null;
+ try {
+ respWriter = response.getWriter();
+ } catch (IOException e) {
+ CusLogger.saveError(e.getMessage());
+ return;
+ }
+ // 获取请求参数(json类型)
+ JSONObject registerData = getJsonData(request);
+ String preTel = "";
+ String tel = "";
+ String name = "";
+ String pwd = "";
+ String gender = "";
+ int age = 0;
+ int emplmtState = 1;
+ String profession = "";
+ int incm = 0;
+ int whetherTheFloatingPopulation = 1;
+ String address = "";
+ try {
+ preTel = registerData.getString("preTel");
+ tel = registerData.getString("tel");
+ name = registerData.getString("name");
+ pwd = registerData.getString("pwd");
+ gender = registerData.getString("gender");
+ age = registerData.getInt("age");
+ emplmtState = registerData.getInt("emplmtState");
+ profession = registerData.getString("profession");
+ incm = registerData.getInt("incm");
+ whetherTheFloatingPopulation = registerData.getInt("whetherTheFloatingPopulation");
+ address = registerData.getString("addresss");
+ } catch (NumberFormatException e) {
+ code = CodeMsg.fieldIsMissing;
+ message = CodeMsg.fieldIsMissingMsg;
+ CusLogger.saveInfo(CodeMsg.fieldIsMissingMsg);
+ respWrite(code, message, null, respWriter);
+ return;
+ }
+ // 数据验证
+ if ("".equals(tel) || "".equals(name) || "".equals(pwd) || "".equals(gender) || "".equals(profession)) {
+ code = CodeMsg.fieldIsMissing;
+ message = CodeMsg.fieldIsMissingMsg;
+ CusLogger.saveInfo(CodeMsg.fieldIsMissingMsg);
+ } else if (age < 0 || incm < 0) {
+ code = CodeMsg.addFailed;
+ message = CodeMsg.addFailedMsg;
+ CusLogger.saveInfo(message);
+ } else {
+ // 密码加密
+ pwd = EncryptUtil.encrypt(pwd);
+ // user
+ user = new User(tel, name, pwd, gender, age, emplmtState, profession, incm,whetherTheFloatingPopulation,address);
+ Connection conn = JDBCUtils.getConnectionDruid();
+ int res = DaoFactory.getUserDaoInstance().update(conn, preTel,user);
+ if (res == 0) {
+ code = CodeMsg.success;
+ message = CodeMsg.successMsg;
+ respWrite(code, message, user, respWriter);
+ JDBCUtils.close(conn, null, null);
+ return;
+ } else if (res == 2) {
+ code = CodeMsg.usrDoesNotExist;
+ message = CodeMsg.usrDoesNotExistMsg;
+ }
+ }
+ respWrite(code, message, null, respWriter);
+ }
+}
diff --git a/src/main/java/utils/CodeMsg.java b/src/main/java/utils/CodeMsg.java
new file mode 100644
index 0000000000000000000000000000000000000000..5101c32b9b1d1c89c1f74f14bd98c00bf44a8c1a
--- /dev/null
+++ b/src/main/java/utils/CodeMsg.java
@@ -0,0 +1,86 @@
+package utils;
+
+/**
+ * @author zdy
+ */
+public class CodeMsg {
+ public static String success = "200";
+ public static String successMsg = "成功";
+ /**
+ * 字段缺失
+ */
+ public static String fieldIsMissing = "2001";
+ public static String fieldIsMissingMsg = "字段缺失";
+
+ /**
+ * map转为json数据失败
+ */
+ public static String toJsonFailed = "2002";
+ public static String toJsonFailMsg = "转为json数据失败";
+
+
+ /**
+ * 登录失败
+ */
+ public static String loginFailed = "2101";
+ public static String loginFailMsg = "登陆失败";
+
+ /**
+ * 密码错误
+ */
+ public static String wrongPwd = "2103";
+ public static String wrongPwdMsg = "密码错误";
+ /**
+ * 用户不存在
+ */
+ public static String usrDoesNotExist = "2104";
+ public static String usrDoesNotExistMsg = "用户不存在";
+
+
+ /**
+ * 添加失败
+ */
+ public static String addFailed = "2201";
+ public static String addFailedMsg = "添加失败";
+ /**
+ * 手机号重复
+ */
+ public static String existingPhnNum = "2202";
+ public static String existingPhnNumMsg = "此手机号已被注册";
+
+
+ /**
+ * 更新失败
+ */
+ public static String updateFailed = "2301";
+ public static String updateFailedMsg = "更新失败";
+
+ /**
+ * 登记为商户/企业/物业失败
+ */
+ public static String registerAsMerchFailed = "2401";
+ public static String registerAsMerchFailedMsg = "登记为商户/企业/物业失败";
+ /**
+ * 商户已存在
+ */
+ public static String merchAlreadyExists = "2402";
+ public static String merchAlreadyExistsMsg = "商户已存在";
+ /**
+ * 错误的商户类型
+ */
+ public static String wrongBusTyp = "2403";
+ public static String wrongBusTypMsg = "错误的商户类型";
+
+ /**
+ * 非法的星数
+ */
+ public static String illegalNumOfStars = "2502";
+ public static String illegalNumOfStarsMsg = "非法的星数";
+
+ /**
+ * 删除失败
+ */
+ public static String deleteFailed = "2601";
+ public static String deleteFailedMsg = "删除失败";
+
+}
diff --git a/src/main/java/utils/EncryptUtil.java b/src/main/java/utils/EncryptUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..30b82e8d3d5331bf9269c849d7401eedf567a509
--- /dev/null
+++ b/src/main/java/utils/EncryptUtil.java
@@ -0,0 +1,176 @@
+package utils;
+
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
+
+import javax.crypto.Cipher;
+import javax.crypto.SecretKey;
+import javax.crypto.SecretKeyFactory;
+import javax.crypto.spec.DESKeySpec;
+
+/**
+ * 加密工具类
+ *
+ * md5加密出来的长度是32位
+ *
+ * sha加密出来的长度是40位
+ * @author zdy
+ */
+public final class EncryptUtil {
+
+ private static final String PASSWORD_CRYPT_KEY = "88444488";
+
+ private final static String DES = "DES";
+
+ /**
+ * 二次加密 先sha-1加密再用MD5加密
+ *
+ * @param src
+ * @return
+ */
+ public final static String md5AndSha(String src) {
+ return md5(sha(src));
+ }
+
+ /**
+ * 二次加密 先MD5加密再用sha-1加密
+ *
+ * @param src
+ * @return
+ */
+ public final static String shaAndMd5(String src) {
+ return sha(md5(src));
+ }
+
+ /**
+ * md5加密
+ *
+ * @param src
+ * @return
+ */
+ public final static String md5(String src) {
+ return encrypt(src, "md5");
+ }
+
+ /**
+ * sha-1加密
+ *
+ * @param src
+ * @return
+ */
+ public final static String sha(String src) {
+ return encrypt(src, "sha-1");
+ }
+
+ /**
+ * md5或者sha-1加密
+ *
+ * @param src 要加密的内容
+ * @param algorithmName 加密算法名称:md5或者sha-1,不区分大小写
+ * @return
+ */
+ private final static String encrypt(String src, String algorithmName) {
+ if (src == null || "".equals(src.trim())) {
+ throw new IllegalArgumentException("请输入要加密的内容");
+ }
+ if (algorithmName == null || "".equals(algorithmName.trim())) {
+ algorithmName = "md5";
+ }
+ String encryptText = null;
+ try {
+ MessageDigest m = MessageDigest.getInstance(algorithmName);
+ m.update(src.getBytes("UTF8"));
+ byte s[] = m.digest();
+ // m.digest(src.getBytes("UTF8"));
+ return hex(s);
+ } catch (NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+ return encryptText;
+ }
+
+ /**
+ * 密码加密
+ *
+ * @param password
+ * @return
+ * @throws Exception
+ */
+ public final static String encrypt(String password) {
+ try {
+ return byte2hex(encrypt(password.getBytes(), PASSWORD_CRYPT_KEY.getBytes()));
+ } catch (Exception e) {
+ }
+ return null;
+ }
+
+ /**
+ * 加密
+ *
+ * @param src 数据源
+ * @param key 密钥,长度必须是8的倍数
+ * @return 返回加密后的数据
+ * @throws Exception
+ */
+ private static byte[] encrypt(byte[] src, byte[] key) throws Exception {
+ // DES算法要求有一个可信任的随机数源
+ SecureRandom sr = new SecureRandom();
+ // 从原始密匙数据创建DESKeySpec对象
+ DESKeySpec dks = new DESKeySpec(key);
+ // 创建一个密匙工厂,然后用它把DESKeySpec转换成一个SecretKey对象
+ SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
+ SecretKey securekey = keyFactory.generateSecret(dks);
+ // Cipher对象实际完成加密操作
+ Cipher cipher = Cipher.getInstance(DES);
+ // 用密匙初始化Cipher对象
+ cipher.init(Cipher.ENCRYPT_MODE, securekey, sr);
+ // 现在,获取数据并加密正式执行加密操作
+ return cipher.doFinal(src);
+ }
+
+ /**
+ * 二行制转字符串
+ *
+ * @param b
+ * @return
+ */
+ private final static String byte2hex(byte[] b) {
+ String hs = "";
+ String stmp = "";
+ for (int n = 0; n < b.length; n++) {
+ stmp = (java.lang.Integer.toHexString(b[n] & 0XFF));
+ if (stmp.length() == 1) {
+ hs = hs + "0" + stmp;
+ } else {
+ hs = hs + stmp;
+ }
+
+ }
+ return hs.toUpperCase();
+ }
+
+ /**
+ * 返回十六进制字符串
+ *
+ * @param arr
+ * @return
+ */
+ private final static String hex(byte[] arr) {
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < arr.length; ++i) {
+ sb.append(Integer.toHexString((arr[i] & 0xFF) | 0x100).substring(1, 3));
+ }
+ return sb.toString();
+ }
+
+
+// public static void main(String[] args) {
+// String encrypt = EncryptUtil.encrypt("12345678");
+// System.out.println(encrypt);
+// }
+
+}
diff --git a/src/main/java/utils/JDBCUtils.java b/src/main/java/utils/JDBCUtils.java
new file mode 100644
index 0000000000000000000000000000000000000000..69c9bc0192e89e3f622eec062cad8d67ab8e5969
--- /dev/null
+++ b/src/main/java/utils/JDBCUtils.java
@@ -0,0 +1,54 @@
+package utils;
+
+import com.alibaba.druid.pool.DruidDataSourceFactory;
+
+import javax.sql.DataSource;
+import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Properties;
+
+/**
+ * @author zdy
+ */
+public class JDBCUtils {
+ /**
+ * 使用Druid连接池
+ */
+ private static DataSource source=null;
+ static {
+ try {
+ Properties pro=new Properties();
+ InputStream is = JDBCUtils.class.getClassLoader().getResourceAsStream("druid.properties");
+ pro.load(is);
+ //加载驱动
+ source = DruidDataSourceFactory.createDataSource(pro);
+ }catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static Connection getConnectionDruid(){
+ Connection conn = null;
+ try {
+ conn = source.getConnection();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ return conn;
+ }
+
+ public static void close(Connection conn, Statement stat, ResultSet rs){
+ if(conn != null){
+ try {conn.close();} catch (SQLException e) {e.printStackTrace();}
+ }
+ if(stat != null){
+ try {stat.close();} catch (SQLException e) {e.printStackTrace();}
+ }
+ if(rs != null){
+ try {rs.close();} catch (SQLException e) {e.printStackTrace();}
+ }
+ }
+}
diff --git a/src/main/java/utils/OnLineList.java b/src/main/java/utils/OnLineList.java
new file mode 100644
index 0000000000000000000000000000000000000000..31b5d3e501f783c5d08db370952821196a3552af
--- /dev/null
+++ b/src/main/java/utils/OnLineList.java
@@ -0,0 +1,7 @@
+package utils;
+
+import java.util.HashSet;
+
+public class OnLineList {
+ public static HashSet list = new HashSet<>();
+}
diff --git a/src/main/java/utils/ServletUtils.java b/src/main/java/utils/ServletUtils.java
new file mode 100644
index 0000000000000000000000000000000000000000..09e7c4b24816170aaeb38f9ffb039f56bc306385
--- /dev/null
+++ b/src/main/java/utils/ServletUtils.java
@@ -0,0 +1,53 @@
+package utils;
+
+import bean.User;
+import com.google.gson.Gson;
+import log.CusLogger;
+import org.json.JSONObject;
+
+import javax.servlet.ServletInputStream;
+import javax.servlet.http.HttpServletRequest;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintWriter;
+import java.util.HashMap;
+import java.util.Map;
+
+public class ServletUtils {
+ public static void respWrite(String code, String message, Object data, PrintWriter respWriter) {
+ Map map = new HashMap(3);
+ map.put("code", code);
+ map.put("message", message);
+ map.put("data", data);
+ String respStr = "";
+ try {
+ respStr = new Gson().toJson(map);
+ } catch (Exception e) {
+ CusLogger.saveError(CodeMsg.toJsonFailMsg);
+ }
+ if (respWriter != null) {
+ respWriter.print(respStr);
+ } else {
+ CusLogger.saveError("respWriter is null");
+ }
+ }
+
+ public static JSONObject getJsonData(HttpServletRequest request) {
+ JSONObject jsonData = null;
+ try {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ ServletInputStream is = request.getInputStream();
+ byte[] buffer = new byte[1024];
+
+ //先把字节流读取到buffer 然后再写入outputStream
+ while (is.read(buffer) > 0) {
+ outputStream.write(buffer);
+ }
+ outputStream.close();
+ jsonData = new JSONObject(outputStream.toString("utf-8"));
+ } catch (Exception e) {
+ CusLogger.saveError(e.getMessage());
+ return null;
+ }
+ return jsonData;
+ }
+}
diff --git a/src/main/resources/druid.properties b/src/main/resources/druid.properties
new file mode 100644
index 0000000000000000000000000000000000000000..f1b9a9d6be8f577101d44fa27458c7d864b7e28c
--- /dev/null
+++ b/src/main/resources/druid.properties
@@ -0,0 +1,9 @@
+url=jdbc:mysql://47.93.88.66:3306/test?rewriteBatchedStatements=true
+username=root
+password=123456
+driverClassName=com.mysql.cj.jdbc.Driver
+
+initialSize=10
+maxActive=20
+maxWait=1000
+filters=wall
diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties
new file mode 100644
index 0000000000000000000000000000000000000000..29df08ab82f92e5cd6efc006dd44f3d87a5deba0
--- /dev/null
+++ b/src/main/resources/log4j.properties
@@ -0,0 +1,47 @@
+#配置根Logger
+#改代码表示输输出info级别以上的日志,文件分别输出,一个是file,一个是error
+log4j.rootLogger=info,file,error
+
+#配置file日志信息输出目的地Appender
+#定义名为file的输出端是每天产生一个日志文件
+log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
+#指定日志信息的最低输出级别位INFO,默认为DEBUG。
+log4j.appender.file.Threshold=INFO
+#指定当前消息输出到jpm/log4j/log.log文件中
+log4j.appender.file.File=log/log.log
+#指定按天来滚动日志文件
+log4j.appender.file.DatePattern=yyyy-MM-dd
+#配置日志信息的格式(布局)Layout是可以灵活地指定布局模式
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+#格式化日志,Log4j采用类似C语言中的printf函数的打印格式格式化日志信息
+log4j.appender.file.layout.ConversionPattern=[%d{yyyy-MM-ddHH:mm:ss}][%-5p][jpm-%c{1}-%M(%L)]-%m%n
+#指定输出信息的编码
+log4j.appender.file.encoding=UTF-8
+
+#配置error日志信息输出目的地Appender
+#定义名为error的输出端是每天产生一个日志文件
+log4j.appender.error=org.apache.log4j.DailyRollingFileAppender
+#指定日志信息的最低输出级别位ERROR,默认为DEBUG。
+log4j.appender.error.Threshold=ERROR
+#指定当前消息输出到error.log文件中
+log4j.appender.error.File=log/error.log
+#指定按月来滚动日志文件
+log4j.appender.error.DatePattern=yyyy-MM
+#配置日志信息的格式(布局)Layout是可以灵活地指定布局模式
+log4j.appender.error.layout=org.apache.log4j.PatternLayout
+#格式化日志,Log4j采用类似C语言中的printf函数的打印格式格式化日志信息
+log4j.appender.error.layout.ConversionPattern=[%d{yyyy-MM-ddHH:mm:ss}][%-5p][jpm-%c{1}-%M(%L)]-%m%n
+#指定输出信息的编码
+#log4j.appender.error.encoding=UTF-8
+
+#使某个功能的日志单独输出到指定的日志文件
+log4j.logger.saveUserLog=INFO,saveUserLog
+#该配置就是让job的日志只输出到自己指定的日志文件中,表示Logger不会在父Logger的appender里输出,默认为true。
+log4j.additivity.saveUserLog=false
+log4j.appender.saveUserLog=org.apache.log4j.DailyRollingFileAppender
+log4j.appender.saveUserLog.File=log/saveUserLog.log
+log4j.appender.saveUserLog.DatePattern=yyyy-MM-dd
+log4j.appender.saveUserLog.Append=true
+log4j.appender.saveUserLog.layout=org.apache.log4j.PatternLayout
+log4j.appender.saveUserLog.layout.ConversionPattern=%m%n
+log4j.appender.error.encoding=UTF-8
\ No newline at end of file
diff --git a/web/WEB-INF/web.xml b/web/WEB-INF/web.xml
new file mode 100644
index 0000000000000000000000000000000000000000..a942c54dc59b29774e6546277398ad7b23742227
--- /dev/null
+++ b/web/WEB-INF/web.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+ characterFilter
+ filter.CharacterFilter
+
+
+ characterFilter
+ /*
+
+
+
\ No newline at end of file
diff --git a/web/index.jsp b/web/index.jsp
new file mode 100644
index 0000000000000000000000000000000000000000..77d31b3447de5d3e125c3ab6136aa06fe46ec289
--- /dev/null
+++ b/web/index.jsp
@@ -0,0 +1,16 @@
+<%--
+ Created by IntelliJ IDEA.
+ bean.User: zdy
+ Date: 2022/6/8
+ Time: 15:40
+ To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+
+
+ $Title$
+
+
+ $END$
+
+