示例#1
0
        public JsonResult Send(SendDetailDataObj sendobj)
        {
            string rs = "发送失败!";

            CommunicateManager.Invoke <IConsoSMSService>(p =>
            {
                rs = p.SmsSend(sendobj);
            });
            return(Json(rs));
        }
示例#2
0
        public string SmsSend(SendDetailDataObj SendDetailobj)
        {
            string code        = AuthManager.GetCurrentUser().Code;
            var    businessman = businessmanRepository.FindAll(x => x.Code == code).SingleOrDefault();
            var    currentUser = AuthManager.GetCurrentUser();

            if (currentUser == null)
            {
                throw new CustomException(404, "获取信息失败,请稍后再试!");
            }
            if (string.IsNullOrEmpty(SendDetailobj.Content))
            {
                throw new CustomException(400, "发送短信内容不能为空!");
            }
            if (SendDetailobj.Content.Length > 300)
            {
                throw new CustomException(400, "短信内容只能在300字数内!");
            }

            string[] phones = SendDetailobj.ReceiveNum.ToString().Replace("\r\n", "").Trim().Replace(',', ',').Split(new char[] { ',' });
            if (phones.Length > 0)
            {
                for (int i = 0; i < phones.Length; i++)
                {
                    if (!Regex.IsMatch(phones[i], "(^1[358]\\d{9}$)"))
                    {
                        throw new CustomException(400, "手机号格式有误:" + phones[i]);
                    }
                    else if (phones.Length > 100)
                    {
                        throw new CustomException(400, "手机号码最多为20个!");
                    }
                }
            }
            int sendCount = Convert.ToInt32(Math.Ceiling((double)SendDetailobj.Content.Length / 64));

            if (sendCount * phones.Length > businessman.SMS.RemainCount)
            {
                throw new CustomException(400, "你的短信余额不足,请充值购买!");
            }
            int countok = 0, counterr = 0, sendokcount = 0;

            for (int i = 0; i < phones.Length; i++)
            {
                var model = AutoMapper.Mapper.Map <SendDetailDataObj, SendDetail>(SendDetailobj);
                model.SendTime   = DateTime.Now;
                model.Name       = currentUser.OperatorName;
                model.SendCount  = sendCount;
                model.ReceiveNum = phones[i].ToString();
                int sendrs = new SMSDefaultService().SendSms(phones[i], SendDetailobj.Content);
                if (sendrs > 0)
                {
                    model.SendState = true;
                    countok++;
                    sendokcount += sendCount;
                }
                else
                {
                    counterr++;
                }
                businessman.SendDetails.Add(model);
            }
            businessman.SMS.RemainCount -= sendokcount;
            businessman.SMS.SendCount   += sendokcount;
            unitOfWorkRepository.PersistUpdateOf(businessman);
            unitOfWork.Commit();
            return("成功发送:" + countok + "条(计费" + sendokcount + "条),发送失败:" + counterr + "条");
        }