public object getOrder(Dictionary <string, object> dicParas) { try { string StoreID = dicParas.ContainsKey("storeId") ? dicParas["storeId"].ToString() : string.Empty; string UserToken = dicParas.ContainsKey("userToken") ? dicParas["userToken"].ToString() : string.Empty; if (string.IsNullOrEmpty(UserToken)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "用户token无效")); } var list = XCCloudUserTokenBusiness.GetUserTokenModel(UserToken); if (list == null) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "用户token无效")); } if (string.IsNullOrEmpty(StoreID)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "门店号无效")); } string OrderNum = string.Empty; IFlw_Order_SerialNumberService flw_Order_SerialNumberService = BLLContainer.Resolve <IFlw_Order_SerialNumberService>(); var orderlist = flw_Order_SerialNumberService.GetModels(x => x.StoreiD == StoreID).ToList().FirstOrDefault(x => Convert.ToDateTime(x.CreateDate).ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd")); IBase_StoreInfoService base_StoreInfoService = BLLContainer.Resolve <IBase_StoreInfoService>(); var menlist = base_StoreInfoService.GetModels(x => x.StoreID == StoreID).FirstOrDefault <Base_StoreInfo>(); if (menlist == null) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "未查询到商户号")); } int num = 0; if (orderlist == null) { num = +1; Flw_Order_SerialNumber flw_Order_SerialNumber = new Flw_Order_SerialNumber(); flw_Order_SerialNumber.StoreiD = StoreID; flw_Order_SerialNumber.CreateDate = DateTime.Now; flw_Order_SerialNumber.CurNumber = num; flw_Order_SerialNumberService.Add(flw_Order_SerialNumber); } else { num = Convert.ToInt32(orderlist.CurNumber + 1); orderlist.CurNumber = num; flw_Order_SerialNumberService.Update(orderlist); } OrderNum = DateTime.Now.ToString("yyyyMMddHHmm") + menlist.MerchID + num.ToString(); return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, OrderNum, Result_Code.T, "")); } catch (Exception e) { throw e; } }
public object getOrderPayState(Dictionary <string, object> dicParas) { try { string OrderId = dicParas.ContainsKey("orderId") ? dicParas["orderId"].ToString().Trim() : string.Empty; string UserToken = dicParas.ContainsKey("userToken") ? dicParas["userToken"].ToString() : string.Empty; if (string.IsNullOrEmpty(UserToken)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "用户token无效")); } var list = XCCloudUserTokenBusiness.GetUserTokenModel(UserToken); if (list == null) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "用户token无效")); } OrderPayCacheModel model = new OrderPayCacheModel(); if (OrderPayCache.IsExist(OrderId)) { model = OrderPayCache.GetValue(OrderId) as OrderPayCacheModel; } else { Flw_Order order = Flw_OrderBusiness.GetOrderModel(OrderId); if (order != null) { model.OrderId = OrderId; model.PayAmount = order.RealPay == null ? 0 : order.RealPay.Value; model.PayTime = order.PayTime == null ? "" : order.PayTime.Value.ToString("yyyy-MM-dd HH:mm:ss"); model.PayState = (OrderState)order.OrderStatus.Value; } } return(ResponseModelFactory <OrderPayCacheModel> .CreateModel(isSignKeyReturn, model)); } catch (Exception e) { throw e; } }
/// <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); } }
public object CheckUser(Dictionary <string, object> dicParas) { try { string errMsg = string.Empty; string token = string.Empty; string userName = dicParas.ContainsKey("userName") ? dicParas["userName"].ToString() : string.Empty; string password = dicParas.ContainsKey("password") ? dicParas["password"].ToString() : string.Empty; if (string.IsNullOrWhiteSpace(userName)) { errMsg = "用户名不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (string.IsNullOrWhiteSpace(password)) { errMsg = "密码不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } password = Utils.MD5(password); UserLogResponseModel userLogResponseModel = new UserLogResponseModel(); IBase_UserInfoService base_UserInfoService = BLLContainer.Resolve <IBase_UserInfoService>(); if (base_UserInfoService.Any(p => p.LogName.Equals(userName, StringComparison.OrdinalIgnoreCase) && p.LogPassword.Equals(password, StringComparison.OrdinalIgnoreCase))) { var base_UserInfoModel = base_UserInfoService.GetModels(p => p.LogName.Equals(userName, StringComparison.OrdinalIgnoreCase) && p.LogPassword.Equals(password, StringComparison.OrdinalIgnoreCase)).FirstOrDefault <Base_UserInfo>(); int userId = base_UserInfoModel.UserID; int userType = (int)base_UserInfoModel.UserType; int logType = (int)RoleType.XcUser; //默认普通员工登录 int isXcAdmin = base_UserInfoModel.Auditor ?? 0; int switchable = base_UserInfoModel.Switchable ?? 0; if (userType == (int)UserType.Xc && isXcAdmin == 0) { logType = (int)RoleType.XcAdmin; userLogResponseModel.Token = XCCloudUserTokenBusiness.SetUserToken(userId.ToString(), logType); } else if (userType == (int)UserType.Store || userType == (int)UserType.StoreBoss) { logType = (int)RoleType.StoreUser; string storeId = base_UserInfoModel.StoreID; IBase_StoreInfoService base_StoreInfoService = BLLContainer.Resolve <IBase_StoreInfoService>(); if (!base_StoreInfoService.Any(a => a.StoreID.Equals(storeId, StringComparison.OrdinalIgnoreCase))) { errMsg = "该门店不存在"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } string merchId = base_StoreInfoService.GetModels(p => p.StoreID.Equals(storeId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault().MerchID; var dataModel = new UserDataModel { StoreID = storeId, MerchID = merchId }; userLogResponseModel.Token = XCCloudUserTokenBusiness.SetUserToken(userId.ToString(), logType, dataModel); } else { logType = (int)RoleType.MerchUser; string merchId = base_UserInfoModel.MerchID; IBase_MerchantInfoService base_MerchantInfoService = BLLContainer.Resolve <IBase_MerchantInfoService>(); if (!base_MerchantInfoService.Any(p => p.MerchID.Equals(merchId, StringComparison.OrdinalIgnoreCase))) { errMsg = "该商户不存在"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } var base_MerchantInfoModel = base_MerchantInfoService.GetModels(p => p.MerchID.Equals(merchId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); var dataModel = new MerchDataModel { MerchID = merchId, MerchType = base_MerchantInfoModel.MerchType, CreateType = base_MerchantInfoModel.CreateType, CreateUserID = base_MerchantInfoModel.CreateUserID }; userLogResponseModel.Token = XCCloudUserTokenBusiness.SetUserToken(userId.ToString(), logType, dataModel); userLogResponseModel.MerchTag = base_MerchantInfoModel.MerchTag; } userLogResponseModel.LogType = logType; userLogResponseModel.UserType = userType; userLogResponseModel.Switchable = switchable; return(ResponseModelFactory.CreateSuccessModel(isSignKeyReturn, userLogResponseModel)); } else { errMsg = "用户名或密码错误"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } } catch (Exception e) { return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, e.Message)); } }
public static void TestInit() { StoreIDDataModel tokenDataModel = new StoreIDDataModel("S0100022", "778852013145", "lijunjie"); XCCloudUserTokenBusiness.SetUserToken("3", (int)RoleType.StoreUser, tokenDataModel); }
protected void Page_Load(object sender, EventArgs e) { try { string errMsg = string.Empty; string md5 = Request["state"] ?? ""; string url = Request.Url.GetLeftPart(UriPartial.Path); string code = Request["code"] ?? ""; LogHelper.SaveLog("code:" + code); //if (!TokenMana.GetTokenMd5(url, md5)) //{ // errMsg = url + WeiXinConfig.Md5key; // LogHelper.SaveLog("错误:" + errMsg); // Response.Redirect(WeiXinConfig.RedirectErrorPage + "?title=" + HttpUtility.UrlEncode("登录失败") + "&message=" + HttpUtility.UrlEncode(errMsg), false); // return; //} string accsess_token = string.Empty; string refresh_token = string.Empty; string openId = string.Empty; string unionId = string.Empty; string token = string.Empty; int? merchTag = null; if (TokenMana.GetOpenTokenForScanQR(code, out accsess_token, out refresh_token, out openId, out unionId)) { if (string.IsNullOrEmpty(unionId)) { if (!TokenMana.GetUnionIdFromOpen(openId, accsess_token, out unionId, out errMsg)) { Response.Redirect(WeiXinConfig.RedirectErrorPage + "?title=" + HttpUtility.UrlEncode("登录失败") + "&message=" + HttpUtility.UrlEncode(errMsg), false); return; } } //验证用户 IBase_UserInfoService userInfoService = BLLContainer.Resolve <IBase_UserInfoService>(); if (userInfoService.Any(w => w.UnionID.ToString().Equals(unionId, StringComparison.OrdinalIgnoreCase))) { var base_UserInfoModel = userInfoService.GetModels(w => w.UnionID.ToString().Equals(unionId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault <Base_UserInfo>(); int userId = base_UserInfoModel.UserID; int userType = (int)base_UserInfoModel.UserType; int logType = (int)RoleType.XcUser; //默认普通员工登录 int isXcAdmin = base_UserInfoModel.Auditor ?? 0; int switchable = base_UserInfoModel.Switchable ?? 0; if (userType == (int)UserType.Xc && isXcAdmin == 0) { logType = (int)RoleType.XcAdmin; token = XCCloudUserTokenBusiness.SetUserToken(userId.ToString(), logType); } else if (userType == (int)UserType.Store || userType == (int)UserType.StoreBoss) { logType = (int)RoleType.StoreUser; var storeId = base_UserInfoModel.StoreID; IBase_StoreInfoService base_StoreInfoService = BLLContainer.Resolve <IBase_StoreInfoService>(); if (!base_StoreInfoService.Any(a => a.StoreID.Equals(storeId, StringComparison.OrdinalIgnoreCase))) { errMsg = "该门店不存在"; Response.Redirect(WeiXinConfig.RedirectErrorPage + "?title=" + HttpUtility.UrlEncode("登录失败") + "&message=" + HttpUtility.UrlEncode(errMsg), false); } string merchId = base_StoreInfoService.GetModels(p => p.StoreID.Equals(storeId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault().MerchID; var dataModel = new UserDataModel { StoreID = storeId, MerchID = merchId }; token = XCCloudUserTokenBusiness.SetUserToken(userId.ToString(), logType, dataModel); } else { logType = (int)RoleType.MerchUser; string merchId = base_UserInfoModel.MerchID; IBase_MerchantInfoService base_MerchantInfoService = BLLContainer.Resolve <IBase_MerchantInfoService>(); if (!base_MerchantInfoService.Any(p => p.MerchID.Equals(merchId, StringComparison.OrdinalIgnoreCase))) { errMsg = "该商户不存在"; Response.Redirect(WeiXinConfig.RedirectErrorPage + "?title=" + HttpUtility.UrlEncode("登录失败") + "&message=" + HttpUtility.UrlEncode(errMsg), false); } var base_MerchantInfoModel = base_MerchantInfoService.GetModels(p => p.MerchID.Equals(merchId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); var dataModel = new MerchDataModel { MerchID = merchId, MerchType = base_MerchantInfoModel.MerchType, CreateType = base_MerchantInfoModel.CreateType, CreateUserID = base_MerchantInfoModel.CreateUserID }; token = XCCloudUserTokenBusiness.SetUserToken(userId.ToString(), logType, dataModel); merchTag = base_MerchantInfoModel.MerchTag; } Response.Redirect(WeiXinConfig.RedirectMainPage + "?token=" + token + "&logType=" + logType + "&userType=" + userType + "&merchTag=" + merchTag + "&switchable=" + switchable, false); } else { errMsg = "用户未注册"; LogHelper.SaveLog("失败:" + errMsg); Response.Redirect(WeiXinConfig.RedirectErrorPage + "?title=" + HttpUtility.UrlEncode("登录失败") + "&message=" + HttpUtility.UrlEncode(errMsg), false); } } else { errMsg = "获取openId失败"; LogHelper.SaveLog("错误:" + errMsg); Response.Redirect(WeiXinConfig.RedirectLogoutPage, false); } } catch (Exception ex) { LogHelper.SaveLog("错误:" + ex.Message); Response.Redirect(WeiXinConfig.RedirectErrorPage + "?title=" + HttpUtility.UrlEncode("登录失败") + "&message=" + HttpUtility.UrlEncode(ex.Message), false); } }