/// <summary>
        /// 获取验证码
        /// </summary>
        /// <param name="vCodeModel">验证码类型</param>
        public void GetSmsVerifyCode(string appSign, VerifyCodeViewModel vCodeModel)
        {
            try
            {
                if (vCodeModel == null)
                {
                    throw new MessageException("获取验证码参数不可为空!");
                }
                if (vCodeModel.TerminalSign == null)
                {
                    throw new MessageException("终端标识不可为空!");
                }
                VerifyCodeType verifyCodeType = (VerifyCodeType)Extensions.ToInt(vCodeModel.CodeType, 1);
                SmsFuncType    funcType       = verifyCodeType == VerifyCodeType.BindMobile ? SmsFuncType.BindMobile : SmsFuncType.Login;
                var            verifyCode     = service.GetVerifyCode(appSign, vCodeModel.Mobile, vCodeModel.TerminalSign, verifyCodeType);

                // 3.调用发送邮件接口,发送验证码
                string  title              = string.Empty;
                string  content            = string.Empty;
                SmsType smsType            = SmsType.UnKnown;
                decimal validateCodeExpire = ConfigUtil.ValidatecodeExpire / 60;
                switch (verifyCodeType)
                {
                case VerifyCodeType.Login:
                case VerifyCodeType.BindMobile:
                {
                    smsType = SmsType.ValidateCode;
                    content = string.Format(MsgTemplateUtil.MsgDict["SmsValidCode"], verifyCode, validateCodeExpire);
                    break;
                }

                default:
                {
                    throw new MessageException("未知的验证码类型!");
                }
                }

                if (!string.IsNullOrWhiteSpace(content))
                {
                    //发送短信
                    if (verifyCodeType == VerifyCodeType.Login || verifyCodeType == VerifyCodeType.BindMobile)
                    {
                        var parms = new Dictionary <string, object>();
                        parms.Add("code", verifyCode);
                        parms.Add("code_expire", validateCodeExpire);
                        SingleInstance <SmsBLL> .Instance.SendSmsMsg(appSign, vCodeModel.Mobile, parms, content, smsType, funcType);
                    }
                }
            }
            catch (Exception ex)
            {
                LogUtil.Error(ex.StackTrace);
                throw new MessageException(ex.Message);
            }
        }
        /// <summary>
        /// 发送短信
        /// </summary>
        /// <param name="appSign"></param>
        /// <param name="mobile"></param>
        /// <param name="content"></param>
        /// <param name="smsType"></param>
        /// <returns></returns>
        public void SendSmsMessage(string appSign, string mobile, Dictionary <string, object> parms, string content, SmsType smsType, SmsFuncType funcType)
        {
            // 参数检查
            if (string.IsNullOrWhiteSpace(appSign))
            {
                throw new MessageException("应用标识不能为空!");
            }
            if (string.IsNullOrWhiteSpace(mobile))
            {
                throw new MessageException("手机号码不能为空!");
            }
            if (parms.Count <= 0)
            {
                throw new MessageException("短信内容参数不能为空!");
            }
            if (string.IsNullOrWhiteSpace(content))
            {
                throw new MessageException("短信内容不能为空!");
            }
            if (!Extensions.IsMobile(mobile))
            {
                throw new MessageException(string.Format("手机号码:{0},格式不正确。" + mobile));
            }

            //创建短信记录
            var entity = new SmsEntity();

            entity.AppSign      = appSign;
            entity.ReceiverCode = mobile;
            entity.SmsContent   = content;
            entity.SmsType      = smsType.GetHashCode();
            entity.CreateUserId = mobile;
            var smsId = InsertEntity(entity);

            switch (smsType)
            {
            case SmsType.ValidateCode:
                SmsUtil.SendValidCode(mobile, parms["code"].ToString(), Extensions.ToDecimal(parms["code_expire"], 2), funcType);
                break;

            default:
                break;
            }
        }
        /// <summary>
        /// 获取验证码
        /// </summary>
        /// <param name="email">邮箱地址</param>
        /// <param name="mobile">手机号码</param>
        /// <returns>已有的验证码</returns>
        public void GetVerifyCode(string appSign, VerifyCodeType verifyCodeType, SmsFuncType tempType, string terminalSign, string email, string mobile)
        {
            // 1.校验请求参数
            CheckGetUserVerifyCode(appSign, verifyCodeType, terminalSign, email, mobile);

            // 2.获取新验证码
            string verifyCode = SingleInstance <VerifyCodeService> .Instance.BuildVerifyCode(appSign, terminalSign, email, mobile);

            // 3.调用发送邮件接口,发送验证码
            string    title              = string.Empty;
            string    content            = string.Empty;
            EmailType emlType            = EmailType.UnKnown;
            SMSType   smsType            = SMSType.UnKnown;
            decimal   validateCodeExpire = ConfigUtil.ValidatecodeExpire / 60;

            switch (verifyCodeType)
            {
            case VerifyCodeType.BindEmail:
            {
                emlType = EmailType.Bind;
                title   = "yingmei.me邮箱验证";
                content = string.Format(TemplateConfigUtil.EmlDic["BindEmail"], verifyCode, validateCodeExpire);
                break;
            }

            case VerifyCodeType.BindMobile:
            {
                smsType = SMSType.Bind;
                content = string.Format(TemplateConfigUtil.EmlDic["SmsValidCode"], verifyCode, validateCodeExpire);
                break;
            }

            case VerifyCodeType.ModifyPwdByMobile:
            {
                smsType = SMSType.Bind;
                content = string.Format(TemplateConfigUtil.EmlDic["SmsValidCode"], verifyCode, validateCodeExpire);
                break;
            }

            case VerifyCodeType.GetPwdByMobile:
            {
                smsType = SMSType.Bind;
                content = string.Format(TemplateConfigUtil.EmlDic["SmsValidCode"], verifyCode, validateCodeExpire);
                break;
            }

            case VerifyCodeType.UpdateBindMobile:
            {
                smsType = SMSType.Bind;
                content = string.Format(TemplateConfigUtil.EmlDic["SmsValidCode"], verifyCode, validateCodeExpire);
                break;
            }

            default:
            {
                throw new MessageException("未知的验证码类型!");
            }
            }

            if (!string.IsNullOrWhiteSpace(content))
            {
                int codeType = (int)verifyCodeType;
                if (codeType == (int)VerifyCodeType.BindEmail)
                {
                    //发送邮件(暂时没有邮件发送)
                    //SingleInstance<EmailService>.Instance.SubmitEmail(email, title, content.ToString(), emlType);
                }

                //发送短信
                if (verifyCodeType == VerifyCodeType.BindMobile ||
                    verifyCodeType == VerifyCodeType.ModifyPwdByMobile ||
                    verifyCodeType == VerifyCodeType.GetPwdByMobile ||
                    verifyCodeType == VerifyCodeType.UpdateBindMobile
                    )
                {
                    Dictionary <string, object> parms = new Dictionary <string, object>();
                    parms.Add("code", verifyCode);
                    parms.Add("code_expire", validateCodeExpire);
                    SingleInstance <SysService> .Instance.SendSmsMessage(appSign, mobile, parms, content, smsType, tempType);
                }
            }
        }
Example #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="appSign"></param>
 /// <param name="mobile"></param>
 /// <param name="parms"></param>
 /// <param name="content"></param>
 /// <param name="smsType"></param>
 /// <param name="funcType"></param>
 public void SendSmsMsg(string appSign, string mobile, Dictionary <string, object> parms, string content, SmsType smsType, SmsFuncType funcType)
 {
     service.SendSmsMessage(appSign, mobile, parms, content, smsType, funcType);
 }
Example #5
0
        /// <summary>
        /// 验证码
        /// </summary>
        /// <param name="mobile">手机号</param>
        /// <param name="validateCode">验证码</param>
        public static void SendValidCode(string mobile, string validateCode, decimal validateCodeExpire, SmsFuncType type)
        {
            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("code", validateCode);
            dic.Add("code_expire", validateCodeExpire);
            string[] paramArray = new string[] { validateCode, validateCodeExpire.ToString() };

            //发送渠道
            var sendWay = ConfigUtil.SmsWay;

            switch (type)
            {
            case SmsFuncType.OpenRegister:
                switch (sendWay)
                {
                case "0":
                    var smsParam = "{\"code\":\"" + validateCode + "\",\"second\":\"" + validateCodeExpire + "\"}";
                    SendSmsByAli(mobile, smsParam, SmsTemplateType.OPEN_DY_ValidCode.GetHashCode());
                    break;

                case "1":
                    SendSmsByRly(mobile, paramArray, SmsTemplateType.OPEN_RLY_ValidCode.GetHashCode());
                    break;

                default:
                    break;
                }
                break;

            case SmsFuncType.OpenModifyPwd:
                switch (sendWay)
                {
                case "0":
                    var smsParam = "{\"code\":\"" + validateCode + "\",\"second\":\"" + validateCodeExpire + "\"}";
                    SendSmsByAli(mobile, smsParam, SmsTemplateType.OPEN_DY_ValidCode.GetHashCode());
                    break;

                case "1":
                    SendSmsByRly(mobile, paramArray, SmsTemplateType.OPEN_RLY_ValidCodeForMpwd.GetHashCode());
                    break;

                default:
                    break;
                }
                break;

            default:
                break;
            }
        }
Example #6
0
        /// <summary>
        /// 发送短信
        /// </summary>
        /// <param name="appSign"></param>
        /// <param name="mobile"></param>
        /// <param name="content"></param>
        /// <param name="smsType"></param>
        /// <returns></returns>
        public void SendSmsMessage(string appSign, string mobile, Dictionary <string, object> parms, string content, SMSType smsType, SmsFuncType tempType)
        {
            // 参数检查
            if (string.IsNullOrWhiteSpace(appSign))
            {
                throw new MessageException("应用标识不能为空!");
            }
            if (string.IsNullOrWhiteSpace(mobile))
            {
                throw new MessageException("手机号码不能为空!");
            }
            if (parms.Count <= 0)
            {
                throw new MessageException("短信内容参数不能为空!");
            }
            if (string.IsNullOrWhiteSpace(content))
            {
                throw new MessageException("短信内容不能为空!");
            }
            if (!RegexUtil.IsMobile(mobile))
            {
                throw new MessageException(string.Format("手机号码:{0},格式不正确。" + mobile));
            }

            var smsId = CreateSmsRecord(appSign, mobile, content, smsType);

            switch (smsType)
            {
            case SMSType.Bind:
            case SMSType.UnBind:
            case SMSType.GetPwd:
            case SMSType.ValidateCode:
                SmsUtil.SendValidCode(mobile, parms["code"].ToString(), TryConvertUtil.ToDecimal(parms["code_expire"], 2), tempType);
                break;

            default:
                break;
            }
        }
        /// <summary>
        /// 验证码
        /// </summary>
        /// <param name="mobile">手机号</param>
        /// <param name="validateCode">验证码</param>
        public static void SendValidCode(string mobile, string validateCode, decimal validateCodeExpire, SmsFuncType funcType)
        {
            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("code", validateCode);
            dic.Add("code_expire", validateCodeExpire);
            string[] paramArray = new string[] { validateCode, validateCodeExpire.ToString() };

            //发送渠道
            var sendWay = ConfigUtil.SmsWay;

            switch (funcType)
            {
            case SmsFuncType.Login:
            case SmsFuncType.BindMobile:
                switch (sendWay)
                {
                case 0:
                    SendCodeSms(mobile, validateCode, validateCodeExpire);
                    break;

                case 1:
                    SendSmsByRly(mobile, paramArray, SmsTemplateType.ORD_RLY_ValidCodeLogin.GetHashCode());
                    break;

                default:
                    break;
                }
                break;

            default:
                break;
            }
        }