diff --git a/B3WeChat.Web/B3WeChat.Web.csproj b/B3WeChat.Web/B3WeChat.Web.csproj index d1c0098..8600203 100644 --- a/B3WeChat.Web/B3WeChat.Web.csproj +++ b/B3WeChat.Web/B3WeChat.Web.csproj @@ -100,7 +100,7 @@ Misc_version.cs - + diff --git a/B3WeChat.Web/Pages/WeiChatLogin.cs b/B3WeChat.Web/Pages/WeChatLogin.cs similarity index 60% rename from B3WeChat.Web/Pages/WeiChatLogin.cs rename to B3WeChat.Web/Pages/WeChatLogin.cs index e2eda31..d9975b4 100644 --- a/B3WeChat.Web/Pages/WeiChatLogin.cs +++ b/B3WeChat.Web/Pages/WeChatLogin.cs @@ -10,7 +10,7 @@ using TSingSoft.WebPluginFramework; namespace BWP.Web.Pages { - class WeiChatLogin:IHttpHandler + class WeChatLogin:IHttpHandler { public bool IsReusable { @@ -20,19 +20,8 @@ namespace BWP.Web.Pages public void ProcessRequest(HttpContext context) { var code = context.Request.QueryString["code"]; - var openID = WeChatPageUtil.QueryOpenID(code); - - var userBL = BIFactory.Create(); - var user = userBL.Get(openID); - if (user == null) - { - throw new Exception("当前微信公众号用户还没有在系统中注册"); - } - var url = context.Request.QueryString["url"]; - - context.Response.Redirect(url); - + Global.WeChatLoginAndRedirect(code, url); } } } diff --git a/B3WeChat.Web/PluginClass.cs b/B3WeChat.Web/PluginClass.cs index 4ec5855..0917e4b 100644 --- a/B3WeChat.Web/PluginClass.cs +++ b/B3WeChat.Web/PluginClass.cs @@ -1,21 +1,46 @@ -using Bwp.Web.Pages; +using Bwp.MainSystem; +using Bwp.MainSystem.Auth; +using Bwp.Web.Pages; +using BWP.B3WeChat.Utils; +using Forks.EnterpriseServices.BusinessInterfaces; using System; using System.Collections.Generic; -using System.Linq; -using System.Text; using TSingSoft.WebPluginFramework; namespace BWP.Web { - public class PluginClass:IPluginClass + public class PluginClass : IPluginClass { + + class WeChatAuth : IAuthPlugin + { + public void Auth(IDictionary context) + { + if (!context.ContainsKey("wechat_code")) + { + return; + } + var code = (string)context["wechat_code"]; + var openID = WeChatPageUtil.QueryOpenID(code); + var username = "wechat_" + openID; + + var userBL = BIFactory.Create(); + var user = userBL.Get(username); + if (user == null) + { + throw new Exception("当前微信公众号用户还没有在系统中注册"); + } + context["User"] = user; + } + } + public void OnInit() { CustomLogin.Register("WeChatReceive.aspx"); + CustomLogin.Register("WeiChatLogin.aspx"); var roleSchemas = Wpf.Settings.RoleSchemas; roleSchemas.Add(new RoleSchema("wechat", "微信公众号用户", RoleSchema.DefaultFunctions.Empty)); - - + Global.RegisterCustomPrePam(new WeChatAuth()); } } } diff --git a/B3WeChat/B3WeChat.csproj b/B3WeChat/B3WeChat.csproj index 9b8439b..f6a48a9 100644 --- a/B3WeChat/B3WeChat.csproj +++ b/B3WeChat/B3WeChat.csproj @@ -52,6 +52,8 @@ False + + False @@ -97,6 +99,7 @@ + @@ -118,10 +121,16 @@ + - + + + + + +