mirror of
https://github.com/ZSCNetSupportDept/WechatTicketSystem.git
synced 2025-10-30 01:46:18 +08:00
add duplicated check for member sign
This commit is contained in:
@@ -32,27 +32,30 @@ public class SignHandler implements WxMpMessageHandler {
|
|||||||
String msg = wxMessage.getContent();
|
String msg = wxMessage.getContent();
|
||||||
TextBuilder out = WxMpXmlOutMessage.TEXT().toUser(wxMessage.getFromUserName()).fromUser(wxMessage.getToUserName());
|
TextBuilder out = WxMpXmlOutMessage.TEXT().toUser(wxMessage.getFromUserName()).fromUser(wxMessage.getToUserName());
|
||||||
Matcher mat = pat.matcher(msg);
|
Matcher mat = pat.matcher(msg);
|
||||||
|
|
||||||
|
root:
|
||||||
if (mat.find()) {
|
if (mat.find()) {
|
||||||
int id = Integer.parseInt(mat.group(1));
|
int id = Integer.parseInt(mat.group(1));
|
||||||
try (Connection conn = SQLCore.ds.getConnection()) {
|
try (Connection conn = SQLCore.ds.getConnection()) {
|
||||||
PreparedStatement ps = conn.prepareStatement("SELECT wechat FROM auth WHERE id=?");
|
switch (checkID(conn, id)) {
|
||||||
ps.setInt(1, id);
|
case -1:
|
||||||
ResultSet rs = ps.executeQuery();
|
out.content("无效ID。");
|
||||||
if (rs.next()) {
|
break root;
|
||||||
if (rs.getString("wechat") != null) {
|
case -2:
|
||||||
out.content("该ID已登记过。");
|
out.content("该ID已登记过。");
|
||||||
} else {
|
break root;
|
||||||
ps = conn.prepareStatement("UPDATE auth SET wechat=? WHERE id=?");
|
}
|
||||||
ps.setString(1, wxMessage.getFromUserName());
|
if (checkDuplicated(conn, wxMessage.getFromUserName())) {
|
||||||
ps.setInt(2, id);
|
out.content("你的微信已经登记过。");
|
||||||
if (ps.executeUpdate() == 1) {
|
break root;
|
||||||
out.content("登记成功。");
|
}
|
||||||
} else {
|
PreparedStatement ps = conn.prepareStatement("UPDATE auth SET wechat=? WHERE id=?");
|
||||||
out.content("登记失败,请联系管理员。");
|
ps.setString(1, wxMessage.getFromUserName());
|
||||||
}
|
ps.setInt(2, id);
|
||||||
}
|
if (ps.executeUpdate() == 1) {
|
||||||
|
out.content("登记成功。");
|
||||||
} else {
|
} else {
|
||||||
out.content("无效ID。");
|
out.content("登记失败,请联系管理员。");
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -64,4 +67,22 @@ public class SignHandler implements WxMpMessageHandler {
|
|||||||
return out.build();
|
return out.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int checkID(Connection conn, int id) throws SQLException {
|
||||||
|
PreparedStatement ps = conn.prepareStatement("SELECT wechat FROM auth WHERE id=?");
|
||||||
|
ps.setInt(1, id);
|
||||||
|
ResultSet rs = ps.executeQuery();
|
||||||
|
if (rs.next()) {
|
||||||
|
return rs.getString("wechat") != null ? -2 : 0;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean checkDuplicated(Connection conn, String wechat) throws SQLException {
|
||||||
|
PreparedStatement ps = conn.prepareStatement("SELECT wechat FROM auth WHERE wechat=?");
|
||||||
|
ps.setString(1, wechat);
|
||||||
|
ResultSet rs = ps.executeQuery();
|
||||||
|
return rs.next();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user