You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

46 lines
1.2 KiB

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