示例#1
0
        /// <summary>
        /// 发送短信(短信类型)
        /// </summary>
        /// <param name="smstype">短信类型(修改密码=1,找回密码=2,添加银行卡=3,佣金提现=4,)</param>
        /// <returns>发送短信结果状态信息</returns>
        public HttpResponseMessage SendSmsForbroker([FromBody] string smstype)
        {
            var user = (UserBase)_workContext.CurrentUser;

            if (user != null)
            {
                var broker = _brokerService.GetBrokerByUserId(user.Id); //获取当前经纪人
                if (broker == null)
                {
                    return(PageHelper.toJson(PageHelper.ReturnValue(false, "获取用户失败,请检查是否登陆")));
                }
                var messageConfigName = Enum.GetName(typeof(MessageConfigTypeEnum), Convert.ToInt32(smstype));
                //获取短信模版名称
                var messageTemplate = _messageConfigService.GetMessageConfigByName(messageConfigName).Template;
                //获取到的短信模版
                string messages;
                if (messageConfigName == "推荐经纪人")                  //不需要生成数字验证码
                {
                    messages = string.Format(messageTemplate, ""); //更改模版
                    //添加到短信表中去
                    AddMessageDetails(new MessageDetailEntity
                    {
                        Content = messages,
                        Mobile  = broker.Phone,
                        Sender  = broker.Phone,
                        Title   = messageConfigName,
                        Addtime = DateTime.Now
                    });

                    return(PageHelper.toJson(SMSHelper.Sending(broker.Phone, messages)));
                }
                var strNumber = new Random().Next(100000, 1000000).ToString();
                //生成大于等于100000,小于等于999999的随机数,也就是六位随机数
                var nowTimestr = DateTime.Now.ToLongTimeString();
                var strs       = EncrypHelper.Encrypt(strNumber + "$" + nowTimestr, "Hos2xNLrgfaYFY2MKuFf3g==");
                //EMS 加密短信验证码
                messages = string.Format(messageTemplate, strNumber); //更改模版

                //添加到短信表中去
                AddMessageDetails(new MessageDetailEntity
                {
                    Content = messages,
                    Mobile  = broker.Phone,
                    Sender  = broker.Phone,
                    Title   = messageConfigName,
                    Addtime = DateTime.Now
                });


                //返回到前台的加密内容  和短信发送返回值
                return(PageHelper.toJson(new { Desstr = strs, Message = SMSHelper.Sending(broker.Phone, messages) }));
            }
            return(PageHelper.toJson(PageHelper.ReturnValue(false, "获取用户失败,请检查是否登陆")));
        }
示例#2
0
        /// <summary>
        /// 发送短信验证码
        /// </summary>
        /// <param name="phone">手机号码</param>
        /// <param name="salt">用户密钥,DES加密用</param>
        ///
        /// <returns></returns>
        public static HttpResponseMessage SendMessage6(string phone, string salt)
        {
            string messa = new Random().Next(100000, 1000000).ToString();//生成大于等于100000,小于等于999999的随机数,也就是六位随机数

            if (!string.IsNullOrEmpty(phone))
            {
                var    p      = SMSHelper.Sending(phone, messa);                //给用户发送验证码
                string time   = DateTime.Now.ToLongTimeString();
                var    source = EncrypHelper.Encrypt(messa + "$" + time, salt); //EMS 加密短信验证码
                return(PageHelper.toJson(new { sou = source, messP = p }));
            }
            return(PageHelper.toJson(0));
        }
示例#3
0
        public HttpResponseMessage SendSMS([FromBody] YzMsg yzmsg)
        {
            if (!string.IsNullOrEmpty(yzmsg.Mobile) && !string.IsNullOrEmpty(yzmsg.SmsType))
            {
                var messageConfigName = Enum.GetName(typeof(MessageConfigTypeEnum), Convert.ToInt32(yzmsg.SmsType));
                //获取短信模版名称
                var messageTemplate = _messageConfigService.GetMessageConfigByName(messageConfigName).Template;
                //获取到的短信模版
                string messages;

                var strNumber = new Random().Next(100000, 1000000).ToString();
                //生成大于等于100000,小于等于999999的随机数,也就是六位随机数
                var nowTimestr = DateTime.Now.ToLongTimeString();
                var strs       = EncrypHelper.Encrypt(strNumber + "#" + yzmsg.Mobile + "$" + nowTimestr, "Hos2xNLrgfaYFY2MKuFf3g==");
                //EMS 加密短信验证码

                if (messageConfigName == "推荐经纪人") //不需要生成数字验证码
                {
                    var user = (UserBase)_workContext.CurrentUser;
                    if (user != null)
                    {
                        var broker = _brokerService.GetBrokerByUserId(user.Id); //获取当前经纪人
                        if (broker == null)
                        {
                            return(PageHelper.toJson(PageHelper.ReturnValue(false, "获取用户失败,请检查是否登陆")));
                        }
                        if (broker.Phone == yzmsg.Mobile) //不能给自己发
                        {
                            return(PageHelper.toJson(PageHelper.ReturnValue(false, "对不起,不能给自己发送短信")));
                        }

                        //添加到短信表中去
                        messages = string.Format(messageTemplate, strNumber, broker.Brokername); //更改模版
                        AddMessageDetails(new MessageDetailEntity
                        {
                            Content        = messages,
                            InvitationCode = strNumber,
                            InvitationId   = broker.Id.ToString(),
                            Mobile         = yzmsg.Mobile,
                            Sender         = yzmsg.Mobile,
                            Title          = messageConfigName,
                            Addtime        = DateTime.Now
                        });
                        return(PageHelper.toJson(SMSHelper.Sending(yzmsg.Mobile, messages)));
                    }
                    return(PageHelper.toJson(PageHelper.ReturnValue(false, "获取用户失败,请检查是否登陆")));
                }

                messages = string.Format(messageTemplate, strNumber); //更改模版

                //添加到短信表中去
                AddMessageDetails(new MessageDetailEntity
                {
                    Content = messages,
                    Mobile  = yzmsg.Mobile,
                    Sender  = yzmsg.Mobile,
                    Title   = messageConfigName,
                    Addtime = DateTime.Now
                });


                //返回到前台的加密内容  和短信发送返回值
                return(PageHelper.toJson(new { Desstr = strs, Message = SMSHelper.Sending(yzmsg.Mobile, messages) }));
            }

            return(PageHelper.toJson(PageHelper.ReturnValue(false, "数据错误,不能发送短信")));
        }