public object getMobileToken(Dictionary <string, object> dicParas) { try { string mobile = dicParas.ContainsKey("mobile") ? dicParas["mobile"].ToString().Trim() : ""; string smsCode = dicParas.ContainsKey("smsCode") ? dicParas["smsCode"].ToString().Trim() : ""; string key = mobile + "_" + smsCode; if (!FilterMobileBusiness.IsTestSMS) { if (!SMSCodeCache.IsExist(key)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "短信验证码无效")); } } if (SMSCodeCache.IsExist(key)) { SMSCodeCache.Remove(key); } string token = MobileTokenBusiness.SetMobileToken(mobile); MobileTokenResponseModel tokenModel = new MobileTokenResponseModel(mobile, token); return(ResponseModelFactory <MobileTokenResponseModel> .CreateModel(isSignKeyReturn, tokenModel)); } catch (Exception e) { throw e; } }
/// <summary> /// 获取短信验证码 /// </summary> /// <returns></returns> public static bool GetSMSCode(out string code) { int num = 1; code = Utils.getNumRandomCode(6); //如果生成的验证码与缓存中的重复 while (num <= 3 && SMSCodeCache.IsExist(code)) { num += 1; code = Utils.getNumRandomCode(6); } if (num == 3) { if (SMSCodeCache.IsExist(code)) { return(false); } else { return(true); } } else { return(true); } }
/// <summary> /// 验证码校验 /// </summary> /// <param name="dicParas"></param> /// <returns></returns> public object checkCode(Dictionary <string, object> dicParas) { string mobile = dicParas.ContainsKey("mobile") ? dicParas["mobile"].ToString() : ""; string code = dicParas.ContainsKey("code") ? dicParas["code"].ToString() : ""; //验证手机号码 if (!Utils.CheckMobile(mobile)) { ResponseModel responseModel = new ResponseModel(Return_Code.T, "", Result_Code.F, "手机号码不正确"); return(responseModel); } //验证码是否存在于缓存中 object codeMobile = SMSCodeCache.GetValue(code); if (codeMobile == null) { ResponseModel responseModel = new ResponseModel(Return_Code.T, "", Result_Code.F, "验证码不存在或已过期"); return(responseModel); } //缓存中的手机号码和请求的手机号码一致 if (codeMobile.ToString().Equals(mobile)) { ResponseModel responseModel = new ResponseModel(Return_Code.T, "", Result_Code.T, ""); return(responseModel); } else { ResponseModel responseModel = new ResponseModel(Return_Code.T, "", Result_Code.F, "验证码无效"); return(responseModel); } }
public object merchLogin(Dictionary <string, object> dicParas) { try { string errMsg = string.Empty; string mobile = dicParas.ContainsKey("mobile") ? dicParas["mobile"].ToString() : string.Empty; string code = dicParas.ContainsKey("smsCode") ? dicParas["smsCode"].ToString() : string.Empty; if (string.IsNullOrWhiteSpace(mobile) || !IsMobile(mobile)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "请输入正确的手机号码")); } string smsCode = dicParas.ContainsKey("smsCode") ? dicParas["smsCode"].ToString() : string.Empty; if (string.IsNullOrEmpty(smsCode)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "请输入短信验证码")); } //验证短信验证码 bool isSMSTest = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["isSMSTest"].ToString()); //判断缓存验证码是否正确 string key = mobile + "_" + smsCode; if (!isSMSTest) { if (!SMSCodeCache.IsExist(key)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "短信验证码无效")); } } IMerchService merchService = BLLContainer.Resolve <IMerchService>(); var merch = merchService.GetModels(p => p.Mobile.Equals(mobile, StringComparison.OrdinalIgnoreCase)).FirstOrDefault <Base_MerchInfo>(); if (merch == null) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "商户不存在")); } //如果商户token为空,就写入新的token if (string.IsNullOrWhiteSpace(merch.Token)) { string token = System.Guid.NewGuid().ToString("N"); merch.Token = token; //更新token merch.State = 1; //状态激活 merchService.Update(merch); if (!MobileTokenCache.ExistTokenByKey(mobile)) { MobileTokenCache.AddToken(CommonConfig.PrefixKey + mobile, token); } } MerchModel merchModel = new MerchModel(merch.MerchName, merch.OPName, merch.Token, merch.State); return(ResponseModelFactory <MerchModel> .CreateModel(isSignKeyReturn, merchModel)); } catch (Exception e) { throw e; } }
/// <summary> /// 发送短信验证码 /// </summary> /// <param name="dicParas"></param> /// <returns></returns> public static object sendSMSCode(Dictionary <string, object> dicParas) { string mobile = dicParas.ContainsKey("mobile") ? dicParas["mobile"].ToString().Trim() : ""; string templateId = dicParas.ContainsKey("templateId") ? dicParas["templateId"].ToString().Trim() : ""; if (!Utils.CheckMobile(mobile)) { ResponseModel responseModel = new ResponseModel(Return_Code.T, "", Result_Code.F, "手机号码无效"); return(responseModel); } string code = string.Empty; if (SMSBusiness.GetSMSCode(out code)) { SMSCodeCache.Add(code, mobile, 2); string errMsg = string.Empty; if (SMSBusiness.SendSMSCode(templateId, mobile, code, out errMsg)) { ResponseModel responseModel = new ResponseModel(Return_Code.T, "", Result_Code.T, ""); return(responseModel); } else { ResponseModel responseModel = new ResponseModel(Return_Code.T, "", Result_Code.F, errMsg); return(responseModel); } } else { ResponseModel responseModel = new ResponseModel(Return_Code.T, "", Result_Code.F, "发送验证码出错"); return(responseModel); } }
public object getUserRegister(Dictionary <string, object> dicParas) { string errMsg = string.Empty; string xcGameDBName = string.Empty; string Mobile = dicParas.ContainsKey("mobile") ? dicParas["mobile"].ToString() : string.Empty; string StoreId = dicParas.ContainsKey("storeId") ? dicParas["storeId"].ToString() : string.Empty; string UserName = dicParas.ContainsKey("UserName") ? dicParas["UserName"].ToString() : string.Empty; string PassWord = dicParas.ContainsKey("PassWord") ? dicParas["PassWord"].ToString() : string.Empty; string smsCode = dicParas.ContainsKey("smsCode") ? dicParas["smsCode"].ToString() : string.Empty; string Pass = Utils.MD5(PassWord); StoreBusiness store = new StoreBusiness(); if (!store.IsEffectiveStore(StoreId, out xcGameDBName, out errMsg)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, errMsg)); } string key = Mobile + "_" + smsCode; //判断缓存验证码是否正确 if (!FilterMobileBusiness.IsTestSMS && !FilterMobileBusiness.ExistMobile(Mobile)) { if (!SMSCodeCache.IsExist(key)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "短信验证码无效")); } } IUserRegisterService userregisterService = BLLContainer.Resolve <IUserRegisterService>(); //判断用户名是否存在 var userlist = userregisterService.GetModels(p => p.UserName == UserName).ToList(); if (userlist.Count > 0) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "该用户名已经存在")); } //判断用户是否注册 var menulist = userregisterService.GetModels(p => p.Mobile == Mobile && p.StoreId == StoreId).ToList(); if (menulist.Count > 0) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "该用户已注册")); } xcGameDBName = "XCGameManagerDB"; string sql = "exec InsertUserRegister @UserName,@PassWord,@Mobile,@StoreId,@Return output "; SqlParameter[] parameters = new SqlParameter[5]; parameters[0] = new SqlParameter("@UserName", UserName); parameters[1] = new SqlParameter("@PassWord", Pass); parameters[2] = new SqlParameter("@Mobile", Mobile); parameters[3] = new SqlParameter("@StoreId", StoreId); parameters[4] = new SqlParameter("@Return", 0); parameters[4].Direction = System.Data.ParameterDirection.Output; t_UserRegister userregister = userregisterService.SqlQuery(sql, xcGameDBName, parameters).FirstOrDefault <t_UserRegister>(); if (userregister == null) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "用户添加异常")); } return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.T, "")); }
public object getUserToken(Dictionary <string, object> dicParas) { try { string storeId = dicParas.ContainsKey("storeId") ? dicParas["storeId"].ToString() : string.Empty; string mobile = dicParas.ContainsKey("mobile") ? dicParas["mobile"].ToString() : string.Empty; string smsCode = dicParas.ContainsKey("smsCode") ? dicParas["smsCode"].ToString() : string.Empty; if (string.IsNullOrEmpty(smsCode)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "请输入验证码")); } bool isSMSTest = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["isSMSTest"].ToString()); string key = mobile + "_" + smsCode; if (!isSMSTest && !FilterMobileBusiness.ExistMobile(mobile)) { if (!SMSCodeCache.IsExist(key)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "短信验证码无效")); } } if (string.IsNullOrEmpty(storeId)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "门店号不能为空")); } if (string.IsNullOrEmpty(mobile)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "手机号码不能为空")); } int storeids = int.Parse(storeId); IStoreService storeService = BLLContainer.Resolve <IStoreService>(); var menlist = storeService.GetModels(x => x.id == storeids).FirstOrDefault <t_store>(); if (menlist == null) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "门店号无效")); } string dbname = menlist.store_dbname; IMemberService memberService = BLLContainer.Resolve <IMemberService>(dbname); var memberlist = memberService.GetModels(x => x.Mobile == mobile).FirstOrDefault <t_member>(); if (memberlist == null) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "手机号码无效")); } var UserToken = UserInfoBusiness.SetUserToken(storeId, mobile); return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, UserToken, Result_Code.T, "")); } catch (Exception e) { throw e; } }
public object BindStoreOpenId(Dictionary <string, object> dicParas) { string errMsg = string.Empty; string storeId = dicParas.ContainsKey("storeId") ? dicParas["storeId"].ToString() : string.Empty; string openId = dicParas.ContainsKey("openId") ? dicParas["openId"].ToString() : string.Empty; string smsCode = dicParas.ContainsKey("smsCode") ? dicParas["smsCode"].ToString() : string.Empty; string mobile = dicParas.ContainsKey("mobile") ? dicParas["mobile"].ToString() : string.Empty; string key = mobile + "_" + smsCode; if (!FilterMobileBusiness.IsTestSMS) { if (!SMSCodeCache.IsExist(key)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "短信验证码无效")); } } //验证门店信息 //StoreCacheModel storeModel = null; //StoreBusiness store = new StoreBusiness(); //if (!store.IsEffectiveStore(storeId, ref storeModel, out errMsg)) //{ // return ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, errMsg); //} IStoreService storeService = BLLContainer.Resolve <IStoreService>(); var storeModel = storeService.GetModels(p => p.id.ToString().Equals(storeId)).FirstOrDefault <t_store>(); if (storeModel == null) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "门店信息不存在")); } if (!string.IsNullOrEmpty(storeModel.openId)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "门店已绑定微信,不能重复绑定")); } if (!storeService.Update(storeModel)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "门店已绑定微信出错")); } return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.T, "")); }
public object getForgetPassWord(Dictionary <string, object> dicParas) { string UserName = dicParas.ContainsKey("UserName") ? dicParas["UserName"].ToString() : string.Empty; string PassWord = dicParas.ContainsKey("PassWord") ? dicParas["PassWord"].ToString() : string.Empty; if (string.IsNullOrEmpty(PassWord)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "请输入新密码")); } string smsCode = dicParas.ContainsKey("smsCode") ? dicParas["smsCode"].ToString() : string.Empty; if (string.IsNullOrEmpty(smsCode)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "请输入验证码")); } IUserRegisterService userervice = BLLContainer.Resolve <IUserRegisterService>(); var menulist = userervice.GetModels(p => p.UserName.Equals(UserName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault <t_UserRegister>(); if (menulist == null) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "未查询到该用户")); } string errMsg = string.Empty; string Mobile = menulist.Mobile; //判断缓存验证码是否正确 string key = Mobile + "_" + smsCode; if (!FilterMobileBusiness.IsTestSMS && !FilterMobileBusiness.ExistMobile(Mobile)) { if (!SMSCodeCache.IsExist(key)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "短信验证码无效")); } } string pass = Utils.MD5(PassWord); menulist.PassWord = pass; userervice.Update(menulist); return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.T, "")); }
public object getUser(Dictionary <string, object> dicParas) { string UserName = dicParas.ContainsKey("UserName") ? dicParas["UserName"].ToString() : string.Empty; string imgCode = dicParas.ContainsKey("imgCode") ? dicParas["imgCode"].ToString() : string.Empty; if (string.IsNullOrEmpty(UserName)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "请输入用户名")); } if (string.IsNullOrEmpty(imgCode)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "请输入验证码")); } if (!FilterMobileBusiness.IsTestSMS) { if (!ValidateImgCache.Exist(imgCode.ToUpper())) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "验证码无效")); } } IUserRegisterService userervice = BLLContainer.Resolve <IUserRegisterService>(); var menulist = userervice.GetModels(p => p.UserName.Equals(UserName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault <t_UserRegister>(); if (menulist == null) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "未查询到该用户")); } string Mobile = menulist.Mobile; //短信模板 string templateId = "2"; string key = string.Empty; if (!FilterMobileBusiness.IsTestSMS && !FilterMobileBusiness.ExistMobile(Mobile)) { string smsCode = string.Empty; if (SMSBusiness.GetSMSCode(out smsCode)) { key = Mobile + "_" + smsCode; SMSCodeCache.Add(key, Mobile, CacheExpires.SMSCodeExpires); string errMsg = string.Empty; if (SMSBusiness.SendSMSCode(templateId, Mobile, smsCode, out errMsg)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.T, "")); } else { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, errMsg)); } } else { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "发送验证码出错")); } } else { key = Mobile + "_" + "123456"; SMSCodeCache.Add(key, Mobile, CacheExpires.SMSCodeExpires); return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.T, "")); } }
public object sendSMSCode(Dictionary <string, object> dicParas) { try { //是否模拟短信测试(1-模拟短信测试,不发送固定短信,不做短信验证) string mobile = dicParas.ContainsKey("mobile") ? dicParas["mobile"].ToString().Trim() : ""; string templateId = "2";//短信模板 string token = dicParas.ContainsKey("token") ? dicParas["token"].ToString().Trim() : ""; //验证请求次数 if (!FilterMobileBusiness.IsTestSMS && !FilterMobileBusiness.ExistMobile(mobile)) { if (!RequestTotalCache.CanRequest(mobile, ApiRequestType.SendSMSCode)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "已超过单日最大请求次数")); } else { RequestTotalCache.Add(mobile, ApiRequestType.SendSMSCode); } } if (!Utils.CheckMobile(mobile)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "手机号码无效")); } //验证短信验证码 string key = mobile + "_" + token; object smsTempTokenCacheObj = SMSTempTokenCache.GetValue(key); if (smsTempTokenCacheObj == null) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "验证码无效")); } if (!smsTempTokenCacheObj.ToString().Equals(mobile)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "验证码无效")); } //发送短信,并添加缓存成功 if (!FilterMobileBusiness.IsTestSMS && !FilterMobileBusiness.ExistMobile(mobile)) { string smsCode = string.Empty; if (SMSBusiness.GetSMSCode(out smsCode)) { key = mobile + "_" + smsCode; SMSCodeCache.Add(key, mobile, CacheExpires.SMSCodeExpires); string errMsg = string.Empty; if (SMSBusiness.SendSMSCode(templateId, mobile, smsCode, out errMsg)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.T, "")); } else { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, errMsg)); } } else { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "发送验证码出错")); } } else { key = mobile + "_" + "123456"; SMSCodeCache.Add(key, mobile, CacheExpires.SMSCodeExpires); return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.T, "")); } } catch (Exception e) { throw e; } }
public object getMobileToken(Dictionary <string, object> dicParas) { try { string token = dicParas.ContainsKey("token") ? dicParas["token"].ToString().Trim() : ""; string smsCode = dicParas.ContainsKey("smsCode") ? dicParas["smsCode"].ToString().Trim() : ""; string storeId = dicParas.ContainsKey("storeId") ? dicParas["storeId"].ToString().Trim() : ""; string openId = dicParas.ContainsKey("openId") ? dicParas["openId"].ToString().Trim() : ""; //获取手机号码 string mobile = string.Empty; if (!MobileTokenBusiness.ExistToken(token, out mobile)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "手机令牌无效")); } string key = mobile + "_" + smsCode; if (!FilterMobileBusiness.IsTestSMS && !FilterMobileBusiness.ExistMobile(mobile)) { if (!SMSCodeCache.IsExist(key)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "短信验证码无效")); } } if (SMSCodeCache.IsExist(key)) { SMSCodeCache.Remove(key); } //绑定openId if (string.IsNullOrEmpty(storeId)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "storeId参数不能为空")); } if (!Utils.isNumber(storeId)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "店号的格式不正确")); } if (string.IsNullOrEmpty(openId)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "openId参数不能为空")); } int iStoreId = Convert.ToInt32(storeId); IStoreService storeService = BLLContainer.Resolve <IStoreService>(); if (!storeService.Any(a => a.id == iStoreId)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "该门店不存在")); } var storeModel = storeService.GetModels(p => p.id == iStoreId).FirstOrDefault(); if (!string.IsNullOrEmpty(storeModel.openId)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "门店已绑定微信,不能重复绑定")); } storeModel.openId = openId; if (!storeService.Update(storeModel)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "绑定openId失败")); } token = MobileTokenBusiness.SetMobileToken(mobile); var tokenModel = new { mobileToken = token }; return(ResponseModelFactory.CreateAnonymousSuccessModel(isSignKeyReturn, tokenModel)); } catch (Exception e) { throw e; } }
/// <summary> /// 验证注册参数 /// </summary> /// <returns></returns> private bool checkRegisterParas(string openId, out string storeId, out string merchId, out int userType, out string revOpenId, out string errMsg) { errMsg = string.Empty; storeId = string.Empty; merchId = string.Empty; revOpenId = string.Empty; userType = (int)UserType.Store; string scode = Request["scode"] != null ? Request["scode"].ToString() : string.Empty; string mobile = Request["mobile"] != null ? Request["mobile"].ToString() : string.Empty; string storeOrMerchId = Request["storeOrMerchId"] != null ? Request["storeOrMerchId"].ToString() : string.Empty; string username = Request["username"] != null ? Request["username"].ToString() : string.Empty; string password = Request["password"] != null ? Request["password"].ToString() : string.Empty; #region 验证参数 //如果用户未获取短信验证码 string key = mobile + "_" + scode; if (!SMSCodeCache.IsExist(key)) { errMsg = "短信验证码无效"; return(false); } if (string.IsNullOrEmpty(storeOrMerchId)) { errMsg = "门店ID或商户ID参数不能为空"; return(false); } if (string.IsNullOrEmpty(openId)) { errMsg = "用户openId参数不能为空"; return(false); } if (openId.Length > 64) { errMsg = "用户openId参数长度不能超过64个字符"; return(false); } if (string.IsNullOrEmpty(username)) { errMsg = "用户名参数不能为空"; return(false); } if (username.Length > 20) { errMsg = "用户名参数长度不能超过20个字符"; return(false); } if (!Utils.CheckMobile(mobile)) { errMsg = "手机号码参数不正确"; return(false); } if (string.IsNullOrEmpty(password)) { errMsg = "密码参数不能为空"; return(false); } #endregion //验证商户 var mId = storeOrMerchId; IBase_MerchantInfoService base_MerchantInfoService = BLLContainer.Resolve <IBase_MerchantInfoService>(); if (!base_MerchantInfoService.Any(p => p.MerchID.Equals(mId, StringComparison.OrdinalIgnoreCase))) { //验证门店 var sId = storeOrMerchId; IBase_StoreInfoService storeInfoService = BLLContainer.Resolve <IBase_StoreInfoService>(); if (!storeInfoService.Any(p => p.StoreID.Equals(sId, StringComparison.OrdinalIgnoreCase))) { errMsg = "门店不存在"; return(false); } mId = storeInfoService.GetModels(p => p.StoreID.Equals(sId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault().MerchID; storeId = storeOrMerchId; } else { merchId = storeOrMerchId; } //验证发起人 IBase_UserInfoService userInfoService = BLLContainer.Resolve <IBase_UserInfoService>(); var userList = userInfoService.GetModels(p => p.OpenID.ToString().Equals(openId, StringComparison.OrdinalIgnoreCase)); int userInfoCount = userList.Count <Base_UserInfo>(); if (userInfoService.Any(p => p.OpenID.ToString().Equals(openId, StringComparison.OrdinalIgnoreCase))) { errMsg = "用户不能重复注册"; return(false); } //验证接收人 if (!base_MerchantInfoService.Any(a => a.MerchID.Equals(mId, StringComparison.OrdinalIgnoreCase))) { errMsg = "接收商户不存在"; return(false); } var base_MerchantInfoModel = base_MerchantInfoService.GetModels(p => p.MerchID.Equals(mId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); var wxOpenId = base_MerchantInfoModel.WxOpenID; revOpenId = wxOpenId; if (!userInfoService.Any(p => p.OpenID.Equals(wxOpenId, StringComparison.OrdinalIgnoreCase))) { errMsg = "接收人不存在"; return(false); } //验证用户类别 if (!string.IsNullOrEmpty(merchId)) { userType = (int)base_MerchantInfoModel.MerchType; } else { userType = (int)UserType.Store; } return(true); }
public object getRegisterSMSCode(Dictionary <string, object> dicParas) { try { string storeId = dicParas.ContainsKey("storeId") ? dicParas["storeId"].ToString() : string.Empty; string mobile = dicParas.ContainsKey("mobile") ? dicParas["mobile"].ToString() : string.Empty; string imgCode = dicParas.ContainsKey("imgCode") ? dicParas["imgCode"].ToString() : string.Empty; string errMsg = string.Empty; //验证码 if (!ValidateImgCache.Exist(imgCode.ToUpper())) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "验证码无效")); } ValidateImgCache.Remove(imgCode.ToUpper()); if (string.IsNullOrEmpty(storeId)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "门店号码不正确")); } if (string.IsNullOrEmpty(mobile)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "手机号码不正确")); } bool isSMSTest = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["isSMSTest"].ToString()); StoreBusiness sb = new StoreBusiness(); StoreCacheModel storeModel = null; if (!sb.IsEffectiveStore(storeId, ref storeModel, out errMsg)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, errMsg)); } if (storeModel.StoreDBDeployType == 0) { //验证用户在分库是否存在 XCCloudService.BLL.IBLL.XCGame.IUserService userService = BLLContainer.Resolve <XCCloudService.BLL.IBLL.XCGame.IUserService>(storeModel.StoreDBName); var gameUserModel = userService.GetModels(p => p.Mobile.Equals(mobile, StringComparison.OrdinalIgnoreCase)).FirstOrDefault <XCCloudService.Model.XCGame.u_users>(); if (gameUserModel == null) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "未查询到该用户")); } } else if (storeModel.StoreDBDeployType == 1) { string sn = System.Guid.NewGuid().ToString().Replace("-", ""); UDPSocketCommonQueryAnswerModel answerModel = null; string radarToken = string.Empty; if (DataFactory.SendDataUserPhoneQuery(sn, storeModel.StoreID.ToString(), storeModel.StorePassword, mobile, out radarToken, out errMsg)) { } else { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, errMsg)); } answerModel = null; int whileCount = 0; while (answerModel == null && whileCount <= 25) { //获取应答缓存数据 whileCount++; System.Threading.Thread.Sleep(1000); answerModel = UDPSocketCommonQueryAnswerBusiness.GetAnswerModel(sn, 1); } if (answerModel != null) { UserPhoneQueryResultNotifyRequestModel model = (UserPhoneQueryResultNotifyRequestModel)(answerModel.Result); //移除应答缓存数据 UDPSocketCommonQueryAnswerBusiness.Remove(sn); if (model.Result_Code == "0") { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "未查询到该用户")); } } else { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "系统没有响应")); } } else { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "门店设置不正确")); } string templateId = "2"; string key = string.Empty; if (!isSMSTest && !FilterMobileBusiness.ExistMobile(mobile)) { string smsCode = string.Empty; if (SMSBusiness.GetSMSCode(out smsCode)) { key = mobile + "_" + smsCode; SMSCodeCache.Add(key, mobile, CacheExpires.SMSCodeExpires); if (SMSBusiness.SendSMSCode(templateId, mobile, smsCode, out errMsg)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.T, "")); } else { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, errMsg)); } } else { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "发送验证码出错")); } } else { key = mobile + "_" + "123456"; SMSCodeCache.Add(key, mobile, CacheExpires.SMSCodeExpires); return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.T, "")); } } catch (Exception e) { throw e; } }
public object registerUser(Dictionary <string, object> dicParas) { try { string storeId = dicParas.ContainsKey("storeId") ? dicParas["storeId"].ToString() : string.Empty; string mobile = dicParas.ContainsKey("mobile") ? dicParas["mobile"].ToString() : string.Empty; string smsCode = dicParas.ContainsKey("smsCode") ? dicParas["smsCode"].ToString() : string.Empty; string errMsg = string.Empty; int userId = 0; if (string.IsNullOrEmpty(storeId)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "门店号码不正确")); } if (string.IsNullOrEmpty(mobile)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "手机号码不正确")); } if (string.IsNullOrEmpty(smsCode)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "请输入验证码")); } //验证短信验证码 string key = mobile + "_" + smsCode; if (!FilterMobileBusiness.IsTestSMS && !FilterMobileBusiness.ExistMobile(mobile)) { if (!SMSCodeCache.IsExist(key)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "短信验证码无效")); } } if (SMSCodeCache.IsExist(key)) { SMSCodeCache.Remove(key); } //验证门店是否有效 StoreBusiness sb = new StoreBusiness(); StoreCacheModel storeModel = null; if (!sb.IsEffectiveStore(storeId, ref storeModel, out errMsg)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, errMsg)); } if (storeModel.StoreDBDeployType == 0) { //验证用户在分库是否存在 XCCloudService.BLL.IBLL.XCGame.IUserService userService = BLLContainer.Resolve <XCCloudService.BLL.IBLL.XCGame.IUserService>(storeModel.StoreDBName); var gameUserModel = userService.GetModels(p => p.Mobile.Equals(mobile, StringComparison.OrdinalIgnoreCase)).FirstOrDefault <XCCloudService.Model.XCGame.u_users>(); if (gameUserModel == null) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "未查询到该用户")); } userId = gameUserModel.UserID; } else if (storeModel.StoreDBDeployType == 1) { string sn = System.Guid.NewGuid().ToString().Replace("-", ""); UDPSocketCommonQueryAnswerModel answerModel = null; string radarToken = string.Empty; if (DataFactory.SendDataUserPhoneQuery(sn, storeModel.StoreID.ToString(), storeModel.StorePassword, mobile, out radarToken, out errMsg)) { } else { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, errMsg)); } answerModel = null; int whileCount = 0; while (answerModel == null && whileCount <= 25) { //获取应答缓存数据 whileCount++; System.Threading.Thread.Sleep(1000); answerModel = UDPSocketCommonQueryAnswerBusiness.GetAnswerModel(sn, 1); } if (answerModel != null) { UserPhoneQueryResultNotifyRequestModel model = (UserPhoneQueryResultNotifyRequestModel)(answerModel.Result); //移除应答缓存数据 UDPSocketCommonQueryAnswerBusiness.Remove(sn); if (model.Result_Code == "0") { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "未查询到该用户")); } } else { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "系统没有响应")); } userId = 0;//本地库用0 } else { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "门店配置无效")); } //验证用户在总库是否已注册 XCCloudService.BLL.IBLL.XCGameManager.IUserService userServiceManager = BLLContainer.Resolve <XCCloudService.BLL.IBLL.XCGameManager.IUserService>(); var userRegisterModel = userServiceManager.GetModels(p => p.Mobile.Equals(mobile) && p.StoreId.Equals(storeId)).FirstOrDefault <XCCloudService.Model.XCGameManager.t_user>(); if (userRegisterModel == null) { //添加注册用户 XCCloudService.Model.XCGameManager.t_user t_user = new XCCloudService.Model.XCGameManager.t_user(); t_user.Mobile = mobile; t_user.StoreId = storeId; t_user.CreateTime = System.DateTime.Now; t_user.OpenId = ""; if (!userServiceManager.Add(t_user)) { return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "添加注册用户失败")); } } //获取用户token //云库不用userId string token = XCCloudManaUserTokenBusiness.SetToken(mobile, storeId, storeModel.StoreName, userId); List <XCCloudManaUserTokenResultModel> list = null; XCCloudManaUserTokenBusiness.GetUserTokenModel(mobile, ref list); var obj = new { userToken = token, storeList = list }; return(ResponseModelFactory.CreateAnonymousSuccessModel(isSignKeyReturn, obj)); } catch (Exception e) { throw e; } }