| @ -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<string, object> 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<IUserBL>(); | |||
| 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()); | |||
| } | |||
| } | |||
| } | |||
| @ -0,0 +1,58 @@ | |||
| using Bwp.MainSystem.BO; | |||
| using BWP.B3WeChat.BO; | |||
| using Forks.EnterpriseServices.DomainObjects2; | |||
| using Forks.EnterpriseServices.DomainObjects2.DQuery; | |||
| using Forks.EnterpriseServices.SqlDoms; | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| using System.Text; | |||
| using TSingSoft.WebPluginFramework; | |||
| namespace BWP.B3WeChat | |||
| { | |||
| public class CustomerUserContext | |||
| { | |||
| CustomerUser mUser; | |||
| public CustomerUser User | |||
| { | |||
| get | |||
| { | |||
| return mUser; | |||
| } | |||
| } | |||
| [ThreadStatic] | |||
| static Lazy<CustomerUserContext> mCurrent = new Lazy<CustomerUserContext>(() => | |||
| { | |||
| var user = BLContext.User; | |||
| var query = new DQueryDom(new JoinAlias(typeof(DeviceAuthentication))); | |||
| query.Where.Conditions.Add(DQCondition.EQ("Ticket", user.UserTag.ToString("N"))); | |||
| query.Columns.Add(DQSelectColumn.Field("DeviceNumber")); | |||
| query.Range = SelectRange.Top(1); | |||
| var deviceNumber = query.EExecuteScalar<string>(); | |||
| var context = new CustomerUserContext(); | |||
| var dmoQuery = new DmoQuery(typeof(CustomerUser)); | |||
| dmoQuery.Where.Conditions.Add(DQCondition.EQ("CustomerCode", deviceNumber)); | |||
| dmoQuery.Where.Conditions.Add(DQCondition.EQ("CustomerUsername", user.Name)); | |||
| dmoQuery.Range = SelectRange.Top(1); | |||
| context.mUser = dmoQuery.EExecuteScalar<CustomerUser>(); | |||
| return context; | |||
| }); | |||
| public static CustomerUserContext Current | |||
| { | |||
| get | |||
| { | |||
| return mCurrent.Value; | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @ -0,0 +1,52 @@ | |||
| using BWP.B3WeChat.BO; | |||
| using Forks.EnterpriseServices.DomainObjects2.DQuery; | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| using System.Text; | |||
| using System.Web; | |||
| using TSingSoft.WebPluginFramework; | |||
| namespace BWP.B3WeChat | |||
| { | |||
| public class WeChatUserContext | |||
| { | |||
| CustomerUser[] mCustomers; | |||
| public CustomerUser[] Customers | |||
| { | |||
| get | |||
| { | |||
| return mCustomers; | |||
| } | |||
| } | |||
| string mOpenID; | |||
| public string OpenID{ | |||
| get{ | |||
| return mOpenID; | |||
| } | |||
| } | |||
| [ThreadStatic] | |||
| static Lazy<WeChatUserContext> mCurrent = new Lazy<WeChatUserContext>(() => | |||
| { | |||
| var user = BLContext.User; | |||
| var context = new WeChatUserContext(); | |||
| context.mOpenID = user.Name.Substring(7); | |||
| var query = new DmoQuery(typeof(CustomerUser)); | |||
| query.Where.Conditions.Add(DQCondition.EQ("OpenID", context.OpenID)); | |||
| context.mCustomers = query.EExecuteList().Cast<CustomerUser>().ToArray(); | |||
| return context; | |||
| }); | |||
| public static WeChatUserContext Current | |||
| { | |||
| get | |||
| { | |||
| return mCurrent.Value; | |||
| } | |||
| } | |||
| } | |||
| } | |||