Browse Source

增加CustomerUserContext,WeChatUserContext

master
yashen 9 years ago
parent
commit
48b589478c
8 changed files with 161 additions and 21 deletions
  1. +1
    -1
      B3WeChat.Web/B3WeChat.Web.csproj
  2. +2
    -13
      B3WeChat.Web/Pages/WeChatLogin.cs
  3. +31
    -6
      B3WeChat.Web/PluginClass.cs
  4. +10
    -1
      B3WeChat/B3WeChat.csproj
  5. +2
    -0
      B3WeChat/BO/ApproveMessage.cs
  6. +58
    -0
      B3WeChat/CustomerUserContext.cs
  7. +5
    -0
      B3WeChat/Rpcs/ApproveMessageRpc.cs
  8. +52
    -0
      B3WeChat/WeChatUserContext.cs

+ 1
- 1
B3WeChat.Web/B3WeChat.Web.csproj View File

@ -100,7 +100,7 @@
<Link>Misc_version.cs</Link>
</Compile>
<Compile Include="Pages\WeChatReceive.cs" />
<Compile Include="Pages\WeiChatLogin.cs" />
<Compile Include="Pages\WeChatLogin.cs" />
<Compile Include="PluginClass.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>


B3WeChat.Web/Pages/WeiChatLogin.cs → B3WeChat.Web/Pages/WeChatLogin.cs View File

@ -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<IUserBL>();
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);
}
}
}

+ 31
- 6
B3WeChat.Web/PluginClass.cs View File

@ -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());
}
}
}

+ 10
- 1
B3WeChat/B3WeChat.csproj View File

@ -52,6 +52,8 @@
<Reference Include="System.Core">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.Web">
<SpecificVersion>False</SpecificVersion>
</Reference>
@ -97,6 +99,7 @@
<Compile Include="BO\NamedValueTemplate.cs" />
<Compile Include="BO\QRCodeScene.cs" />
<Compile Include="BO\CustomerUser.cs" />
<Compile Include="CustomerUserContext.cs" />
<Compile Include="Entities\ErrorObject.cs" />
<Compile Include="Entities\EventType.cs" />
<Compile Include="Entities\MeassageBody.cs" />
@ -118,10 +121,16 @@
<Compile Include="Utils\SendMessageUtil.cs" />
<Compile Include="Utils\WeChatPageUtil.cs" />
<Compile Include="Utils\XmlUtil.cs" />
<Compile Include="WeChatUserContext.cs" />
<Compile Include="WeiChatObjs\AuthorizationCodeResponse.cs" />
<Compile Include="WeiChatObjs\BaseResponse.cs" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<WCFMetadata Include="Service References\" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.


+ 2
- 0
B3WeChat/BO/ApproveMessage.cs View File

@ -48,5 +48,7 @@ namespace BWP.B3WeChat.BO
[LogicName("审批意见")]
public string ApproveComment { get; set; }
public string OpenID { get; set; }
}
}

+ 58
- 0
B3WeChat/CustomerUserContext.cs View File

@ -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;
}
}
}
}

+ 5
- 0
B3WeChat/Rpcs/ApproveMessageRpc.cs View File

@ -24,6 +24,11 @@ namespace BWP.B3WeChat.Rpcs
[Rpc]
public static void Insert(ApproveMessage message)
{
var user = CustomerUserContext.Current.User;
message.CustomerCode = user.CustomerCode;
message.OpenID = user.OpenID;
ApproveMessageBL.Instance.Insert(message);
}


+ 52
- 0
B3WeChat/WeChatUserContext.cs View File

@ -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;
}
}
}
}

Loading…
Cancel
Save