示例#1
0
        private void GetMobildCode(string strSMSType)
        {
            string randomNumber = StringUtils.GetRandomNumber(5, true);
            string strContent   = string.Empty;

            if (strSMSType == "reg")
            {
                strContent = base.GetConfigValue("RegSMSCheckCode").Replace("${checkcode}", randomNumber);
            }
            else if (strSMSType == "findpwd")
            {
                strContent = base.GetConfigValue("GetPwdSMSCheckCode").Replace("${username}", WebUtils.GetQueryString("username")).Replace("${checkcode}", randomNumber);
            }
            else if (strSMSType == "bind")
            {
                strContent = base.GetConfigValue("BindSMSCheckCode").Replace("${username}", WebUtils.GetQueryString("username")).Replace("${checkcode}", randomNumber);
            }
            string queryString = WebUtils.GetQueryString("paramval");
            string s           = "{\"ret\":\"fail\",\"timeout\":0,\"msg\":\"短信验证码发送失败\"}";
            bool   flag        = true;

            if (!string.IsNullOrEmpty(queryString))
            {
                if ((strSMSType == "reg" || strSMSType == "bind") && SinGooCMS.BLL.User.IsExistsByMobile(queryString))
                {
                    s = "{\"ret\":\"exists\",\"timeout\":0,\"msg\":\"手机号码已经存在\"}";
                }
                else
                {
                    SMSInfo lastCheckCode = SMS.GetLastCheckCode(queryString);
                    if (lastCheckCode != null)
                    {
                        System.TimeSpan timeSpan = System.DateTime.Now - lastCheckCode.AutoTimeStamp;
                        if (timeSpan.TotalSeconds < 60.0)
                        {
                            flag = false;
                            s    = "{\"ret\":\"fail\",\"timeout\":" + (60.0 - timeSpan.TotalSeconds).ToString("f0") + ",\"msg\":\"发送间隔太短\"}";
                        }
                    }
                    if (flag)
                    {
                        if (MsgService.SendSMSCheckCode(queryString, strContent, randomNumber) > 0)
                        {
                            s = "{\"ret\":\"success\",\"timeout\":60,\"msg\":\"短信验证码发送成功,请注意查收!\"}";
                        }
                    }
                }
            }
            base.Response.Write(s);
        }