public static string Encrypt(long userId, string controllerName) { string str; string userCookieKey = Instance <ISiteSettingService> .Create.GetSiteSettings().UserCookieKey; if (string.IsNullOrEmpty(userCookieKey)) { Guid guid = Guid.NewGuid(); userCookieKey = SecureHelper.MD5(guid.ToString()); Instance <ISiteSettingService> .Create.SaveSetting("UserCookieKey", userCookieKey); } string empty = string.Empty; try { string str1 = string.Concat(controllerName, ",", userId.ToString()); empty = SecureHelper.AESEncrypt(str1, userCookieKey); empty = SecureHelper.EncodeBase64(empty); str = empty; } catch (Exception exception) { Log.Error(string.Format("加密用户标识Cookie出错", empty), exception); throw; } return(str); }
/// <summary> /// 短信验证成功后创建验证成功凭证 /// </summary> /// <param name="contact"></param> /// <returns></returns> protected override string CreateCertificate(string contact) { var identity = Cache.Get(_encryptKey + contact).ToString(); identity = SecureHelper.AESEncrypt(identity, _encryptKey); return(identity); }
public static string Encrypt(long userId, string controllerName) { string text = Instance <ISiteSettingService> .Create.GetSiteSettings().UserCookieKey; if (string.IsNullOrEmpty(text)) { text = SecureHelper.MD5(Guid.NewGuid().ToString()); Instance <ISiteSettingService> .Create.SaveSetting("UserCookieKey", text); } string text2 = string.Empty; string result; try { string encryptStr = controllerName + "," + userId.ToString(); text2 = SecureHelper.AESEncrypt(encryptStr, text); text2 = SecureHelper.EncodeBase64(text2); result = text2; } catch (Exception exception) { Log.Error(string.Format("加密用户标识Cookie出错", text2), exception); throw; } return(result); }
/// <summary> /// 初始化admin密码 /// </summary> public void InitAdmin() { try { SYS_USER_INFO model = new SYS_USER_INFO(); model.UserName = "******"; //判断admin是否存在 DynamicParameters param = new DynamicParameters(); param.Add("UserName", model.UserName); string querysql = @"SELECT * FROM SYS_USER_INFO WHERE UserName=@UserName"; if (idal.FindOne <SYS_USER_INFO>(querysql, param, false) == null) { model.CreateTime = DateTime.Now; model.PassWord = SecureHelper.AESEncrypt("admin"); model.State = 1; string insertsql = @"INSERT INTO [SYS_USER_INFO] ( [UserName] ,[PassWord] ,[State] ,[CreateTime] ) VALUES ( @UserName ,@PassWord ,@State ,@CreateTime ) "; idal.CreateEntity <SYS_USER_INFO>(insertsql, model); } else { model.UpdateTime = DateTime.Now; model.PassWord = SecureHelper.AESEncrypt("admin"); model.State = 1; param.Add("PassWord", model.PassWord); param.Add("UpdateTime", model.UpdateTime); param.Add("State", model.State); string updatesql = @"UPDATE [SYS_USER_INFO] SET [PassWord]=@PassWord ,[State]=@State ,[UpdateTime]=@UpdateTime WHERE UserName='******' "; idal.ExcuteNonQuery <SYS_USER_INFO>(updatesql, param, false); } } catch (Exception ex) { Logger.Error(string.Format("admin初始化异常,异常信息:{0}", ex.ToString())); } }
/// <summary> /// 短信验证成功后创建验证成功凭证 /// </summary> /// <param name="contact"></param> /// <returns></returns> protected override string CreateCertificate(string contact) { object data = Cache.Get <object>(_encryptKey + contact); string identity = ""; try { identity = Convert.ToString(data); } catch { } identity = SecureHelper.AESEncrypt(identity, _encryptKey); return(identity); }
/// <summary> /// AES加密 /// </summary> /// <param name="encryptStr">加密字符串</param> public static string AESEncrypt(string encryptStr) { return(SecureHelper.AESEncrypt(encryptStr, BSPConfig.ShopConfig.SecretKey)); }
private static object _locker = new object();//锁对象 #region 加密/解密 /// <summary> /// AES加密 /// </summary> /// <param name="encryptStr">加密字符串</param> public static string AESEncrypt(string encryptStr) { return(SecureHelper.AESEncrypt(encryptStr, HaConfig.MallConfig.SecretKey)); }
private bool BindOpenIdToUser(ActionExecutingContext filterContext) { string str; bool flag = true; IMobileOAuth weixinOAuth = null; if (base.PlatformType == ChemCloud.Core.PlatformType.WeiXin) { weixinOAuth = new WeixinOAuth(); } string.Format("/m-{0}/Login/Entrance?returnUrl={1}", base.PlatformType.ToString(), HttpUtility.UrlEncode(filterContext.HttpContext.Request.Url.ToString())); if (weixinOAuth == null || GetRequestType(filterContext.HttpContext.Request) != ChemCloud.Core.PlatformType.WeiXin) { flag = false; } else { WXShopInfo wXShopInfo = new WXShopInfo(); string item = filterContext.HttpContext.Request["shop"]; MemberOpenIdInfo.AppIdTypeEnum appIdTypeEnum = MemberOpenIdInfo.AppIdTypeEnum.Normal; if (!string.IsNullOrEmpty(item)) { long num = 0; long.TryParse(item, out num); if (num > 0) { wXShopInfo = ServiceHelper.Create <IVShopService>().GetVShopSetting(num); } } if (string.IsNullOrEmpty(wXShopInfo.AppId) || string.IsNullOrEmpty(wXShopInfo.AppSecret)) { WXShopInfo wXShopInfo1 = new WXShopInfo() { AppId = base.CurrentSiteSetting.WeixinAppId, AppSecret = base.CurrentSiteSetting.WeixinAppSecret, Token = base.CurrentSiteSetting.WeixinToken }; wXShopInfo = wXShopInfo1; appIdTypeEnum = MemberOpenIdInfo.AppIdTypeEnum.Payment; } MobileOAuthUserInfo userInfoBequiet = weixinOAuth.GetUserInfo_bequiet(filterContext, out str, wXShopInfo); if (!string.IsNullOrWhiteSpace(str)) { filterContext.Result = Redirect(str); } else { flag = false; if (userInfoBequiet != null && !string.IsNullOrWhiteSpace(userInfoBequiet.OpenId)) { if (appIdTypeEnum == MemberOpenIdInfo.AppIdTypeEnum.Payment) { string str1 = SecureHelper.AESEncrypt(userInfoBequiet.OpenId, "Mobile"); WebHelper.SetCookie("Himall-User_OpenId", str1); } IMemberService memberService = ServiceHelper.Create <IMemberService>(); UserMemberInfo memberByOpenId = null; if (memberByOpenId == null) { memberByOpenId = memberService.GetMemberByOpenId(userInfoBequiet.LoginProvider, userInfoBequiet.OpenId); } if (memberByOpenId == null) { memberService.BindMember(base.CurrentUser.Id, "ChemCloud.Plugin.OAuth.WeiXin", userInfoBequiet.OpenId, appIdTypeEnum, null, userInfoBequiet.UnionId); } else { string str2 = UserCookieEncryptHelper.Encrypt(memberByOpenId.Id, "Mobile"); WebHelper.SetCookie("ChemCloud-User", str2); } } } } return(flag); }
private bool ProcessInvalidUser_NormalRequest(ActionExecutingContext filterContext) { string str; bool flag = true; IMobileOAuth weixinOAuth = null; if (base.PlatformType == ChemCloud.Core.PlatformType.WeiXin) { weixinOAuth = new WeixinOAuth(); } string str1 = string.Format("/m-{0}/Login/Entrance?returnUrl={1}", base.PlatformType.ToString(), HttpUtility.UrlEncode(filterContext.HttpContext.Request.Url.ToString())); if (weixinOAuth == null || GetRequestType(filterContext.HttpContext.Request) != ChemCloud.Core.PlatformType.WeiXin) { filterContext.Result = Redirect(str1); } else { WXShopInfo wXShopInfo = new WXShopInfo(); string item = filterContext.HttpContext.Request["shop"]; MemberOpenIdInfo.AppIdTypeEnum appIdTypeEnum = MemberOpenIdInfo.AppIdTypeEnum.Normal; if (!string.IsNullOrEmpty(item)) { long num = 0; long.TryParse(item, out num); if (num > 0) { wXShopInfo = ServiceHelper.Create <IVShopService>().GetVShopSetting(num); } } if (string.IsNullOrEmpty(wXShopInfo.AppId) || string.IsNullOrEmpty(wXShopInfo.AppSecret)) { WXShopInfo wXShopInfo1 = new WXShopInfo() { AppId = base.CurrentSiteSetting.WeixinAppId, AppSecret = base.CurrentSiteSetting.WeixinAppSecret, Token = base.CurrentSiteSetting.WeixinToken }; wXShopInfo = wXShopInfo1; appIdTypeEnum = MemberOpenIdInfo.AppIdTypeEnum.Payment; } MobileOAuthUserInfo userInfo = weixinOAuth.GetUserInfo(filterContext, out str, wXShopInfo); if (!string.IsNullOrWhiteSpace(str)) { filterContext.Result = Redirect(str); } else if (userInfo == null || string.IsNullOrWhiteSpace(userInfo.OpenId)) { filterContext.Result = Redirect(str1); } else { if (appIdTypeEnum == MemberOpenIdInfo.AppIdTypeEnum.Payment) { string str2 = SecureHelper.AESEncrypt(userInfo.OpenId, "Mobile"); WebHelper.SetCookie("Himall-User_OpenId", str2); } UserMemberInfo memberByOpenId = null; if (memberByOpenId == null) { memberByOpenId = ServiceHelper.Create <IMemberService>().GetMemberByOpenId(userInfo.LoginProvider, userInfo.OpenId); } if (memberByOpenId == null) { object[] objArray = new object[] { base.PlatformType.ToString(), userInfo.OpenId, "ChemCloud.Plugin.OAuth.WeiXin", HttpUtility.UrlEncode(userInfo.NickName), HttpUtility.UrlEncode(userInfo.RealName), HttpUtility.UrlEncode(userInfo.Headimgurl), HttpUtility.UrlEncode(filterContext.HttpContext.Request.Url.ToString()), appIdTypeEnum, userInfo.UnionId }; str1 = string.Format("/m-{0}/Login/Entrance?openId={1}&serviceProvider={2}&nickName={3}&realName={4}&headimgurl={5}&returnUrl={6}&AppidType={7}&unionid={8}", objArray); filterContext.Result = Redirect(str1); } else { string str3 = UserCookieEncryptHelper.Encrypt(memberByOpenId.Id, "Mobile"); WebHelper.SetCookie("ChemCloud-User", str3); } } } return(flag); }