/// <summary> /// 是否返回带签名的结果 /// </summary> /// <param name="signKeyEnum"></param> /// <returns></returns> private bool IsSignKeyReturn(SignKeyEnum signKeyEnum) { switch (signKeyEnum) { case SignKeyEnum.DogNoToken: return(true); case SignKeyEnum.MethodToken: return(false); case SignKeyEnum.XCGameMemberToken: return(false); default: return(true); } }
/// <summary> /// 验证访问权限 /// </summary> /// <param name="context">上下文信息</param> /// <param name="errMsg">错误信息</param> /// <returns></returns> private bool CheckAuthorize(AuthorizeAttribute authorizeAttribute, SignKeyEnum signKeyEnum, Dictionary <string, object> dicParas, out string errMsg) { errMsg = string.Empty; switch (signKeyEnum) { case SignKeyEnum.MobileToken: break; case SignKeyEnum.XCGameMemberToken: break; case SignKeyEnum.XCGameMemberOrMobileToken: break; case SignKeyEnum.XCGameUserCacheToken: break; case SignKeyEnum.XCCloudUserCacheToken: { string token = dicParas["userToken"].ToString(); //验证token XCCloudUserTokenModel userTokenKeyModel = XCCloudUserTokenBusiness.GetUserTokenModel(token); if (userTokenKeyModel == null) { errMsg = "token无效"; return(false); } else { if (!string.IsNullOrEmpty(authorizeAttribute.Roles)) { string roleName = Enum.GetName(typeof(RoleType), userTokenKeyModel.LogType); if (!authorizeAttribute.Roles.Contains(roleName)) { errMsg = "当前用户无权访问"; return(false); } } if (!string.IsNullOrEmpty(authorizeAttribute.Merches)) { var merchDataModel = userTokenKeyModel.DataModel as MerchDataModel; if (merchDataModel == null) { errMsg = "当前用户无权访问"; return(false); } string merchType = Enum.GetName(typeof(MerchType), merchDataModel.MerchType); if (!authorizeAttribute.Merches.Contains(merchType)) { errMsg = "当前用户无权访问"; return(false); } } } break; } case SignKeyEnum.MethodToken: break; default: break; } return(true); }
//验证签名 private bool CheckSignKey(SignKeyEnum signKeyEnum, Dictionary <string, object> dicParas, out string signkeyToken, out string errMsg) { errMsg = string.Empty; signkeyToken = string.Empty; if (signKeyEnum == SignKeyEnum.MobileToken) { string mobile = string.Empty; string mobileToken = Utils.GetDictionaryValue <string>(dicParas, "mobileToken").ToString(); string storeId = Utils.GetDictionaryValue <string>(dicParas, "storeId").ToString(); //如果是手机token if (MobileTokenBusiness.ExistToken(mobileToken, out mobile)) { MobileTokenModel mobileTokenTokenModel = new MobileTokenModel(mobile); dicParas.Add(Constant.MobileTokenModel, mobileTokenTokenModel); return(true); } else { errMsg = "手机令牌无效"; return(false); } } else if (signKeyEnum == SignKeyEnum.XCGameMemberToken) { string token = dicParas["memberToken"].ToString(); //验证token XCGameMemberTokenModel memberTokenKeyModel = MemberTokenBusiness.GetMemberTokenModel(token); if (memberTokenKeyModel == null) { errMsg = "token无效"; return(false); } else { dicParas.Add(Constant.XCGameMemberTokenModel, memberTokenKeyModel); return(true); } } else if (signKeyEnum == SignKeyEnum.XCGameMemberOrMobileToken) { string mobile = string.Empty; string mobileToken = Utils.GetDictionaryValue <string>(dicParas, "mobileToken").ToString(); string memberToken = Utils.GetDictionaryValue <string>(dicParas, "memberToken").ToString(); if (string.IsNullOrEmpty(mobileToken) && string.IsNullOrEmpty(memberToken)) { errMsg = "手机令牌或会员令牌不正确"; return(false); } else if (!string.IsNullOrEmpty(mobileToken) && string.IsNullOrEmpty(memberToken)) { //如果是手机token if (MobileTokenBusiness.ExistToken(mobileToken, out mobile)) { MobileTokenModel mobileTokenTokenModel = new MobileTokenModel(mobile); dicParas.Add(Constant.MobileTokenModel, mobileTokenTokenModel); return(true); } else { errMsg = "手机令牌无效"; return(false); } } else if (!string.IsNullOrEmpty(memberToken) && string.IsNullOrEmpty(mobileToken)) { XCGameMemberTokenModel memberTokenModel = MemberTokenBusiness.GetMemberTokenModel(memberToken); if (memberTokenModel != null) { dicParas.Add(Constant.XCGameMemberTokenModel, memberTokenModel); return(true); } else { errMsg = "会员令牌无效"; return(false); } } else if (!string.IsNullOrEmpty(memberToken) && !string.IsNullOrEmpty(mobileToken)) { //手机token验证 if (!MobileTokenBusiness.ExistToken(mobileToken, out mobile)) { errMsg = "手机令牌无效"; return(false); } MobileTokenModel mobileTokenModel = new MobileTokenModel(mobile); dicParas.Add(Constant.MobileTokenModel, mobileTokenModel); //会员token XCGameMemberTokenModel memberTokenModel = MemberTokenBusiness.GetMemberTokenModel(memberToken); if (memberTokenModel == null) { errMsg = "会员令牌无效"; return(false); } dicParas.Add(Constant.XCGameMemberTokenModel, memberTokenModel); //会员token和手机token手机号对比 if (!memberTokenModel.Mobile.Equals(mobileTokenModel.Mobile)) { errMsg = "手机令牌和会员令牌手机号不一致"; return(false); } return(true); } return(true); } else if (signKeyEnum == SignKeyEnum.XCGameUserCacheToken) { string mobile = dicParas.ContainsKey("mobile") ? dicParas["mobile"].ToString() : string.Empty; string UserName = dicParas.ContainsKey("UserName") ? dicParas["UserName"].ToString() : string.Empty; string PassWord = dicParas.ContainsKey("PassWord") ? dicParas["PassWord"].ToString() : string.Empty; string storeId = dicParas.ContainsKey("storeId") ? dicParas["storeId"].ToString() : string.Empty; if (string.IsNullOrEmpty(storeId)) { errMsg = "门店Id不能为空"; return(false); } if (string.IsNullOrEmpty(UserName)) { errMsg = "用户名不能为空"; return(false); } if (string.IsNullOrEmpty(PassWord)) { errMsg = "密码不能为空"; return(false); } if (string.IsNullOrEmpty(mobile)) { errMsg = "手机号码不能为空"; return(false); } return(true); } else if (signKeyEnum == SignKeyEnum.XCCloudUserCacheToken) { string token = dicParas["userToken"].ToString(); //验证token XCCloudUserTokenModel userTokenKeyModel = XCCloudUserTokenBusiness.GetUserTokenModel(token); if (userTokenKeyModel == null) { errMsg = "token无效"; return(false); } else { dicParas.Add(Constant.XCCloudUserTokenModel, userTokenKeyModel); return(true); } } else if (signKeyEnum == SignKeyEnum.MethodToken) { return(true); } else if (signKeyEnum == SignKeyEnum.XCGameAdminToken) { string userToken = dicParas.ContainsKey("userToken") ? dicParas["userToken"].ToString() : string.Empty; string configUnionId = System.Configuration.ConfigurationManager.AppSettings["BossUnionId"].ToString(); string unionId = string.Empty; if (!UnionIdTokenBusiness.ExistToken(userToken, out unionId)) { errMsg = "用户令牌无效"; return(false); } if (!configUnionId.Contains(unionId)) { errMsg = "用户没有授权"; return(false); } return(true); } else if (signKeyEnum == SignKeyEnum.XCGameManaUserToken) { string userToken = dicParas.ContainsKey("userToken") ? dicParas["userToken"].ToString() : string.Empty; XCCloudManaUserTokenModel userTokenModel = XCCloudManaUserTokenBusiness.GetManaUserTokenModel(userToken); if (userTokenModel == null) { errMsg = "用户没有授权"; return(false); } dicParas.Add(Constant.XCGameManaUserToken, userTokenModel); return(true); } else if (signKeyEnum == SignKeyEnum.XCGameManamAdminUserToken) { string userToken = dicParas.ContainsKey("userToken") ? dicParas["userToken"].ToString() : string.Empty; XCGameManaAdminUserTokenModel tokenModel = XCGameManaAdminUserTokenBusiness.GetTokenModel(userToken); if (tokenModel == null) { errMsg = "用户没有授权"; return(false); } dicParas.Add(Constant.XCGameManamAdminUserToken, tokenModel); return(true); } else { string token = dicParas["token"].ToString(); string signKey = dicParas["signkey"].ToString(); errMsg = string.Empty; signkeyToken = "default"; return(true); } }