예제 #1
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json";
            context.Response.Expires     = 0;
            string        result      = "false";
            string        phone       = context.Request["phone"];
            string        smsContent  = context.Request["smscontent"];
            string        is_register = context.Request["is_register"];
            string        is_reset    = context.Request["is_reset"];
            string        is_member   = context.Request["is_member"];
            string        content     = context.Request["content"];
            List <string> blackIpList = new List <string>();

            blackIpList.Add("139.196.16.189");
            if (blackIpList.Contains(context.Request.UserHostAddress))
            {
                resp.errcode = 1;
                resp.errmsg  = "Ip Invai";
                goto outoff;
            }
            if (string.IsNullOrEmpty(phone))
            {
                resp.errcode = 1;
                resp.errmsg  = "请输入手机号";
                goto outoff;
            }
            if ((!phone.StartsWith("1")) || (!phone.Length.Equals(11)))
            {
                resp.errcode = 2;
                resp.errmsg  = "手机号格式不正确";
                goto outoff;
            }
            if (!ZentCloud.Common.MyRegex.PhoneNumLogicJudge(phone))
            {
                resp.errcode = 2;
                resp.errmsg  = "手机格式不正确";
                goto outoff;
            }
            if (string.IsNullOrEmpty(smsContent))
            {
                resp.errcode = 1;
                resp.errmsg  = "短信内容不能为空";
                goto outoff;
            }
            if (!smsContent.Contains("{{SMSVERCODE}}"))//验证码标签
            {
                resp.errcode = 1;
                resp.errmsg  = "缺少标签{{SMSVERCODE}}";
                goto outoff;
            }
            if (is_register == "1")
            {
                BLLUser bllUser = new BLLUser();
                BLLJIMP.Model.UserInfo ouser = bllUser.GetUserInfoByPhone(phone, bllUser.WebsiteOwner);
                if (ouser != null)
                {
                    resp.errcode = 1;
                    resp.errmsg  = "手机号码已存在账号,请尝试找回密码";
                    goto outoff;
                }
            }
            if (is_reset == "1")
            {
                BLLUser bllUser = new BLLUser();
                BLLJIMP.Model.UserInfo ouser = bllUser.GetUserInfoByPhone(phone, bllUser.WebsiteOwner);
                if (ouser == null)
                {
                    resp.errcode = 1;
                    resp.errmsg  = "手机号未注册";
                    goto outoff;
                }
                if (ouser.IsDisable == 1)
                {
                    resp.errcode = 1;
                    resp.errmsg  = "账号已被禁用";
                    goto outoff;
                }
                if (is_member == "1" && ouser.MemberLevel == 0)
                {
                    resp.errcode = 1;
                    resp.errmsg  = "您不是会员";
                    goto outoff;
                }
            }
            var lastSmsVerificationCode = bllSms.GetLastSmsVerificationCode(phone);

            if (lastSmsVerificationCode != null)
            {
                if ((DateTime.Now - lastSmsVerificationCode.InsertDate).TotalSeconds < 60)
                {
                    resp.errcode = 3;
                    resp.errmsg  = "验证码限制每60秒发送一次";
                    goto outoff;
                }
            }
            bool   isSuccess = false;
            string verCode   = new Random().Next(111111, 999999).ToString();
            string msg       = "";

            smsContent = smsContent.Replace("{{SMSVERCODE}}", verCode);//替换验证码标签
            if (content == "1")
            {
                smsContent = "金融玩家欢迎你,验证码" + verCode;
            }
            string smsSignature = string.Format("{0}", bllSms.GetWebsiteInfoModelFromDataBase().SmsSignature);//短信签名

            bllSms.SendSmsVerificationCode(phone, smsContent, smsSignature, verCode, out isSuccess, out msg);
            if (isSuccess)
            {
                resp.errcode = 0;
                resp.errmsg  = "ok";
                //resp.sms_vercode = verCode;
            }
            else
            {
                resp.errcode = 4;
                resp.errmsg  = string.Format("发送验证码失败{0}", msg);
            }

outoff:
            result = ZentCloud.Common.JSONHelper.ObjectToJson(resp);
            if (!string.IsNullOrEmpty(context.Request["callback"]))
            {
                //返回 jsonp数据
                context.Response.Write(string.Format("{0}({1})", context.Request["callback"], result));
            }
            else
            {
                //返回json数据
                context.Response.Write(result);
            }
        }
예제 #2
0
파일: GetSMSCode.ashx.cs 프로젝트: uvbs/mmp
        public void ProcessRequest(HttpContext context)
        {
            string phone      = context.Request["phone"];
            string smsContent = context.Request["smscontent"];
            string check_user = context.Request["check_user"];
            string limit_user = context.Request["limit_user"];

            #region 判断手机格式
            if (!MyRegex.PhoneNumLogicJudge(phone))
            {
                apiResp.code = (int)APIErrCode.PhoneFormatError;
                apiResp.msg  = "手机格式错误";
                bllSms.ContextResponse(context, apiResp);
                return;
            }
            #endregion
            #region 判断手机是否已被使用,且是否是当前账号
            if (check_user == "1")
            {
                UserInfo model = bllUser.GetUserInfoByPhone(phone);
                if (limit_user == "1" && model == null)
                {
                    apiResp.code = (int)APIErrCode.IsNotFound;
                    apiResp.msg  = "该手机号没有账号";
                    bllSms.ContextResponse(context, apiResp);
                    return;
                }
                if (limit_user == "2" && model != null)
                {
                    apiResp.code = (int)APIErrCode.IsNotFound;
                    apiResp.msg  = "该手机号已有账号";
                    bllSms.ContextResponse(context, apiResp);
                    return;
                }
                if (model != null)
                {
                    UserInfo CurrentUserInfo = bllUser.GetCurrentUserInfo();
                    if (CurrentUserInfo != null && model.UserID != CurrentUserInfo.UserID)
                    {
                        apiResp.code = (int)APIErrCode.OperateFail;
                        apiResp.msg  = "手机号码已被其他账号使用,请联系管理员";
                        bllSms.ContextResponse(context, apiResp);
                        return;
                    }
                    //if (model.IsPhoneVerify == 1)
                    //{
                    //    apiResp.code = (int)APIErrCode.OperateFail;
                    //    apiResp.msg = "手机号码已验证";
                    //    bllSms.ContextResponse(context, apiResp);
                    //    return;
                    //}
                }
            }
            #endregion
            var lastSmsVerificationCode = bllSms.GetLastSmsVerificationCode(phone);
            if (lastSmsVerificationCode != null)
            {
                if ((DateTime.Now - lastSmsVerificationCode.InsertDate).TotalSeconds < 60)
                {
                    apiResp.code = (int)APIErrCode.IsRepeat;
                    apiResp.msg  = "验证码限制每60秒发送一次";
                    bllSms.ContextResponse(context, apiResp);
                    return;
                }
            }
            string verCode      = new Random().Next(111111, 999999).ToString();
            string smsSignature = string.Format("{0}", bllSms.GetWebsiteInfoModelFromDataBase().SmsSignature);//短信签名
            if (string.IsNullOrWhiteSpace(smsContent) || !smsContent.Contains("{{SMSVERCODE}}"))
            {
                smsContent = "手机验证码:{{SMSVERCODE}}";
            }
            smsContent = smsContent.Replace("{{SMSVERCODE}}", verCode);//替换验证码标签
            string msg       = "";
            bool   isSuccess = false;
            bllSms.SendSmsVerificationCode(phone, smsContent, smsSignature, verCode, out isSuccess, out msg);
            if (!isSuccess)
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "手机验证码发送失败";
                bllSms.ContextResponse(context, apiResp);
                return;
            }
            apiResp.status = isSuccess;
            apiResp.code   = (int)APIErrCode.IsSuccess;
            apiResp.msg    = "手机验证码已发送";
            bllSms.ContextResponse(context, apiResp);
        }