mirror of
https://github.com/ZSCNetSupportDept/WechatTicketSystem.git
synced 2025-10-29 08:05:04 +08:00
add check token api
This commit is contained in:
@@ -0,0 +1,67 @@
|
|||||||
|
package love.sola.netsupport.api.admin;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import love.sola.netsupport.api.Response;
|
||||||
|
import love.sola.netsupport.enums.Attribute;
|
||||||
|
import love.sola.netsupport.sql.SQLCore;
|
||||||
|
import love.sola.netsupport.util.ParseUtil;
|
||||||
|
import love.sola.netsupport.wechat.WechatSession;
|
||||||
|
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;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ***********************************************
|
||||||
|
* Created by Sola on 2015/12/21.
|
||||||
|
* Don't modify this source without my agreement
|
||||||
|
* ***********************************************
|
||||||
|
*/
|
||||||
|
@WebServlet(name = "CheckSession", urlPatterns = "/api/checksession", loadOnStartup = 43)
|
||||||
|
public class CheckSession 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(check(request));
|
||||||
|
out.println(ParseUtil.parseJsonP(request, json));
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Response check(HttpServletRequest request) {
|
||||||
|
String t = request.getParameter("token");
|
||||||
|
if (t == null || t.isEmpty()) return new Response(Response.ResponseCode.UNAUTHORIZED);
|
||||||
|
WxSession s = WechatSession.get(t, false);
|
||||||
|
if (s == null) return new Response(Response.ResponseCode.UNAUTHORIZED);
|
||||||
|
String more = request.getParameter("more");
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
result.put(Attribute.AUTHORIZED, s.getAttribute(Attribute.AUTHORIZED));
|
||||||
|
if (more != null){
|
||||||
|
switch (more) {
|
||||||
|
case "1":
|
||||||
|
result.put(Attribute.USER, s.getAttribute(Attribute.USER));
|
||||||
|
result.put(Attribute.OPERATOR, s.getAttribute(Attribute.OPERATOR));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new Response(Response.ResponseCode.OK, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import com.google.gson.reflect.TypeToken;
|
|||||||
import com.google.gson.stream.JsonReader;
|
import com.google.gson.stream.JsonReader;
|
||||||
import com.google.gson.stream.JsonWriter;
|
import com.google.gson.stream.JsonWriter;
|
||||||
import love.sola.netsupport.enums.ISP;
|
import love.sola.netsupport.enums.ISP;
|
||||||
|
import love.sola.netsupport.wechat.Command;
|
||||||
import org.hibernate.Hibernate;
|
import org.hibernate.Hibernate;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
@@ -59,6 +60,8 @@ public class SQLCore {
|
|||||||
.registerTypeAdapter(Date.class, (JsonSerializer<Date>) (src, typeOfSrc, context) -> new JsonPrimitive(src.getTime()))
|
.registerTypeAdapter(Date.class, (JsonSerializer<Date>) (src, typeOfSrc, context) -> new JsonPrimitive(src.getTime()))
|
||||||
.registerTypeAdapter(ISP.class, (JsonDeserializer<ISP>) (json, typeOfT, context) -> ISP.fromId(json.getAsJsonPrimitive().getAsInt()))
|
.registerTypeAdapter(ISP.class, (JsonDeserializer<ISP>) (json, typeOfT, context) -> ISP.fromId(json.getAsJsonPrimitive().getAsInt()))
|
||||||
.registerTypeAdapter(ISP.class, (JsonSerializer<ISP>) (src, typeOfSrc, context) -> new JsonPrimitive(src.id))
|
.registerTypeAdapter(ISP.class, (JsonSerializer<ISP>) (src, typeOfSrc, context) -> new JsonPrimitive(src.id))
|
||||||
|
.registerTypeAdapter(Command.class, (JsonDeserializer<Command>) (json, typeOfT, context) -> Command.fromId(json.getAsJsonPrimitive().getAsInt()))
|
||||||
|
.registerTypeAdapter(Command.class, (JsonSerializer<Command>) (src, typeOfSrc, context) -> new JsonPrimitive(src.id))
|
||||||
.registerTypeAdapterFactory(HibernateProxyTypeAdapter.FACTORY)
|
.registerTypeAdapterFactory(HibernateProxyTypeAdapter.FACTORY)
|
||||||
.create();
|
.create();
|
||||||
public static SessionFactory sf;
|
public static SessionFactory sf;
|
||||||
|
|||||||
@@ -34,13 +34,11 @@ public enum Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final String name;
|
|
||||||
public final String regex;
|
public final String regex;
|
||||||
public final Class<? extends WxMpMessageHandler> handler;
|
public final Class<? extends WxMpMessageHandler> handler;
|
||||||
public final int id;
|
public final int id;
|
||||||
|
|
||||||
Command(int id, Class<? extends WxMpMessageHandler> handler) {
|
Command(int id, Class<? extends WxMpMessageHandler> handler) {
|
||||||
this.name = lang("CMD_" + name());
|
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.regex = lang("REGEX_" + name());
|
this.regex = lang("REGEX_" + name());
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
@@ -52,7 +50,7 @@ public enum Command {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return name;
|
return name();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user