mirror of
https://github.com/ZSCNetSupportDept/WechatTicketSystem.git
synced 2025-10-29 16:14:16 +08:00
Merge branch 'release/1.3'
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
|||||||
<name>WechatTicketSystem</name>
|
<name>WechatTicketSystem</name>
|
||||||
<groupId>love.sola.netsupport</groupId>
|
<groupId>love.sola.netsupport</groupId>
|
||||||
<artifactId>WechatTicketSystem</artifactId>
|
<artifactId>WechatTicketSystem</artifactId>
|
||||||
<version>1.2-SNAPSHOT</version>
|
<version>1.3</version>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package love.sola.netsupport.api.admin;
|
package love.sola.netsupport.api;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import love.sola.netsupport.api.Response;
|
|
||||||
import love.sola.netsupport.enums.Attribute;
|
import love.sola.netsupport.enums.Attribute;
|
||||||
import love.sola.netsupport.sql.SQLCore;
|
import love.sola.netsupport.sql.SQLCore;
|
||||||
import love.sola.netsupport.util.ParseUtil;
|
import love.sola.netsupport.util.ParseUtil;
|
||||||
@@ -24,7 +23,7 @@ import java.util.Map;
|
|||||||
* Don't modify this source without my agreement
|
* Don't modify this source without my agreement
|
||||||
* ***********************************************
|
* ***********************************************
|
||||||
*/
|
*/
|
||||||
@WebServlet(name = "CheckSession", urlPatterns = "/api/checksession", loadOnStartup = 43)
|
@WebServlet(name = "CheckSession", urlPatterns = "/api/checksession", loadOnStartup = 11)
|
||||||
public class CheckSession extends HttpServlet {
|
public class CheckSession extends HttpServlet {
|
||||||
|
|
||||||
private Gson gson = SQLCore.gson;
|
private Gson gson = SQLCore.gson;
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package love.sola.netsupport.api.admin;
|
package love.sola.netsupport.api;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import love.sola.netsupport.api.Response;
|
|
||||||
import love.sola.netsupport.enums.Access;
|
import love.sola.netsupport.enums.Access;
|
||||||
import love.sola.netsupport.enums.Attribute;
|
import love.sola.netsupport.enums.Attribute;
|
||||||
import love.sola.netsupport.pojo.Operator;
|
import love.sola.netsupport.pojo.Operator;
|
||||||
@@ -31,7 +30,7 @@ import java.io.PrintWriter;
|
|||||||
* ***********************************************
|
* ***********************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@WebServlet(name = "Login", urlPatterns = "/api/admin/login", loadOnStartup = 31)
|
@WebServlet(name = "Login", urlPatterns = "/api/admin/login", loadOnStartup = 12)
|
||||||
public class Login extends HttpServlet {
|
public class Login extends HttpServlet {
|
||||||
|
|
||||||
private Gson gson = SQLCore.gson;
|
private Gson gson = SQLCore.gson;
|
||||||
@@ -36,14 +36,12 @@ public class Response {
|
|||||||
PARAMETER_REQUIRED(-1),
|
PARAMETER_REQUIRED(-1),
|
||||||
ILLEGAL_PARAMETER(-2),
|
ILLEGAL_PARAMETER(-2),
|
||||||
REQUEST_FAILED(-3),
|
REQUEST_FAILED(-3),
|
||||||
AUTHORIZE_FAILED(-9),
|
LENGTH_LIMIT_EXCEEDED(-4),
|
||||||
USER_NOT_FOUND(-11),
|
USER_NOT_FOUND(-11),
|
||||||
TICKET_NOT_FOUND(-12),
|
TICKET_NOT_FOUND(-12),
|
||||||
OPERATOR_NOT_FOUND(-13),
|
OPERATOR_NOT_FOUND(-13),
|
||||||
UNAUTHORIZED(-20),
|
UNAUTHORIZED(-20),
|
||||||
REQUEST_EXPIRED(-21),
|
|
||||||
WRONG_PASSWORD(-22),
|
WRONG_PASSWORD(-22),
|
||||||
INCORRECT_WECHAT(-23),
|
|
||||||
PERMISSION_DENIED(-24),
|
PERMISSION_DENIED(-24),
|
||||||
INTERNAL_ERROR(-90),
|
INTERNAL_ERROR(-90),
|
||||||
DATABASE_ERROR(-91),
|
DATABASE_ERROR(-91),
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package love.sola.netsupport.api.admin.root;
|
package love.sola.netsupport.api.manager;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import love.sola.netsupport.api.Response;
|
import love.sola.netsupport.api.Response;
|
||||||
@@ -28,7 +28,7 @@ import java.io.PrintWriter;
|
|||||||
* Don't modify this source without my agreement
|
* Don't modify this source without my agreement
|
||||||
* ***********************************************
|
* ***********************************************
|
||||||
*/
|
*/
|
||||||
@WebServlet(name = "GetUser",urlPatterns = "/api/admin/getuser",loadOnStartup = 42)
|
@WebServlet(name = "GetUser",urlPatterns = "/api/admin/getuser",loadOnStartup = 41)
|
||||||
public class GetUser extends HttpServlet {
|
public class GetUser extends HttpServlet {
|
||||||
|
|
||||||
private Gson gson = SQLCore.gson;
|
private Gson gson = SQLCore.gson;
|
||||||
@@ -59,7 +59,7 @@ public class GetUser extends HttpServlet {
|
|||||||
return new Response(Response.ResponseCode.UNAUTHORIZED);
|
return new Response(Response.ResponseCode.UNAUTHORIZED);
|
||||||
}
|
}
|
||||||
Operator op = (Operator) session.getAttribute(Attribute.OPERATOR);
|
Operator op = (Operator) session.getAttribute(Attribute.OPERATOR);
|
||||||
if (op.getAccess() != Access.ROOT) {
|
if (op.getAccess() > Access.LEADER) {
|
||||||
return new Response(Response.ResponseCode.PERMISSION_DENIED);
|
return new Response(Response.ResponseCode.PERMISSION_DENIED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
package love.sola.netsupport.api.manager;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import love.sola.netsupport.api.Response;
|
||||||
|
import love.sola.netsupport.config.Settings;
|
||||||
|
import love.sola.netsupport.enums.Access;
|
||||||
|
import love.sola.netsupport.enums.Attribute;
|
||||||
|
import love.sola.netsupport.enums.Status;
|
||||||
|
import love.sola.netsupport.pojo.Operator;
|
||||||
|
import love.sola.netsupport.pojo.Ticket;
|
||||||
|
import love.sola.netsupport.pojo.User;
|
||||||
|
import love.sola.netsupport.sql.SQLCore;
|
||||||
|
import love.sola.netsupport.util.Checker;
|
||||||
|
import love.sola.netsupport.util.ParseUtil;
|
||||||
|
import love.sola.netsupport.wechat.Command;
|
||||||
|
import me.chanjar.weixin.common.session.WxSession;
|
||||||
|
import org.hibernate.HibernateException;
|
||||||
|
import org.hibernate.Session;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ***********************************************
|
||||||
|
* Created by Sola on 2015/12/22.
|
||||||
|
* Don't modify this source without my agreement
|
||||||
|
* ***********************************************
|
||||||
|
*/
|
||||||
|
@WebServlet(name = "TicketPush",urlPatterns = "/api/admin/ticketpush",loadOnStartup = 42)
|
||||||
|
public class TicketPush extends HttpServlet{
|
||||||
|
|
||||||
|
private Gson gson = SQLCore.gson;
|
||||||
|
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
doGet(request, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
request.setCharacterEncoding("utf-8");
|
||||||
|
response.setCharacterEncoding("utf-8");
|
||||||
|
response.addHeader("Content-type", "application/json;charset=utf-8");
|
||||||
|
PrintWriter out = response.getWriter();
|
||||||
|
String json = gson.toJson(push(request));
|
||||||
|
out.println(ParseUtil.parseJsonP(request, json));
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Response push(HttpServletRequest request) {
|
||||||
|
String uid = request.getParameter("uid");
|
||||||
|
String desc = request.getParameter("desc");
|
||||||
|
if (Checker.hasNull(uid, desc)) {
|
||||||
|
return new Response(Response.ResponseCode.PARAMETER_REQUIRED);
|
||||||
|
}
|
||||||
|
if (desc.length() > Settings.MAX_DESC_LENGTH) {
|
||||||
|
return new Response(Response.ResponseCode.LENGTH_LIMIT_EXCEEDED);
|
||||||
|
}
|
||||||
|
|
||||||
|
WxSession session = Checker.isAuthorized(request, Command.LOGIN);
|
||||||
|
if (session == null) {
|
||||||
|
return new Response(Response.ResponseCode.UNAUTHORIZED);
|
||||||
|
}
|
||||||
|
Operator op = (Operator) session.getAttribute(Attribute.OPERATOR);
|
||||||
|
if (op.getAccess() > Access.LEADER) {
|
||||||
|
return new Response(Response.ResponseCode.PERMISSION_DENIED);
|
||||||
|
}
|
||||||
|
|
||||||
|
try (Session s = SQLCore.sf.openSession()) {
|
||||||
|
s.beginTransaction();
|
||||||
|
User u = s.get(User.class, Long.parseLong(uid));
|
||||||
|
if (u == null) {
|
||||||
|
return new Response(Response.ResponseCode.USER_NOT_FOUND);
|
||||||
|
}
|
||||||
|
Ticket t = new Ticket(null, u, desc, null, "Pushed By Admin", null, op, Status.UNCHECKED);
|
||||||
|
s.save(t);
|
||||||
|
s.getTransaction().commit();
|
||||||
|
return new Response(Response.ResponseCode.OK, t);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return new Response(Response.ResponseCode.ILLEGAL_PARAMETER);
|
||||||
|
} catch (HibernateException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return new Response(Response.ResponseCode.DATABASE_ERROR, e.getMessage());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return new Response(Response.ResponseCode.INTERNAL_ERROR, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
package love.sola.netsupport.api.admin.root;
|
package love.sola.netsupport.api.root;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import love.sola.netsupport.enums.Access;
|
import love.sola.netsupport.enums.Access;
|
||||||
import love.sola.netsupport.enums.Attribute;
|
import love.sola.netsupport.enums.Attribute;
|
||||||
import love.sola.netsupport.pojo.Operator;
|
import love.sola.netsupport.pojo.Operator;
|
||||||
import love.sola.netsupport.sql.SQLCore;
|
|
||||||
import love.sola.netsupport.util.Checker;
|
import love.sola.netsupport.util.Checker;
|
||||||
import love.sola.netsupport.wechat.Command;
|
import love.sola.netsupport.wechat.Command;
|
||||||
import love.sola.netsupport.wechat.WechatSession;
|
import love.sola.netsupport.wechat.WechatSession;
|
||||||
@@ -27,25 +25,24 @@ import java.util.Enumeration;
|
|||||||
* ***********************************************
|
* ***********************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@WebServlet(name = "Dashboard", urlPatterns = "/api/admin/dashboard", loadOnStartup = 41)
|
@WebServlet(name = "Dashboard", urlPatterns = "/api/root/dashboard", loadOnStartup = 51)
|
||||||
public class DashBoard extends HttpServlet {
|
public class DashBoard extends HttpServlet {
|
||||||
|
|
||||||
private Gson gson = SQLCore.gson;
|
|
||||||
|
|
||||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
doGet(request, response);
|
doGet(request, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("Duplicates")
|
||||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
request.setCharacterEncoding("utf-8");
|
request.setCharacterEncoding("utf-8");
|
||||||
response.setCharacterEncoding("utf-8");
|
response.setCharacterEncoding("utf-8");
|
||||||
response.addHeader("Content-type", "text/plain;charset=utf-8");
|
response.addHeader("Content-type", "text/plain;charset=utf-8");
|
||||||
PrintWriter out = response.getWriter();
|
PrintWriter out = response.getWriter();
|
||||||
print(request, out);
|
process(request, out);
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void print(HttpServletRequest request, PrintWriter out) {
|
private void process(HttpServletRequest request, PrintWriter out) {
|
||||||
WxSession session = Checker.isAuthorized(request, Command.LOGIN);
|
WxSession session = Checker.isAuthorized(request, Command.LOGIN);
|
||||||
if (session == null) {
|
if (session == null) {
|
||||||
out.println("Unauthorized");
|
out.println("Unauthorized");
|
||||||
59
src/main/java/love/sola/netsupport/api/root/FlushCache.java
Normal file
59
src/main/java/love/sola/netsupport/api/root/FlushCache.java
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
package love.sola.netsupport.api.root;
|
||||||
|
|
||||||
|
import love.sola.netsupport.enums.Access;
|
||||||
|
import love.sola.netsupport.enums.Attribute;
|
||||||
|
import love.sola.netsupport.pojo.Operator;
|
||||||
|
import love.sola.netsupport.sql.TableUser;
|
||||||
|
import love.sola.netsupport.util.Checker;
|
||||||
|
import love.sola.netsupport.wechat.Command;
|
||||||
|
import me.chanjar.weixin.common.session.WxSession;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ***********************************************
|
||||||
|
* Created by Sola on 2015/12/15.
|
||||||
|
* Don't modify this source without my agreement
|
||||||
|
* ***********************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
@WebServlet(name = "FlushCache", urlPatterns = "/api/root/flushcache", loadOnStartup = 52)
|
||||||
|
public class FlushCache extends HttpServlet {
|
||||||
|
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
doGet(request, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("Duplicates")
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
request.setCharacterEncoding("utf-8");
|
||||||
|
response.setCharacterEncoding("utf-8");
|
||||||
|
response.addHeader("Content-type", "text/plain;charset=utf-8");
|
||||||
|
PrintWriter out = response.getWriter();
|
||||||
|
process(request, out);
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void process(HttpServletRequest request, PrintWriter out) {
|
||||||
|
WxSession session = Checker.isAuthorized(request, Command.LOGIN);
|
||||||
|
if (session == null) {
|
||||||
|
out.println("Unauthorized");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Operator op = (Operator) session.getAttribute(Attribute.OPERATOR);
|
||||||
|
if (op.getAccess() != Access.ROOT) {
|
||||||
|
out.println("Unauthorized");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
TableUser.flushCache();
|
||||||
|
out.println("Flushed wechat cache");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package love.sola.netsupport.api.admin.root;
|
package love.sola.netsupport.api.root;
|
||||||
|
|
||||||
import love.sola.netsupport.enums.Access;
|
import love.sola.netsupport.enums.Access;
|
||||||
import love.sola.netsupport.enums.Attribute;
|
import love.sola.netsupport.enums.Attribute;
|
||||||
@@ -24,13 +24,14 @@ import java.io.PrintWriter;
|
|||||||
* Don't modify this source without my agreement
|
* Don't modify this source without my agreement
|
||||||
* ***********************************************
|
* ***********************************************
|
||||||
*/
|
*/
|
||||||
@WebServlet(name = "SetPassword",urlPatterns = "/api/admin/setpass",loadOnStartup = 43)
|
@WebServlet(name = "SetPassword",urlPatterns = "/api/root/setpass",loadOnStartup = 53)
|
||||||
public class SetPassword extends HttpServlet{
|
public class SetPassword extends HttpServlet{
|
||||||
|
|
||||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
doGet(request, response);
|
doGet(request, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("Duplicates")
|
||||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
request.setCharacterEncoding("utf-8");
|
request.setCharacterEncoding("utf-8");
|
||||||
response.setCharacterEncoding("utf-8");
|
response.setCharacterEncoding("utf-8");
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package love.sola.netsupport.api.admin;
|
package love.sola.netsupport.api.stuff;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import love.sola.netsupport.api.Response;
|
import love.sola.netsupport.api.Response;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package love.sola.netsupport.api.admin;
|
package love.sola.netsupport.api.stuff;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import love.sola.netsupport.api.Response;
|
import love.sola.netsupport.api.Response;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package love.sola.netsupport.api.admin;
|
package love.sola.netsupport.api.stuff;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import love.sola.netsupport.api.Response;
|
import love.sola.netsupport.api.Response;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package love.sola.netsupport.api.admin;
|
package love.sola.netsupport.api.stuff;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import love.sola.netsupport.api.Response;
|
import love.sola.netsupport.api.Response;
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package love.sola.netsupport.api;
|
package love.sola.netsupport.api.user;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import love.sola.netsupport.api.Response;
|
||||||
import love.sola.netsupport.enums.Attribute;
|
import love.sola.netsupport.enums.Attribute;
|
||||||
import love.sola.netsupport.enums.ISP;
|
import love.sola.netsupport.enums.ISP;
|
||||||
import love.sola.netsupport.pojo.User;
|
import love.sola.netsupport.pojo.User;
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package love.sola.netsupport.api;
|
package love.sola.netsupport.api.user;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import love.sola.netsupport.api.Response;
|
||||||
import love.sola.netsupport.enums.Attribute;
|
import love.sola.netsupport.enums.Attribute;
|
||||||
import love.sola.netsupport.enums.ISP;
|
import love.sola.netsupport.enums.ISP;
|
||||||
import love.sola.netsupport.pojo.User;
|
import love.sola.netsupport.pojo.User;
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package love.sola.netsupport.api;
|
package love.sola.netsupport.api.user;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import love.sola.netsupport.api.Response;
|
||||||
import love.sola.netsupport.enums.Attribute;
|
import love.sola.netsupport.enums.Attribute;
|
||||||
import love.sola.netsupport.pojo.Ticket;
|
import love.sola.netsupport.pojo.Ticket;
|
||||||
import love.sola.netsupport.pojo.User;
|
import love.sola.netsupport.pojo.User;
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
package love.sola.netsupport.api;
|
package love.sola.netsupport.api.user;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import love.sola.netsupport.api.Response;
|
||||||
|
import love.sola.netsupport.config.Settings;
|
||||||
import love.sola.netsupport.enums.Attribute;
|
import love.sola.netsupport.enums.Attribute;
|
||||||
import love.sola.netsupport.pojo.Ticket;
|
import love.sola.netsupport.pojo.Ticket;
|
||||||
import love.sola.netsupport.pojo.User;
|
import love.sola.netsupport.pojo.User;
|
||||||
@@ -51,6 +53,9 @@ public class TicketSubmit extends HttpServlet {
|
|||||||
if (desc == null || desc.isEmpty()) {
|
if (desc == null || desc.isEmpty()) {
|
||||||
return new Response(Response.ResponseCode.PARAMETER_REQUIRED);
|
return new Response(Response.ResponseCode.PARAMETER_REQUIRED);
|
||||||
}
|
}
|
||||||
|
if (desc.length() > Settings.MAX_DESC_LENGTH) {
|
||||||
|
return new Response(Response.ResponseCode.LENGTH_LIMIT_EXCEEDED);
|
||||||
|
}
|
||||||
|
|
||||||
try (Session s = SQLCore.sf.openSession()) {
|
try (Session s = SQLCore.sf.openSession()) {
|
||||||
|
|
||||||
@@ -12,6 +12,8 @@ import love.sola.netsupport.sql.TableConfig;
|
|||||||
@ToString
|
@ToString
|
||||||
public class Settings {
|
public class Settings {
|
||||||
|
|
||||||
|
public static final int MAX_DESC_LENGTH = 255;
|
||||||
|
|
||||||
public static Settings I;
|
public static Settings I;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@@ -29,9 +31,8 @@ public class Settings {
|
|||||||
public int Check_Spam_Cache_Expire_Time;
|
public int Check_Spam_Cache_Expire_Time;
|
||||||
public int Check_Spam_Interval;
|
public int Check_Spam_Interval;
|
||||||
|
|
||||||
public int User_Caching_Time;
|
|
||||||
|
|
||||||
public int User_Session_Max_Inactive;
|
public int User_Session_Max_Inactive;
|
||||||
|
public int User_Wechat_Cache_Expire_Time;
|
||||||
|
|
||||||
//No arg constructor for Yaml.loadAs
|
//No arg constructor for Yaml.loadAs
|
||||||
public Settings() { I = this; }
|
public Settings() { I = this; }
|
||||||
|
|||||||
@@ -15,6 +15,14 @@ import static love.sola.netsupport.config.Lang.lang;
|
|||||||
public class Access {
|
public class Access {
|
||||||
|
|
||||||
public static final int ROOT = 0;
|
public static final int ROOT = 0;
|
||||||
|
public static final int MANAGER = 1;
|
||||||
|
public static final int CO_MANAGER = 2;
|
||||||
|
public static final int LEADER = 3;
|
||||||
|
public static final int CO_LEADER = 4;
|
||||||
|
public static final int ELITE = 5;
|
||||||
|
public static final int ELDER = 6;
|
||||||
|
public static final int MEMBER = 7;
|
||||||
|
public static final int PRE_MEMBER = 8;
|
||||||
public static final int NOLOGIN = 9;
|
public static final int NOLOGIN = 9;
|
||||||
|
|
||||||
public static final Map<Integer, String> inverseMap = new HashMap<>();
|
public static final Map<Integer, String> inverseMap = new HashMap<>();
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ public class Block {
|
|||||||
public static final int DM_13 = 31;
|
public static final int DM_13 = 31;
|
||||||
public static final int DM_14 = 32;
|
public static final int DM_14 = 32;
|
||||||
public static final int DM_15 = 33;
|
public static final int DM_15 = 33;
|
||||||
|
public static final int DM_20 = 34;
|
||||||
|
public static final int DM_21 = 35;
|
||||||
public static final int XH_A = 40;
|
public static final int XH_A = 40;
|
||||||
public static final int XH_B = 41;
|
public static final int XH_B = 41;
|
||||||
public static final int XH_C = 42;
|
public static final int XH_C = 42;
|
||||||
@@ -35,8 +37,6 @@ public class Block {
|
|||||||
public static final int FX_4 = 53;
|
public static final int FX_4 = 53;
|
||||||
public static final int FX_5 = 54;
|
public static final int FX_5 = 54;
|
||||||
public static final int FX_6 = 55;
|
public static final int FX_6 = 55;
|
||||||
public static final int DM_20 = 60;
|
|
||||||
public static final int DM_21 = 61;
|
|
||||||
|
|
||||||
public static final Map<Integer, String> inverseMap = new HashMap<>();
|
public static final Map<Integer, String> inverseMap = new HashMap<>();
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ public class Block {
|
|||||||
AVAILABLE[BM_8] = new int[]{100, 221, 321, 421, 521, 621, 721};
|
AVAILABLE[BM_8] = new int[]{100, 221, 321, 421, 521, 621, 721};
|
||||||
AVAILABLE[BM_9] = new int[]{100, 221, 321, 421, 521, 621};
|
AVAILABLE[BM_9] = new int[]{100, 221, 321, 421, 521, 621};
|
||||||
AVAILABLE[BM_10] = new int[]{111, 239, 339, 439, 558, 658, 758, 858};
|
AVAILABLE[BM_10] = new int[]{111, 239, 339, 439, 558, 658, 758, 858};
|
||||||
AVAILABLE[BM_11] = new int[]{100, 220, 320, 420, 520, 620, 720, 820};
|
AVAILABLE[BM_11] = new int[]{100, 213, 321, 421, 521, 621, 721, 821};
|
||||||
AVAILABLE[DM_12] = new int[]{119, 221, 321, 421, 521, 621, 720};
|
AVAILABLE[DM_12] = new int[]{119, 221, 321, 421, 521, 621, 720};
|
||||||
AVAILABLE[DM_13] = new int[]{120, 222, 322, 422, 522, 622, 722};
|
AVAILABLE[DM_13] = new int[]{120, 222, 322, 422, 522, 622, 722};
|
||||||
AVAILABLE[DM_14] = new int[]{100, 230, 330, 430, 530, 630, 730};
|
AVAILABLE[DM_14] = new int[]{100, 230, 330, 430, 530, 630, 730};
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ public class Status {
|
|||||||
public static final int UNCHECKED = 0;
|
public static final int UNCHECKED = 0;
|
||||||
public static final int ARRANGED = 1;
|
public static final int ARRANGED = 1;
|
||||||
public static final int PUTOFF = 2;
|
public static final int PUTOFF = 2;
|
||||||
|
public static final int REPORTED = 4;
|
||||||
|
public static final int ISP_HANDLED = 7;
|
||||||
public static final int SOLVED = 9;
|
public static final int SOLVED = 9;
|
||||||
|
|
||||||
public static final Map<Integer, String> inverseMap = new HashMap<>();
|
public static final Map<Integer, String> inverseMap = new HashMap<>();
|
||||||
|
|||||||
@@ -42,4 +42,10 @@ public class User {
|
|||||||
private Integer room;
|
private Integer room;
|
||||||
private Long phone;
|
private Long phone;
|
||||||
|
|
||||||
|
|
||||||
|
//System Accounts
|
||||||
|
public static User OFFICIAL_CHINA_UNICOM_XH;
|
||||||
|
public static User OFFICIAL_CHINA_MOBILE_XH;
|
||||||
|
public static User OFFICIAL_CHINA_MOBILE_FX;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ public class SQLCore {
|
|||||||
sr = new StandardServiceRegistryBuilder().configure().build();
|
sr = new StandardServiceRegistryBuilder().configure().build();
|
||||||
sf = new MetadataSources(sr).buildMetadata().buildSessionFactory();
|
sf = new MetadataSources(sr).buildMetadata().buildSessionFactory();
|
||||||
|
|
||||||
|
TableUser.init();
|
||||||
TableOperator.init();
|
TableOperator.init();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -63,8 +63,10 @@ public class TableTicket extends SQLCore {
|
|||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static List<Ticket> unsolvedByBlock(int b) {
|
public static List<Ticket> unsolvedByBlock(int b) {
|
||||||
|
if (b == 0) return unsolved();
|
||||||
try (Session s = SQLCore.sf.openSession()) {
|
try (Session s = SQLCore.sf.openSession()) {
|
||||||
return s.createCriteria(Ticket.class)
|
return s.createCriteria(Ticket.class)
|
||||||
|
.addOrder(Order.desc(Ticket.PROPERTY_SUBMIT_TIME))
|
||||||
.add(Restrictions.ne(Ticket.PROPERTY_STATUS, Status.SOLVED))
|
.add(Restrictions.ne(Ticket.PROPERTY_STATUS, Status.SOLVED))
|
||||||
.createCriteria(Ticket.PROPERTY_USER)
|
.createCriteria(Ticket.PROPERTY_USER)
|
||||||
.add(Restrictions.between(User.PROPERTY_BLOCK, b * 10, (b + 1) * 10 - 1))
|
.add(Restrictions.between(User.PROPERTY_BLOCK, b * 10, (b + 1) * 10 - 1))
|
||||||
@@ -72,6 +74,18 @@ public class TableTicket extends SQLCore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static List<Ticket> unsolved() {
|
||||||
|
try (Session s = SQLCore.sf.openSession()) {
|
||||||
|
return s.createCriteria(Ticket.class)
|
||||||
|
.createAlias(Ticket.PROPERTY_USER, "u")
|
||||||
|
.addOrder(Order.asc("u." + User.PROPERTY_BLOCK))
|
||||||
|
.addOrder(Order.desc(Ticket.PROPERTY_SUBMIT_TIME))
|
||||||
|
.add(Restrictions.ne(Ticket.PROPERTY_STATUS, Status.SOLVED))
|
||||||
|
.list();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static List<Object[]> track(int tid) {
|
public static List<Object[]> track(int tid) {
|
||||||
try (Session s = SQLCore.sf.openSession()) {
|
try (Session s = SQLCore.sf.openSession()) {
|
||||||
|
|||||||
@@ -1,9 +1,16 @@
|
|||||||
package love.sola.netsupport.sql;
|
package love.sola.netsupport.sql;
|
||||||
|
|
||||||
|
import com.google.common.cache.CacheBuilder;
|
||||||
|
import com.google.common.cache.CacheLoader;
|
||||||
|
import com.google.common.cache.LoadingCache;
|
||||||
|
import love.sola.netsupport.config.Settings;
|
||||||
import love.sola.netsupport.pojo.User;
|
import love.sola.netsupport.pojo.User;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.criterion.Restrictions;
|
import org.hibernate.criterion.Restrictions;
|
||||||
|
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* ***********************************************
|
||||||
* Created by Sola on 2015/11/10.
|
* Created by Sola on 2015/11/10.
|
||||||
@@ -28,26 +35,64 @@ public class TableUser extends SQLCore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static User getByWechat(String wechat) {
|
|
||||||
try (Session s = sf.openSession()) {
|
|
||||||
return (User) s.createCriteria(User.class).add(Restrictions.eq(User.PROPERTY_WECHAT, wechat)).uniqueResult();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static User getByName(String name) {
|
public static User getByName(String name) {
|
||||||
try (Session s = sf.openSession()) {
|
try (Session s = sf.openSession()) {
|
||||||
return (User) s.createCriteria(User.class).add(Restrictions.eq(User.PROPERTY_NAME, name)).uniqueResult();
|
return (User) s.createCriteria(User.class).add(Restrictions.eq(User.PROPERTY_NAME, name)).uniqueResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static User getByWechat(String wechat) {
|
||||||
|
try {
|
||||||
|
User u = cache.get(wechat);
|
||||||
|
return u == NULL_USER ? null : u;
|
||||||
|
} catch (ExecutionException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static int update(User user) {
|
public static int update(User user) {
|
||||||
try (Session s = sf.openSession()) {
|
try (Session s = sf.openSession()) {
|
||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
s.update(user);
|
s.update(user);
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
|
cache.put(user.getWechatId(), user);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static void init() {
|
||||||
|
try (Session s = SQLCore.sf.openSession()) {
|
||||||
|
User.OFFICIAL_CHINA_UNICOM_XH = s.get(User.class, 100104L);
|
||||||
|
User.OFFICIAL_CHINA_MOBILE_XH = s.get(User.class, 100864L);
|
||||||
|
User.OFFICIAL_CHINA_MOBILE_FX = s.get(User.class, 100865L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static LoadingCache<String, User> cache = CacheBuilder.newBuilder()
|
||||||
|
.concurrencyLevel(4)
|
||||||
|
.maximumSize(4096)
|
||||||
|
.expireAfterWrite(Settings.I.User_Wechat_Cache_Expire_Time, TimeUnit.SECONDS)
|
||||||
|
.build(new ValueLoader());
|
||||||
|
|
||||||
|
private static class ValueLoader extends CacheLoader<String, User> {
|
||||||
|
@Override
|
||||||
|
public User load(String key) throws Exception {
|
||||||
|
User u = TableUser.getByWechat0(key);
|
||||||
|
return u == null ? NULL_USER : u;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final User NULL_USER = new User();
|
||||||
|
|
||||||
|
public static void flushCache() {
|
||||||
|
cache.invalidateAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static User getByWechat0(String wechat) {
|
||||||
|
try (Session s = sf.openSession()) {
|
||||||
|
return (User) s.createCriteria(User.class).add(Restrictions.eq(User.PROPERTY_WECHAT, wechat)).uniqueResult();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package love.sola.netsupport.wechat;
|
|||||||
|
|
||||||
import love.sola.netsupport.config.Settings;
|
import love.sola.netsupport.config.Settings;
|
||||||
import love.sola.netsupport.wechat.handler.RegisterHandler;
|
import love.sola.netsupport.wechat.handler.RegisterHandler;
|
||||||
|
import love.sola.netsupport.wechat.handler.SignHandler;
|
||||||
|
import love.sola.netsupport.wechat.handler.SubscribeHandler;
|
||||||
import love.sola.netsupport.wechat.matcher.CheckSpamMatcher;
|
import love.sola.netsupport.wechat.matcher.CheckSpamMatcher;
|
||||||
import love.sola.netsupport.wechat.matcher.RegisterMatcher;
|
import love.sola.netsupport.wechat.matcher.RegisterMatcher;
|
||||||
import me.chanjar.weixin.common.util.StringUtils;
|
import me.chanjar.weixin.common.util.StringUtils;
|
||||||
@@ -56,11 +58,7 @@ public class WxMpServlet extends HttpServlet {
|
|||||||
.async(false)
|
.async(false)
|
||||||
.msgType("event")
|
.msgType("event")
|
||||||
.event("subscribe")
|
.event("subscribe")
|
||||||
.handler((wxMessage, context, wxMpService1, sessionManager)
|
.handler(new SubscribeHandler())
|
||||||
-> WxMpXmlOutMessage.TEXT()
|
|
||||||
.fromUser(wxMessage.getToUserName())
|
|
||||||
.toUser(wxMessage.getFromUserName())
|
|
||||||
.content(lang("Event_Subscribe")).build())
|
|
||||||
.end();
|
.end();
|
||||||
wxMpMessageRouter.rule()
|
wxMpMessageRouter.rule()
|
||||||
.async(false)
|
.async(false)
|
||||||
@@ -83,6 +81,7 @@ public class WxMpServlet extends HttpServlet {
|
|||||||
} catch (IllegalAccessException | InstantiationException e) {
|
} catch (IllegalAccessException | InstantiationException e) {
|
||||||
throw new ServletException(e);
|
throw new ServletException(e);
|
||||||
}
|
}
|
||||||
|
wxMpMessageRouter.rule().async(false).msgType("text").rContent("(?i)^Auth \\d{4}").handler(new SignHandler()).end();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerCommands(WxMpMessageRouter router) throws IllegalAccessException, InstantiationException {
|
public static void registerCommands(WxMpMessageRouter router) throws IllegalAccessException, InstantiationException {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class ProfileHandler implements WxMpMessageHandler {
|
|||||||
session.setAttribute(Attribute.WECHAT, wxMessage.getFromUserName());
|
session.setAttribute(Attribute.WECHAT, wxMessage.getFromUserName());
|
||||||
session.setAttribute(Attribute.USER, u);
|
session.setAttribute(Attribute.USER, u);
|
||||||
TextBuilder out = WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName());
|
TextBuilder out = WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName());
|
||||||
out.content(format("User_Profile_Link", id, u.getName(), u.getIsp().id, u.getNetAccount(), u.getBlock(), u.getRoom(), u.getPhone()));
|
out.content(format("Profile_Modify", format("User_Profile_Link", id, u.getName(), u.getIsp().id, u.getNetAccount(), u.getBlock(), u.getRoom(), u.getPhone())));
|
||||||
return out.build();
|
return out.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import me.chanjar.weixin.mp.bean.outxmlbuilder.TextBuilder;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static love.sola.netsupport.config.Lang.format;
|
import static love.sola.netsupport.config.Lang.format;
|
||||||
import static love.sola.netsupport.config.Lang.lang;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* ***********************************************
|
||||||
@@ -33,14 +32,17 @@ public class RegisterHandler implements WxMpMessageHandler {
|
|||||||
TextBuilder out = WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName());
|
TextBuilder out = WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName());
|
||||||
String fromUser = wxMessage.getFromUserName();
|
String fromUser = wxMessage.getFromUserName();
|
||||||
User u = TableUser.getByWechat(fromUser);
|
User u = TableUser.getByWechat(fromUser);
|
||||||
|
String id = WechatSession.genId();
|
||||||
|
WxSession session = WechatSession.get(id, true);
|
||||||
if (u != null) {
|
if (u != null) {
|
||||||
out.content(lang("Already_Registered"));
|
session.setAttribute(Attribute.AUTHORIZED, Command.PROFILE);
|
||||||
|
session.setAttribute(Attribute.WECHAT, fromUser);
|
||||||
|
session.setAttribute(Attribute.USER, u);
|
||||||
|
out.content(format("Already_Registered", format("User_Profile_Link", id, u.getName(), u.getIsp().id, u.getNetAccount(), u.getBlock(), u.getRoom(), u.getPhone())));
|
||||||
} else {
|
} else {
|
||||||
String id = WechatSession.genId();
|
|
||||||
WxSession session = WechatSession.get(id, true);
|
|
||||||
session.setAttribute(Attribute.AUTHORIZED, Command.REGISTER);
|
session.setAttribute(Attribute.AUTHORIZED, Command.REGISTER);
|
||||||
session.setAttribute(Attribute.WECHAT, wxMessage.getFromUserName());
|
session.setAttribute(Attribute.WECHAT, fromUser);
|
||||||
out.content(format("User_Register_Link", id));
|
out.content(format("User_Register", format("User_Register_Link", id)));
|
||||||
}
|
}
|
||||||
return out.build();
|
return out.build();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,88 @@
|
|||||||
|
package love.sola.netsupport.wechat.handler;
|
||||||
|
|
||||||
|
import love.sola.netsupport.sql.SQLCore;
|
||||||
|
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||||
|
import me.chanjar.weixin.common.session.WxSessionManager;
|
||||||
|
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
|
||||||
|
import me.chanjar.weixin.mp.api.WxMpService;
|
||||||
|
import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
|
||||||
|
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
|
||||||
|
import me.chanjar.weixin.mp.bean.outxmlbuilder.TextBuilder;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ***********************************************
|
||||||
|
* Created by Sola on 2015/12/26.
|
||||||
|
* Don't modify this source without my agreement
|
||||||
|
* ***********************************************
|
||||||
|
*/
|
||||||
|
public class SignHandler implements WxMpMessageHandler {
|
||||||
|
|
||||||
|
public static Pattern pat = Pattern.compile("(?i)^Auth (\\d{4})");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
|
||||||
|
String msg = wxMessage.getContent();
|
||||||
|
TextBuilder out = WxMpXmlOutMessage.TEXT().toUser(wxMessage.getFromUserName()).fromUser(wxMessage.getToUserName());
|
||||||
|
Matcher mat = pat.matcher(msg);
|
||||||
|
|
||||||
|
root:
|
||||||
|
if (mat.find()) {
|
||||||
|
int id = Integer.parseInt(mat.group(1));
|
||||||
|
try (Connection conn = SQLCore.ds.getConnection()) {
|
||||||
|
switch (checkID(conn, id)) {
|
||||||
|
case -1:
|
||||||
|
out.content("无效ID。");
|
||||||
|
break root;
|
||||||
|
case -2:
|
||||||
|
out.content("该ID已登记过。");
|
||||||
|
break root;
|
||||||
|
}
|
||||||
|
if (checkDuplicated(conn, wxMessage.getFromUserName())) {
|
||||||
|
out.content("你的微信已经登记过。");
|
||||||
|
break root;
|
||||||
|
}
|
||||||
|
PreparedStatement ps = conn.prepareStatement("UPDATE auth SET wechat=? WHERE id=?");
|
||||||
|
ps.setString(1, wxMessage.getFromUserName());
|
||||||
|
ps.setInt(2, id);
|
||||||
|
if (ps.executeUpdate() == 1) {
|
||||||
|
out.content("登记成功。");
|
||||||
|
} else {
|
||||||
|
out.content("登记失败,请联系管理员。");
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
out.content("系统异常,请联系管理员。");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
out.content("无效ID。");
|
||||||
|
}
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package love.sola.netsupport.wechat.handler;
|
||||||
|
|
||||||
|
import love.sola.netsupport.enums.Attribute;
|
||||||
|
import love.sola.netsupport.pojo.User;
|
||||||
|
import love.sola.netsupport.sql.TableUser;
|
||||||
|
import love.sola.netsupport.wechat.Command;
|
||||||
|
import love.sola.netsupport.wechat.WechatSession;
|
||||||
|
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||||
|
import me.chanjar.weixin.common.session.WxSession;
|
||||||
|
import me.chanjar.weixin.common.session.WxSessionManager;
|
||||||
|
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
|
||||||
|
import me.chanjar.weixin.mp.api.WxMpService;
|
||||||
|
import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
|
||||||
|
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
|
||||||
|
import me.chanjar.weixin.mp.bean.outxmlbuilder.TextBuilder;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static love.sola.netsupport.config.Lang.format;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ***********************************************
|
||||||
|
* Created by Sola on 2015/12/25.
|
||||||
|
* Don't modify this source without my agreement
|
||||||
|
* ***********************************************
|
||||||
|
*/
|
||||||
|
public class SubscribeHandler implements WxMpMessageHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
|
||||||
|
TextBuilder out = WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName());
|
||||||
|
String fromUser = wxMessage.getFromUserName();
|
||||||
|
User u = TableUser.getByWechat(fromUser);
|
||||||
|
String id = WechatSession.genId();
|
||||||
|
WxSession session = WechatSession.get(id, true);
|
||||||
|
if (u != null) {
|
||||||
|
session.setAttribute(Attribute.AUTHORIZED, Command.PROFILE);
|
||||||
|
session.setAttribute(Attribute.WECHAT, fromUser);
|
||||||
|
session.setAttribute(Attribute.USER, u);
|
||||||
|
out.content(format("Event_Subscribe", format("Already_Registered", format("User_Profile_Link", id, u.getName(), u.getIsp().id, u.getNetAccount(), u.getBlock(), u.getRoom(), u.getPhone()))));
|
||||||
|
} else {
|
||||||
|
session.setAttribute(Attribute.AUTHORIZED, Command.REGISTER);
|
||||||
|
session.setAttribute(Attribute.WECHAT, fromUser);
|
||||||
|
out.content(format("Event_Subscribe", format("User_Register", format("User_Register_Link", id))));
|
||||||
|
}
|
||||||
|
return out.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,7 +26,6 @@ public class CheckSpamMatcher implements WxMpMessageMatcher {
|
|||||||
|
|
||||||
private LoadingCache<String, Long> cache = CacheBuilder.newBuilder()
|
private LoadingCache<String, Long> cache = CacheBuilder.newBuilder()
|
||||||
.concurrencyLevel(4)
|
.concurrencyLevel(4)
|
||||||
.weakKeys()
|
|
||||||
.maximumSize(4096)
|
.maximumSize(4096)
|
||||||
.expireAfterWrite(Settings.I.Check_Spam_Cache_Expire_Time, TimeUnit.SECONDS)
|
.expireAfterWrite(Settings.I.Check_Spam_Cache_Expire_Time, TimeUnit.SECONDS)
|
||||||
.build(new ValueLoader());
|
.build(new ValueLoader());
|
||||||
|
|||||||
@@ -11,12 +11,14 @@ REGEX_CANCEL: '^(?i)(Cancel)|(取消)|(撤销)|(qx)|(cx)$'
|
|||||||
REGEX_LOGIN: '^(?i)Authme$'
|
REGEX_LOGIN: '^(?i)Authme$'
|
||||||
REGEX_PROFILE: '^(?i)(EditProfile)|(修改资料)|(修改信息)|(xgzl)|(xgxx)$'
|
REGEX_PROFILE: '^(?i)(EditProfile)|(修改资料)|(修改信息)|(xgzl)|(xgxx)$'
|
||||||
|
|
||||||
#Event
|
#Misc
|
||||||
Event_Subscribe: "欢迎使用电子科技大学中山学院网络维护科微信自助报修平台。\n\n若您尚未进行过微信绑定,请发送'绑定'(bd)进行微信绑定"
|
|
||||||
Invalid_Operation: 'Whoops,报修姬找不到你想要的东西啦 (╯‵□′)╯︵┻━┻。'
|
Invalid_Operation: 'Whoops,报修姬找不到你想要的东西啦 (╯‵□′)╯︵┻━┻。'
|
||||||
Message_Spam: '你的打字速度太快了,喝一杯82年的Java压压惊吧。'
|
Message_Spam: '你的打字速度太快了,喝一杯82年的Java压压惊吧。'
|
||||||
|
#Subscribe
|
||||||
|
Event_Subscribe: "欢迎使用电子科技大学中山学院网络维护科微信自助报修平台。\n\n{0}"
|
||||||
#Register
|
#Register
|
||||||
Already_Registered: "您已进行过微信绑定。如果需要更改个人信息,请发送 '修改资料'(xgzl) 。"
|
User_Register: "您尚未进行微信绑定。\n<a href=\"{0}\">>点击这里进行微信绑定操作<</a>"
|
||||||
|
Already_Registered: '您已进行过微信绑定。若是需要更改个人信息,请<a href="{0}"> >点击此处<</a>。'
|
||||||
#Query
|
#Query
|
||||||
Query_Title: '最近一次报修记录:'
|
Query_Title: '最近一次报修记录:'
|
||||||
More_Details: '>>> 查询更早的报修信息,请点击 <<<'
|
More_Details: '>>> 查询更早的报修信息,请点击 <<<'
|
||||||
@@ -24,30 +26,31 @@ No_Ticket_Available: '您尚未提交过任何报修。'
|
|||||||
#Submit
|
#Submit
|
||||||
Already_Opening_Ticket: "您上次提交的报修单仍在处理中. 若需要查询报修单状态,请发送 '查询' 。"
|
Already_Opening_Ticket: "您上次提交的报修单仍在处理中. 若需要查询报修单状态,请发送 '查询' 。"
|
||||||
Submit_Title: '在网维工作人员上门解决您的问题之前...'
|
Submit_Title: '在网维工作人员上门解决您的问题之前...'
|
||||||
Submit_Desc: "在网维工作人员上门解决您的问题之前,您可以尝试以下方法来更有效地解决您的问题:\n
|
Submit_Desc: |
|
||||||
重新插拔您电脑的网线以及墙上的端口。\n
|
在网维工作人员上门解决您的问题之前,您可以尝试以下方法来更有效地解决您的问题:
|
||||||
尝试卸载掉您的wifi共享软件并重启电脑。\n
|
- 重新插拔您电脑的网线以及墙上的端口。
|
||||||
请您检查一下您的账号是否余额充足。\n
|
- 尝试卸载掉您的wifi共享软件并重启电脑。
|
||||||
若您的电脑出现明显异常,请尝试使用他人的电脑能否正常登录,网维的工作成员主要负责网络的维护工作,可能无法解决您的个人电脑问题。\n
|
- 请您检查一下您的账号是否余额充足。
|
||||||
\n
|
- 若您的电脑出现明显异常,请尝试使用他人的电脑能否正常登录,网维的工作成员主要负责网络的维护工作,可能无法解决您的个人电脑问题。
|
||||||
若以上步骤对您没有帮助,请点此提交报修表单。"
|
|
||||||
|
若以上步骤对您没有帮助,请点此提交报修表单。
|
||||||
#Cancel
|
#Cancel
|
||||||
No_Open_Ticket_Available: '您当前没有未解决的报修表单。'
|
No_Open_Ticket_Available: '您当前没有未解决的报修表单。'
|
||||||
Cancel_Title: '报修已取消:'
|
Cancel_Title: '报修已取消:'
|
||||||
User_Cancel_Remark: '用户手动取消报修。'
|
User_Cancel_Remark: '用户手动取消报修。'
|
||||||
Cancel_Failed: '取消失败。'
|
Cancel_Failed: '取消失败。'
|
||||||
#Modify
|
#Modify
|
||||||
Modify_Title: ''
|
Profile_Modify: '<a href="{0}">> 点此修改资料 <</a>'
|
||||||
#Login
|
#Login
|
||||||
Not_Operator: '嘟嘟嘟……'
|
Not_Operator: '嘟嘟嘟……'
|
||||||
No_Login: 'Permission Denied.'
|
No_Login: 'Permission Denied.'
|
||||||
Internal_Error: '啊哦,登录失败了哦。'
|
Internal_Error: '啊哦,登录失败了哦。'
|
||||||
|
|
||||||
#URL
|
#URL
|
||||||
User_Register_Link: "您尚未进行微信绑定。\n<a href=\"http://topaz.sinaapp.com/nm/v1/reg.html?token={0}\">>点击这里进行微信绑定操作<</a>"
|
User_Register_Link: 'http://topaz.sinaapp.com/nm/v1/reg.html?token={0}'
|
||||||
User_Query_Link: 'http://topaz.sinaapp.com/nm/v1/list.html?token={0}'
|
User_Query_Link: 'http://topaz.sinaapp.com/nm/v1/list.html?token={0}'
|
||||||
User_Submit_Link: 'http://topaz.sinaapp.com/nm/v1/rrepair.html?token={0}&name={1}&isp={2}&room={3}&block={4}&phone={5,number,#}'
|
User_Submit_Link: 'http://topaz.sinaapp.com/nm/v1/rrepair.html?token={0}&name={1}&isp={2}&room={3}&block={4}&phone={5,number,#}'
|
||||||
User_Profile_Link: '<a href="http://topaz.sinaapp.com/nm/v1/modi.html?token={0}&name={1}&isp={2}&username={3}&block={4}&room={5}&phone={6,number,#}">> 点此修改资料 <</a>'
|
User_Profile_Link: 'http://topaz.sinaapp.com/nm/v1/modi.html?token={0}&name={1}&isp={2}&username={3}&block={4}&room={5}&phone={6,number,#}'
|
||||||
Result_Page: 'http://topaz.sinaapp.com/nm/v1/result.html'
|
Result_Page: 'http://topaz.sinaapp.com/nm/v1/result.html'
|
||||||
Operator_Home_Page: '<a href="http://topaz.sinaapp.com/nm/v1/man/home.html?token={0}">CLICK HERE</a>'
|
Operator_Home_Page: '<a href="http://topaz.sinaapp.com/nm/v1/man/home.html?token={0}">CLICK HERE</a>'
|
||||||
Operator_Login_Page: 'http://topaz.sinaapp.com/nm/v1/man/login.html?pkey={0}'
|
Operator_Login_Page: 'http://topaz.sinaapp.com/nm/v1/man/login.html?pkey={0}'
|
||||||
|
|||||||
Reference in New Issue
Block a user