mirror of
				https://github.com/ZSCNetSupportDept/WechatTicketSystem.git
				synced 2025-11-01 02:46:19 +08:00 
			
		
		
		
	add oauth2 for profile modify
This commit is contained in:
		| @@ -45,12 +45,12 @@ public class Redirect { | ||||
| 		} | ||||
|  | ||||
| 		public RedirectBuilder msg(String msg) { | ||||
| 			sb.append("msg=").append(i18nThenEscape(msg)).append("&"); | ||||
| 			sb.append("msg=").append(escape(msg)).append("&"); | ||||
| 			return this; | ||||
| 		} | ||||
|  | ||||
| 		public RedirectBuilder title(String title) { | ||||
| 			sb.append("title=").append(i18nThenEscape(title)).append("&"); | ||||
| 			sb.append("title=").append(escape(title)).append("&"); | ||||
| 			return this; | ||||
| 		} | ||||
|  | ||||
| @@ -60,7 +60,7 @@ public class Redirect { | ||||
| 		} | ||||
|  | ||||
| 		public RedirectBuilder button(String text) { | ||||
| 			sb.append("btn=").append(i18nThenEscape(text)).append("&"); | ||||
| 			sb.append("btn=").append(escape(text)).append("&"); | ||||
| 			return this; | ||||
| 		} | ||||
|  | ||||
| @@ -70,7 +70,7 @@ public class Redirect { | ||||
| 		} | ||||
|  | ||||
| 		public RedirectBuilder to(String url) { | ||||
| 			sb.append("redirect=").append(i18nThenEscape(url)).append("&"); | ||||
| 			sb.append("redirect=").append(escape(url)).append("&"); | ||||
| 			return this; | ||||
| 		} | ||||
|  | ||||
| @@ -82,8 +82,8 @@ public class Redirect { | ||||
| 			return sb.toString(); | ||||
| 		} | ||||
|  | ||||
| 		private static String i18nThenEscape(String str) { | ||||
| 			return UrlEscapers.urlFragmentEscaper().escape(lang(str)); | ||||
| 		private static String escape(String str) { | ||||
| 			return UrlEscapers.urlFragmentEscaper().escape(str); | ||||
| 		} | ||||
|  | ||||
| 	} | ||||
|   | ||||
| @@ -1,10 +1,12 @@ | ||||
| package love.sola.netsupport.wechat.handler; | ||||
|  | ||||
| import love.sola.netsupport.auth.OAuth2Handler; | ||||
| import love.sola.netsupport.enums.Attribute; | ||||
| import love.sola.netsupport.pojo.User; | ||||
| import love.sola.netsupport.session.WechatSession; | ||||
| import love.sola.netsupport.session.WxSession; | ||||
| import love.sola.netsupport.sql.TableUser; | ||||
| import love.sola.netsupport.util.Redirect; | ||||
| import love.sola.netsupport.wechat.Command; | ||||
| import me.chanjar.weixin.common.exception.WxErrorException; | ||||
| import me.chanjar.weixin.common.session.WxSessionManager; | ||||
| @@ -14,9 +16,12 @@ import me.chanjar.weixin.mp.bean.WxMpXmlMessage; | ||||
| import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage; | ||||
| import me.chanjar.weixin.mp.bean.outxmlbuilder.TextBuilder; | ||||
|  | ||||
| import javax.servlet.AsyncContext; | ||||
| import javax.servlet.http.HttpServletResponse; | ||||
| import java.util.Map; | ||||
|  | ||||
| import static love.sola.netsupport.config.Lang.format; | ||||
| import static love.sola.netsupport.config.Lang.lang; | ||||
|  | ||||
| /** | ||||
|  * *********************************************** | ||||
| @@ -24,7 +29,7 @@ import static love.sola.netsupport.config.Lang.format; | ||||
|  * Don't modify this source without my agreement | ||||
|  * *********************************************** | ||||
|  */ | ||||
| public class ProfileHandler implements WxMpMessageHandler { | ||||
| public class ProfileHandler implements WxMpMessageHandler, OAuth2Handler { | ||||
|  | ||||
| 	@Override | ||||
| 	public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException { | ||||
| @@ -38,4 +43,25 @@ public class ProfileHandler implements WxMpMessageHandler { | ||||
| 		return out.build(); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void onOAuth2(AsyncContext acxt, HttpServletResponse resp, String user, WxSession session) { | ||||
| 		try { | ||||
| 			User u = TableUser.getByWechat(user); | ||||
| 			if (u == null) { | ||||
| 				session.setAttribute(Attribute.AUTHORIZED, Command.REGISTER); | ||||
| 				session.setAttribute(Attribute.WECHAT, user); | ||||
| 				Redirect.error().icon(Redirect.WeUIIcon.INFO).noButton() | ||||
| 						.title(lang("Need_Register_Title")).msg(lang("Need_Register")) | ||||
| 						.to(format(lang("User_Register_Link"), session.getId())).go(resp); | ||||
| 				return; | ||||
| 			} | ||||
| 			session.setAttribute(Attribute.AUTHORIZED, Command.PROFILE); | ||||
| 			session.setAttribute(Attribute.WECHAT, user); | ||||
| 			session.setAttribute(Attribute.USER, u); | ||||
| 			resp.sendRedirect(format("User_Profile_Link", session.getId(), u.getName(), u.getIsp().id, u.getNetAccount(), u.getBlock(), u.getRoom(), u.getPhone())); | ||||
| 		} catch (Exception e) { | ||||
| 			e.printStackTrace(); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -62,12 +62,12 @@ public class LoginHandler implements WxMpMessageHandler, OAuth2Handler { | ||||
| 			Operator operator = TableOperator.get(user); | ||||
| 			if (operator == null) { | ||||
| 				Redirect.error().icon(Redirect.WeUIIcon.WARN_SAFE).noButton() | ||||
| 						.title("Not_Operator").msg("Not_Operator_OAuth2").go(resp); | ||||
| 						.title(lang("Not_Operator")).msg(lang("Not_Operator_OAuth2")).go(resp); | ||||
| 				return; | ||||
| 			} | ||||
| 			if (operator.getAccess() >= Access.NO_LOGIN) { | ||||
| 				Redirect.error().icon(Redirect.WeUIIcon.WAITING).noButton() | ||||
| 						.title("Left_Operator_Title").msg("Left_Operator").go(resp); | ||||
| 						.title(lang("Left_Operator_Title")).msg(lang("Left_Operator")).go(resp); | ||||
| 				return; | ||||
| 			} | ||||
| 			session.setAttribute(Attribute.AUTHORIZED, Command.LOGIN); | ||||
|   | ||||
| @@ -1,6 +1,5 @@ | ||||
| package love.sola.netsupport.wechat.handler.admin; | ||||
|  | ||||
| import love.sola.netsupport.enums.Access; | ||||
| import love.sola.netsupport.pojo.Operator; | ||||
| import love.sola.netsupport.sql.TableOperator; | ||||
| import me.chanjar.weixin.common.exception.WxErrorException; | ||||
| @@ -29,10 +28,10 @@ public class OperatorInfoHandler implements WxMpMessageHandler { | ||||
| 		TextBuilder out = WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName()); | ||||
| 		try { | ||||
| 			Operator op = TableOperator.get(wxMessage.getFromUserName()); | ||||
| 			if (op == null) | ||||
| 			if (op == null) { | ||||
| 				out.content(lang("Not_Operator")); | ||||
| 			else if (op.getAccess() >= Access.NO_LOGIN) { | ||||
| 				out.content(lang("No_Login")); | ||||
| //			} else if (op.getAccess() >= Access.NO_LOGIN) { | ||||
| //				out.content(lang("No_Login")); | ||||
| 			} else { | ||||
| 				out.content(format("Operator_Info", op.getId(), op.getName(), op.getAccess(), op.getBlock(), op.getWeek())); | ||||
| 			} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Sola
					Sola