mirror of
https://github.com/ZSCNetSupportDept/WechatTicketSystem.git
synced 2025-10-30 09:56:18 +08:00
update v2 links
This commit is contained in:
@@ -11,10 +11,10 @@ import static love.sola.netsupport.config.Lang.lang;
|
||||
public class Error {
|
||||
|
||||
public static final Error ALREADY_SUBMITTED = new Error(1);
|
||||
public static final Error OK = new Error(0);
|
||||
public static final Object OK = new Object();
|
||||
public static final Error PARAMETER_REQUIRED = new Error(-1);
|
||||
public static final Error ILLEGAL_PARAMETER = new Error(-2);
|
||||
public static final Error REQUEST_FAILED = new Error(-3);
|
||||
// public static final Error REQUEST_FAILED = new Error(-3); REMOVED
|
||||
public static final Error LENGTH_LIMIT_EXCEEDED = new Error(-4);
|
||||
public static final Error INVALID_PARAMETER = new Error(-5);
|
||||
public static final Error USER_NOT_FOUND = new Error(-11);
|
||||
|
||||
@@ -86,7 +86,7 @@ public class Login extends HttpServlet {
|
||||
return sid;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return Error.REQUEST_FAILED;
|
||||
return Error.INTERNAL_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
51
src/main/java/love/sola/netsupport/auth/OAuth2.java
Normal file
51
src/main/java/love/sola/netsupport/auth/OAuth2.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package love.sola.netsupport.auth;
|
||||
|
||||
import love.sola.netsupport.util.Checker;
|
||||
import love.sola.netsupport.wechat.WechatSession;
|
||||
import love.sola.netsupport.wechat.WxMpServlet;
|
||||
import me.chanjar.weixin.common.session.WxSession;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
||||
|
||||
import javax.servlet.AsyncContext;
|
||||
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;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
* Created by Sola on 2014/8/20.
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
@WebServlet(name = "OAuth2", urlPatterns = "/oauth2/callback", loadOnStartup = 21)
|
||||
public class OAuth2 extends HttpServlet {
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
AsyncContext acxt = req.startAsync();
|
||||
String code = req.getParameter("code");
|
||||
String state = req.getParameter("state");
|
||||
if (Checker.hasNull(code, state)) {
|
||||
resp.sendError(HttpServletResponse.SC_FORBIDDEN);
|
||||
return;
|
||||
}
|
||||
acxt.start(() -> {
|
||||
try {
|
||||
WxMpService wxMpService = WxMpServlet.instance.wxMpService;
|
||||
WxMpOAuth2AccessToken token = wxMpService.oauth2getAccessToken(code);
|
||||
WxMpUser wxUser = wxMpService.oauth2getUserInfo(token, "zh_CN");
|
||||
String sid = WechatSession.genId();
|
||||
WxSession session = WechatSession.get(sid, true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user