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;
|
|
}
|
|
}
|
|
|
|
public static WeChatUserContext Current
|
|
{
|
|
get
|
|
{
|
|
var httpContext = HttpContext.Current;
|
|
var key = "WeChatUserContext";
|
|
if (httpContext != null && httpContext.Items.Contains(key))
|
|
{
|
|
return httpContext.Items[key] as WeChatUserContext;
|
|
}
|
|
else
|
|
{
|
|
var user = BLContext.User;
|
|
if (!user.Name.StartsWith("wechat_"))
|
|
{
|
|
throw new Exception("not a wechat 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();
|
|
|
|
if (httpContext != null)
|
|
{
|
|
httpContext.Items[key] = context;
|
|
}
|
|
|
|
return context;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|