コード例 #1
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 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;
            }
        }
コード例 #2
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;
            }
        }