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.
 
 

50 lines
1.3 KiB

using Bwp.MainSystem;
using Bwp.MainSystem.Auth;
using Bwp.Web.Pages;
using BWP.B3WeChat.Utils;
using Forks.EnterpriseServices.BusinessInterfaces;
using Forks.Utils;
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)
{
using (var scope = new WpfInternalUserScope())
{
user = userBL.Create(username, StringUtil.CreateRandomString(20), "");
}
}
context["User"] = user;
}
}
public void OnInit()
{
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());
}
}
}