Пример #1
0
        public void SendSMS(SendSMSParameter param)
        {
            var client = GetSMSSender(param);

            client.Form["to"]      = param.ReceiveMobile;
            client.Form["content"] = param.SendMessage;
            client.Form["time"]    = string.Empty;
            client.SetRequest(client.BuildUri(client.Form["url"], client.Form));
            using (var context = base.CreateContext())
            {
                int maxSentPreDay = 3;
                var q             = from t in context.SMSMessages
                                    where t.ReceiveMobile == param.ReceiveMobile && t.AppID == param.AppID &&
                                    DateTime.UtcNow.AddDays(-1D) <= t.SendDate && t.SendDate <= DateTime.UtcNow.AddDays(1D)
                                    select t;
                int count = q.Count();
                if (count > maxSentPreDay)
                {
                    throw new InvalidInvokeException("SendSMS");
                }

                var pObj = new SMSMessage();
                EntityMapper.Map <SendSMSParameter, SMSMessage>(param, pObj);
                pObj.RowID      = Guid.NewGuid();
                pObj.CreateDate = DateTime.Now;
                pObj.Status     = (int)MessageStatusKind.Unsent;
                context.SMSMessages.Add(pObj);
                context.SaveChanges();
                TaskHelper.Factory.StartNew(sender_SendCompleted, new object[] { pObj.RowID, client });
            }
        }
Пример #2
0
        private HttpClient GetSMSSender(SendSMSParameter header)
        {
            base.VerifyHeader(header);

            using (var context = base.CreateContext())
            {
                var config = context.SMSConfigs.First(t => header.ConfigID == null || t.RowID == header.ConfigID);
                if (!string.IsNullOrEmpty(config.Sign))
                {
                    header.SendMessage += "【" + config.Sign + "】";
                }
                var client = new HttpClient();
                client.Form["url"] = config.WebAuthority;
                client.Form["id"]  = config.UserName;
                client.Form["pwd"] = config.Password;
                return(client);
            }
        }
Пример #3
0
        public void SendSMS(SendSMSParameter param)
        {
            var repository = new InfrastructureRepository();

            repository.SendSMS(param);
        }