/// <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 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 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; } }