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 TSingSoft.WebPluginFramework; namespace BWP.Web { 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()); } } }