Esempio n. 1
0
        public object checkImgCode(Dictionary <string, object> dicParas)
        {
            try
            {
                string errMsg = string.Empty;
                string mobile = dicParas.ContainsKey("mobile") ? dicParas["mobile"].ToString() : string.Empty;
                string code   = dicParas.ContainsKey("code") ? dicParas["code"].ToString() : string.Empty;
                string sysId  = dicParas.ContainsKey("sysId") ? dicParas["sysId"].ToString() : string.Empty;

                //验证请求次数
                if (!RequestTotalCache.CanRequest(mobile, ApiRequestType.CheckImgCode))
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "已超过单日最大请求次数"));
                }
                else
                {
                    RequestTotalCache.Add(mobile, ApiRequestType.CheckImgCode);
                }

                if (!checkCodeParams(dicParas, out errMsg))
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, errMsg));
                }

                //如果用户未获取验证码
                if (!ValidateImgCache.Exist(code.ToUpper()))
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "验证码无效"));
                }

                string key = mobile + "_" + code;
                SMSTempTokenCache.Add(key, mobile, CacheExpires.SMSTempTokenExpires);
                ValidateImgCache.Remove(code.ToUpper());

                SMSTokenModel smsTokenModel = new SMSTokenModel(mobile, code);
                return(ResponseModelFactory <SMSTokenModel> .CreateModel(isSignKeyReturn, smsTokenModel));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Esempio n. 2
0
        public object checkStoreImgCode(Dictionary <string, object> dicParas)
        {
            try
            {
                string errMsg  = string.Empty;
                string storeId = dicParas.ContainsKey("storeId") ? dicParas["storeId"].ToString() : string.Empty;
                string code    = dicParas.ContainsKey("code") ? dicParas["code"].ToString() : string.Empty;
                string sysId   = dicParas.ContainsKey("sysId") ? dicParas["sysId"].ToString() : string.Empty;

                if (string.IsNullOrEmpty(storeId))
                {
                    errMsg = "storeId参数不能为空";
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, errMsg));
                }

                if (!Utils.isNumber(storeId))
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "店号的格式不正确"));
                }

                if (string.IsNullOrEmpty(code))
                {
                    errMsg = "code参数不能为空";
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, errMsg));
                }

                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();
                string mobile     = storeModel.phone;
                if (string.IsNullOrEmpty(mobile))
                {
                    errMsg = "该门店手机号为空";
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, errMsg));
                }
                if (!Utils.CheckMobile(mobile))
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "手机格式不正确"));
                }

                //验证请求次数
                if (!RequestTotalCache.CanRequest(mobile, ApiRequestType.CheckImgCode))
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "已超过单日最大请求次数"));
                }
                else
                {
                    RequestTotalCache.Add(mobile, ApiRequestType.CheckImgCode);
                }

                //如果用户未获取验证码
                if (!ValidateImgCache.Exist(code.ToUpper()))
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "验证码已过期"));
                }

                string key = mobile + "_" + code;
                SMSTempTokenCache.Add(key, mobile, CacheExpires.SMSTempTokenExpires);
                ValidateImgCache.Remove(code.ToUpper());

                string token      = MobileTokenBusiness.SetMobileToken(mobile);
                var    tokenModel = new {
                    token  = token,
                    mobile = mobile.Substring(0, 3) + "****" + mobile.Substring(7), //屏蔽中间4位手机号码
                    code   = code
                };

                return(ResponseModelFactory.CreateAnonymousSuccessModel(isSignKeyReturn, tokenModel));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Esempio n. 3
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;
            }
        }
Esempio n. 4
0
        public object checkMerch(Dictionary <string, object> dicParas)
        {
            try
            {
                string errMsg = string.Empty;
                string mobile = dicParas.ContainsKey("mobile") ? dicParas["mobile"].ToString() : string.Empty;
                string code   = dicParas.ContainsKey("imgCode") ? dicParas["imgCode"].ToString() : string.Empty;

                if (string.IsNullOrEmpty(mobile))
                {
                    errMsg = "mobile参数不能为空";
                }

                if (string.IsNullOrEmpty(code))
                {
                    errMsg = "验证码不能为空";
                }

                if (!string.IsNullOrEmpty(errMsg))
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, errMsg));
                }

                if (string.IsNullOrWhiteSpace(mobile) || !IsMobile(mobile))
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "请输入正确的手机号码"));
                }

                //验证请求次数
                if (!RequestTotalCache.CanRequest(mobile, ApiRequestType.CheckImgCode))
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "已超过单日最大请求次数"));
                }
                else
                {
                    RequestTotalCache.Add(mobile, ApiRequestType.CheckImgCode);
                }

                //如果用户未获取验证码
                if (!ValidateImgCache.Exist(code.ToUpper()))
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "验证码错误"));
                }

                //验证商户手机号码是否存在
                string         sql        = "select Mobile,State from Base_MerchInfo where Mobile=@Mobile";
                SqlParameter[] parameters = new SqlParameter[1];
                parameters[0] = new SqlParameter("@Mobile", mobile);
                System.Data.DataSet ds = XCCloudRS232BLL.ExecuteQuerySentence(sql, parameters);
                if (ds.Tables[0].Rows.Count == 0)
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "手机号码未注册"));
                }
                else if (ds.Tables[0].Rows[0]["state"].ToString() == "0")
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "该手机号已被禁用"));
                }

                string key = mobile + "_" + code;
                SMSTempTokenCache.Add(key, mobile, CacheExpires.SMSTempTokenExpires);
                ValidateImgCache.Remove(code.ToUpper());

                SMSTokenModel smsTokenModel = new SMSTokenModel(mobile, code);
                return(ResponseModelFactory <SMSTokenModel> .CreateModel(isSignKeyReturn, smsTokenModel));
            }
            catch (Exception e)
            {
                throw e;
            }
        }