using Bwp.MainSystem;
|
|
using Bwp.MainSystem.Auth;
|
|
using Bwp.Web.Pages;
|
|
using BWP.B3WeChat.Tasks;
|
|
using BWP.B3WeChat.Utils;
|
|
using Forks.EnterpriseServices.BusinessInterfaces;
|
|
using Forks.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using TSingSoft.WebPluginFramework;
|
|
using System.Linq;
|
|
|
|
namespace BWP.Web
|
|
{
|
|
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)
|
|
{
|
|
using (var scope = new WpfInternalUserScope())
|
|
{
|
|
user = userBL.Create(username, StringUtil.CreateRandomString(20), "");
|
|
}
|
|
}
|
|
context["User"] = user;
|
|
}
|
|
}
|
|
|
|
public void OnInit()
|
|
{
|
|
if (PluginManager.Current.Plugins.Any((p) => p.Name == "B3UnitedInfos"))
|
|
{
|
|
throw new Exception("业务系统中不应该安装微信模块");
|
|
}
|
|
|
|
|
|
CustomLogin.Register("WeChatReceive.aspx");
|
|
CustomLogin.Register("WeChatLogin.aspx");
|
|
var roleSchemas = Wpf.Settings.RoleSchemas;
|
|
roleSchemas.Add(new RoleSchema("wechat", "微信公众号用户", RoleSchema.DefaultFunctions.Empty));
|
|
Global.RegisterCustomPrePam(new WeChatAuth());
|
|
ClearExpiredApproveMessagesTask.Register();
|
|
}
|
|
}
|
|
}
|