示例#1
0
        /// <summary>
        /// 手机码验证错误次数加1
        /// </summary>
        /// <param name="business"></param>
        /// <param name="uniqueKey"></param>
        public void IncreaseErrorCount(SMSBusiness business, string uniqueKey)
        {
            SecurityMethod securityMethod = SecurityMethod.CellphoneCode;
            var            errorKey       = $"{Platform}:{securityMethod.ToString()}:{business.ToString()}:ErrorCounts:{uniqueKey}";

            var errorCountsStr = RedisHelper.StringGet(Constant.REDIS_SMS_DBINDEX, errorKey);

            int.TryParse(errorCountsStr, out int errorCount);
            ++errorCount;
            int spInt = Constant.VIRIFY_FAILD_LOCK_TIME;

            if (business == SMSBusiness.Register || business == SMSBusiness.UpdateCellphoneNew)
            {
                spInt = Constant.REGISTER_FAILD_LOCK_TIME;
            }
            RedisHelper.StringSet(Constant.REDIS_SMS_DBINDEX, errorKey, errorCount.ToString(), TimeSpan.FromMinutes(spInt));
            if (errorCount >= Constant.VIRIFY_FAILD_TIMES_LIMIT)
            {
                var minCount = GetErrorLockTime(Constant.REDIS_SMS_DBINDEX, errorKey);
                ThrowMoreTimesException(business, minCount);
            }
            else
            {
                ThrowVerifyFaildException(securityMethod, Constant.VIRIFY_FAILD_TIMES_LIMIT - errorCount);
            }
        }
示例#2
0
        /// <summary>
        /// 获取短信余额
        /// </summary>
        /// <param name="pid">产品编号</param>
        /// <returns></returns>
        public object balance(Dictionary <string, object> dicParas)
        {
            string pid    = dicParas.ContainsKey("pid") ? dicParas["pid"].ToString() : "";
            string errMsg = string.Empty;

            if (!checkBalanceParams(dicParas, out errMsg))
            {
                ResponseModel responseModel = new ResponseModel(Return_Code.T, "", Result_Code.F, errMsg);
                return(responseModel);
            }

            string state  = string.Empty;
            int    remain = 0;

            SMSBusiness.GetBalance(pid, out state, out remain);
            if (state == "0")
            {
                SMSBalanceResponseModel smsResponseModel = new SMSBalanceResponseModel(remain);
                ResponseModel <SMSBalanceResponseModel> responseModel = new ResponseModel <SMSBalanceResponseModel>(smsResponseModel);
                return(responseModel);
            }
            else
            {
                ResponseModel responseModel = new ResponseModel(Return_Code.T, "", Result_Code.F, errMsg);
                return(responseModel);
            }
        }
示例#3
0
        public static void SendWithExtension(this SMSCodeComponent scc, SMSBusiness business, string uniqueKey, string cellphone, object extension)
        {
            scc.Send(business, uniqueKey, cellphone);
            var cacheExtensionKey = $"{scc.Platform}:{business}:Code:{uniqueKey}:Extension";

            RedisHelper.Set(Constant.REDIS_SMS_DBINDEX, cacheExtensionKey, extension, TimeSpan.FromMinutes(Constant.TEMPTOKEN_EXPIRED_TIME));
        }
示例#4
0
        /// <summary>
        /// 发送短信
        /// </summary>
        /// <param name="dicParas"></param>
        /// <returns></returns>
        public object send(Dictionary <string, object> dicParas)
        {
            //广告类  1012812;验证码类 1012818
            string errMsg = string.Empty;
            string type   = dicParas.ContainsKey("type") ? dicParas["type"].ToString() : "";
            string mobile = dicParas.ContainsKey("mobile") ? dicParas["mobile"].ToString() : "";
            string body   = (dicParas.ContainsKey("body") ? dicParas["body"].ToString() : "") + " 退订回T 【莘宸科技】";

            if (!checkSendParams(dicParas, out errMsg))
            {
                ResponseModel responseModel = new ResponseModel(Return_Code.T, "", Result_Code.F, errMsg);
                return(responseModel);
            }

            try
            {
                string state = SMSBusiness.Send(type, mobile, body);
                //发送成功
                if (state == "0")
                {
                    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);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#5
0
        /// <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);
            }
        }
示例#6
0
        /// <summary>
        /// 验证发送参数
        /// </summary>
        /// <param name="dicParas"></param>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        private bool checkSendParams(Dictionary <string, object> dicParas, out string errMsg)
        {
            errMsg = string.Empty;
            string mobile = dicParas.ContainsKey("mobile") ? dicParas["mobile"].ToString().Trim() : "";
            string body   = dicParas.ContainsKey("body") ? dicParas["body"].ToString().Trim() : "";
            string type   = dicParas.ContainsKey("type") ? dicParas["type"].ToString() : "";

            if (SMSBusiness.GetSMSType(type) == string.Empty)
            {
                errMsg = "短信类型不正确";
                return(false);
            }

            if (!Utils.CheckMobile(mobile))
            {
                errMsg = "手机号不正确";
                return(false);
            }

            if (string.IsNullOrEmpty(body))
            {
                errMsg = "消息内容不能为空";
                return(false);
            }

            return(true);
        }
示例#7
0
文件: Startup.cs 项目: a602123/CLMS
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });


            //初始化采集中心
            //MonitorBusiness.GetInstance();
            MonitorCenter.GetInstance().Init(new LineBusiness().GetAllItems());
            MonitorCenter.GetInstance().Start();
            SMSBusiness.GetInstance();
        }
        public ActionResult SendSms(int id)
        {
            string errMsg  = string.Empty;
            var    userIDs = getFinalBiddingInfoList(id).GroupBy(g => g.UserID).Select(o => o.Key).ToList();
            IBase_UserInfoService base_UserInfoService = BLLContainer.Resolve <IBase_UserInfoService>();
            var    userMobiles = base_UserInfoService.GetModels(p => userIDs.Contains(p.ID)).Select(o => o.Mobile).ToList();
            string phones      = string.Join(",", userMobiles);

            IData_SmsManageService data_SmsManageService = BLLContainer.Resolve <IData_SmsManageService>();
            var data_SmsManage = new Data_SmsManage();

            data_SmsManage.CreateTime = DateTime.Now;
            data_SmsManage.Phones     = phones;
            data_SmsManage.State      = (int)SmsType.Send;
            if (!data_SmsManageService.Add(data_SmsManage))
            {
                return(RedirectToAction("NoticePublish", "NoticeManage", new { errMsg = "发送失败" }));
            }

            //发送短信
            if (!SMSBusiness.SendSMSNotice("2", data_SmsManage.Phones, "", out errMsg))
            {
                return(RedirectToAction("NoticePublish", "NoticeManage", new { errMsg = errMsg }));
            }

            return(RedirectToAction("NoticePublish", "NoticeManage", new { errMsg = "发送成功" }));
        }
示例#9
0
        public static void DeleteCodeWithExtension(this SMSCodeComponent scc, SMSBusiness business, string uniqueKey)
        {
            scc.DeleteSMSCode(business, uniqueKey);
            var cacheExtensionKey = $"{scc.Platform}:{business}:Code:{uniqueKey}:Extension";

            RedisHelper.KeyDelete(Constant.REDIS_SMS_DBINDEX, cacheExtensionKey);
        }
示例#10
0
        /// <summary>
        /// 验证获取短信余量参数
        /// </summary>
        /// <param name="dicParas"></param>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        private bool checkBalanceParams(Dictionary <string, object> dicParas, out string errMsg)
        {
            errMsg = string.Empty;
            string pid = dicParas.ContainsKey("pid") ? dicParas["pid"].ToString() : "";

            if (!SMSBusiness.CheckPid(pid))
            {
                errMsg = "短信类型不正确";
                return(false);
            }

            return(true);
        }
示例#11
0
        public static T VerifyWithExtension <T>(this SMSCodeComponent scc, SMSBusiness business, string uniqueKey, string code, bool deleteCode)
        {
            scc.Verify(business, uniqueKey, code, deleteCode);

            var cacheExtensionKey = $"{scc.Platform}:{business}:Code:{uniqueKey}:Extension";
            var cacheExtension    = RedisHelper.Get <T>(Constant.REDIS_SMS_DBINDEX, cacheExtensionKey);

            if (deleteCode)
            {
                RedisHelper.KeyDelete(Constant.REDIS_SMS_DBINDEX, cacheExtensionKey);
            }

            return(cacheExtension);
        }
示例#12
0
        /// <summary>
        /// 手机码验证错误次数检查
        /// </summary>
        /// <param name="business"></param>
        /// <param name="uniqueKey"></param>
        /// <returns></returns>
        public int CheckErrorCount(SMSBusiness business, string uniqueKey)
        {
            SecurityMethod securityMethod = SecurityMethod.CellphoneCode;
            var            errorKey       = $"{Platform}:{securityMethod.ToString()}:{business.ToString()}:ErrorCounts:{uniqueKey}";
            var            errorCountsStr = RedisHelper.StringGet(Constant.REDIS_SMS_DBINDEX, errorKey);

            int.TryParse(errorCountsStr, out int errorCount);
            if (errorCount >= Constant.VIRIFY_FAILD_TIMES_LIMIT)
            {
                var minCount = GetErrorLockTime(Constant.REDIS_SMS_DBINDEX, errorKey);
                ThrowMoreTimesException(business, minCount);
            }
            return(errorCount);
        }
        // GET: SmsManage
        public ActionResult SendSms(string phones, string message, int id = 0)
        {
            string errMsg = string.Empty;

            if (string.IsNullOrEmpty(phones))
            {
                errMsg = "手机号不能不能为空";
                return(RedirectToAction("Index", "SmsManage", new { errMsg = errMsg }));
            }

            if (string.IsNullOrEmpty(message))
            {
                errMsg = "短信内容不能为空";
                return(RedirectToAction("Index", "SmsManage", new { errMsg = errMsg }));
            }

            IData_SmsManageService data_SmsManageService = BLLContainer.Resolve <IData_SmsManageService>();
            var data_SmsManage = new Data_SmsManage();

            if (id == 0)
            {
                data_SmsManage.CreateTime = DateTime.Now;
                data_SmsManage.Message    = message;
                data_SmsManage.Phones     = phones.Replace(",", ",");
                data_SmsManage.State      = (int)SmsType.Send;
                if (!data_SmsManageService.Add(data_SmsManage))
                {
                    return(RedirectToAction("Index", "SmsManage", new { errMsg = "发送失败" }));
                }
            }
            else
            {
                data_SmsManage         = data_SmsManageService.GetModels(p => p.ID == id).FirstOrDefault();
                data_SmsManage.Message = message;
                data_SmsManage.Phones  = phones.Replace(",", ",");
                if (!data_SmsManageService.Update(data_SmsManage))
                {
                    return(RedirectToAction("Index", "SmsManage", new { errMsg = "发送失败" }));
                }
            }

            //发送短信
            if (!SMSBusiness.SendSMSNotice("1", data_SmsManage.Phones, data_SmsManage.Message, out errMsg))
            {
                return(RedirectToAction("Index", "SmsManage", new { errMsg = errMsg }));
            }

            return(RedirectToAction("Index", "SmsManage", new { errMsg = "发送成功" }));
        }
示例#14
0
        /// <summary>
        /// 手机验证码多次错误异常
        /// </summary>
        /// <param name="business"></param>
        /// <param name="minCount"></param>
        private void ThrowMoreTimesException(SMSBusiness business, int minCount)
        {
            switch (business)
            {
            case SMSBusiness.Login:
                throw new CommonException(ReasonCode.LOGIN_ERROR_TOO_MANY_TIMES_BYSMS, string.Format(GeneralResources.EMLoginSMSCodeTry5Times, minCount));

            case SMSBusiness.Register:
            case SMSBusiness.UpdateCellphoneNew:
                throw new CommonException(ReasonCode.PHONECODE_VERIFYFAILED_TOOMANY_TEIMS, string.Format(GeneralResources.EMRegisterVerifyLimit5Times, minCount));

            default:
                throw new CommonException(ReasonCode.PHONECODE_VERIFYFAILED_TOOMANY_TEIMS, string.Format(GeneralResources.EMVerifyLimit5Times, minCount));
            }
        }
示例#15
0
        protected void Application_Start()
        {
            // ModelBinders.Binders.Add(typeof (Consultation), new DebugModelBinder());
            //Bootstrap.Configure();
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            InitializeBusiness.Initilize();
            var send    = new NotificationBusiness();
            var sendSMS = new SMSBusiness();

            send.sendNotification();
            sendSMS.sendSMS();
            //throw new Exception(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
        }
示例#16
0
        public void Verify(SMSBusiness business, string uniqueKey, string code, bool deleteCode)
        {
            bool isOnlyCellphoneVerify = business != SMSBusiness.SecurityValidate;
            var  securityVerify        = new SecurityVerification(Platform);

            if (isOnlyCellphoneVerify)
            {
                securityVerify.CheckErrorCount(business, uniqueKey);
            }

            var keyByCode = $"{Platform.ToString()}:{SecurityMethod.CellphoneCode.ToString()}:{business.ToString()}:Code:{uniqueKey}";
            var codeInDb  = RedisHelper.StringGet(Constant.REDIS_SMS_DBINDEX, keyByCode);

            if (codeInDb != null && codeInDb == code)//验证通过
            {
                if (deleteCode)
                {
                    DeleteSMSCode(business, uniqueKey);
                }
                else
                {
                    //如果验证通过,并且不删除这个验证码,表示以后还要用这个验证码验证
                    RedisHelper.KeyExpire(keyByCode, TimeSpan.FromMinutes(Constant.SMS_EXPIRED_TIME));
                }
                if (isOnlyCellphoneVerify)
                {
                    securityVerify.DeleteErrorCount(business, uniqueKey);
                }
                return;
            }
            if (isOnlyCellphoneVerify)
            {
                securityVerify.IncreaseErrorCount(business, uniqueKey);
            }
            else
            {
                securityVerify.IncreaseErrorCount(SecurityMethod.SecurityValidate, uniqueKey, SecurityMethod.CellphoneCode);
            }
        }
示例#17
0
        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, ""));
            }
        }
示例#18
0
        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;
            }
        }
示例#19
0
        public void DeleteSMSCode(SMSBusiness business, string uniqueKey)
        {
            var keyByCode = $"{Platform.ToString()}:{SecurityMethod.CellphoneCode.ToString()}:{business.ToString()}:Code:{uniqueKey}";

            RedisHelper.KeyDelete(Constant.REDIS_SMS_DBINDEX, keyByCode);
        }
示例#20
0
        public void Send(SMSBusiness business, string uniqueKey, string cellphone)
        {
            new SecurityVerification(Platform).CheckErrorCount(business, uniqueKey);

            var isTestSMS       = System.Configuration.ConfigurationManager.AppSettings["Test_Sms"] == "1";
            var keyByCount      = $"{Platform}:SMSSend:Count:{cellphone}";
            var keyTimeInterval = $"{Platform}:SMSSend:Interval:{cellphone}:{business}";

            var interval = RedisHelper.StringGet(Constant.REDIS_SMS_DBINDEX, keyTimeInterval);

            if (interval == "1")
            {
                return;
            }

            var limit = string.IsNullOrWhiteSpace(Constant.SEND_SMS_LIMIT) ? 20 : Convert.ToInt32(Constant.SEND_SMS_LIMIT);

            var countStr = RedisHelper.StringGet(Constant.REDIS_SMS_DBINDEX, keyByCount);

            int.TryParse(countStr, out int count);
            if (count >= limit)
            {
                throw new CommonException(ReasonCode.PHONECODE_SEND_TOOMANY_TIMES, GeneralResources.SMSLimit);
            }
            var dateNow           = DateTime.Now;
            var tomorrowStartTime = new DateTime(dateNow.Year, dateNow.Month, dateNow.Day).AddDays(1);

            RedisHelper.StringSet(Constant.REDIS_SMS_DBINDEX, keyByCount, (count + 1).ToString(), tomorrowStartTime - dateNow);//一天内限制发送条数,每天重置

            var keyByCode = $"{Platform}:{SecurityMethod.CellphoneCode}:{business}:Code:{uniqueKey}";

            var code = string.Empty;

            //var codeInDb = RedisHelper.StringGet(Constant.REDIS_SMS_DBINDEX, keyByCode);
            //if (!string.IsNullOrEmpty(codeInDb))
            //{
            //    code = codeInDb;
            //}
            //else
            //{
            //    code = isTestSMS ? "123456" : new Random().Next(0, 1000000).ToString("000000");
            //    RedisHelper.StringSet(Constant.REDIS_SMS_DBINDEX, keyByCode, code, TimeSpan.FromMinutes(Constant.SMS_EXPIRED_TIME));
            //}

            //暂定每次发送的验证码不同
            code = isTestSMS ? "123456" : new Random().Next(0, 1000000).ToString("000000");
            RedisHelper.StringSet(Constant.REDIS_SMS_DBINDEX, keyByCode, code, TimeSpan.FromMinutes(Constant.SMS_EXPIRED_TIME));

            string template = string.Empty;

            switch (Platform)
            {
            case SystemPlatform.FiiiPOS:
                template = GeneralResources.SMS_Template_POS;
                break;

            case SystemPlatform.FiiiPay:
                template = GeneralResources.SMS_Template_FiiiPay;
                break;
            }

            string msmStr = string.Format(template, code, Constant.SMS_EXPIRED_TIME);

            if (!isTestSMS)
            {
                new SMSAgent().Send(cellphone, msmStr, 5);
            }

            Info($"SMSSend:PlateForm:{Platform},Business:{business},Cellphone:{cellphone},Content:{msmStr}");

            RedisHelper.StringSet(Constant.REDIS_SMS_DBINDEX, keyTimeInterval, "1", new TimeSpan(0, 1, 0));
        }
示例#21
0
        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;
            }
        }
示例#22
0
        /// <summary>
        /// 清除手机码验证错误次数
        /// </summary>
        /// <param name="business"></param>
        /// <param name="uniqueKey"></param>
        public void DeleteErrorCount(SMSBusiness business, string uniqueKey)
        {
            var errorKey = $"{Platform}:{SecurityMethod.CellphoneCode.ToString()}:{business.ToString()}:ErrorCounts:{uniqueKey}";

            RedisHelper.KeyDelete(Constant.REDIS_SMS_DBINDEX, errorKey);
        }