快速开发平台消息通知中心之短信发送

快速开发平台消息通知中心之短信发送,短信发送是什么,用什么实现?

短信发送一般是用的第三方短信平台,调用第三方短信平台接口即可实现收发信息的服务。


        /// <summary>
        /// 发送短信通知
        /// </summary>
        public static void SendSmsNotice(int number)
        {
            using (var unitOfWork = new UnitOfWork())
            {
                var messageList = unitOfWork.SmsNoticeMessageRepository.GetSmsNoticeMessages(number);
                if (!messageList.Any()) return;
                var duplicate = new List<SmsNoticeMessage>(messageList.ToArray());
                var removeMessageList = new List<SmsNoticeMessage>();
                foreach (var msg in duplicate)
                {
                    var result = messageList.Where(s => s.ReasonType == msg.ReasonType && s.PhoneNumber == msg.PhoneNumber).ToList();
                    var remark = string.Empty;
                    if (result.Any() && result.Count > 1)
                    {
                        remark = result.Where(r => !string.IsNullOrWhiteSpace(r.Remark)).Aggregate(remark, (current, r) => current + (r.Remark + "|"));
                        for (int i = 0; i < result.Count; i++)
                        {
                            removeMessageList.Add(result[i]);
                            messageList.Remove(result[i]);
                        }
                        result[0].Remark = remark;
                        messageList.Add(result[0]);
                    }
                }
                if (removeMessageList.Any())
                {
                    removeMessageList.ForEach(s => { s.IsSended = true; s.IsSendSuccess = true; });
                }
                var messageCollection = new Dictionary<string, string>();
                foreach (var noticeMessage in messageList)
                {
                    var message = GetMessageTemplete(noticeMessage);
                    if (messageCollection.ContainsKey(message))
                    {
                        messageCollection[message] = messageCollection[message] + "," + noticeMessage.PhoneNumber;
                    }
                    else
                    {
                        messageCollection.Add(message, noticeMessage.PhoneNumber);
                    }
                }
                foreach (var msg in messageCollection)
                {
                    var toList = msg.Value.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    //var isSuccess = Utils.SendSms(toList, msg.Key);
                    Task.Factory.StartNew(() => { Utils.SendSms(toList, msg.Key); }).Start();
                    foreach (var entity in messageList.Where(p=>toList.Contains(p.PhoneNumber)))
                    {
                        entity.IsSended = true;
                        entity.IsSendSuccess = true;
                    }
                }

                unitOfWork.SmsNoticeMessageRepository.UpdateBatch(messageList);
                unitOfWork.SmsNoticeMessageRepository.UpdateBatch(removeMessageList);
            }
        }
        /// <summary>
        /// 发送短信通知
        /// </summary>
        public static void SendSmsNotice(Product product)
        {
            using (var unitOfWork = new UnitOfWork())
            {
                var contact = unitOfWork.ContactInfoRepository.GetFirst(s => s.UserId == product.UserId);
                var reason = string.Empty;
                var message = string.Empty;
                var call = contact.FirstName + (contact.Sex == SexEnum.Woman ? "女士" : "先生");

                if (product.State == ProductStateEnum.CheckFail)
                {
                    reason = "产品审核状态变更为审核失败";
                    message = string.Format("{0},您好!您的产品[{1}]因[{2}]未通过审核,请登录网站修改", call, product.Name, product.CheckRemark);
                }
                else if (product.State == ProductStateEnum.IsConfirmed)
                {
                    reason = "产品审核状态变更为已上架";
                    message = string.Format("{0},您好!您的产品[{1}]已通过审核,请登录网站进行产品操作", call, product.Name);
                }
                var smsMessageNotice = new SmsNoticeMessage
                                         {
                                             IsSended = true,
                                             UserId = product.UserId,
                                             PhoneNumber = contact.MobileTelephone,
                                             Reason = reason,
                                             Gender = contact.Sex == SexEnum.Woman ? Gender.Female : Gender.Male,
                                             FirstName = contact.FirstName,
                                             AddTime = DateTime.Now,
                                             ReasonType = product.State == ProductStateEnum.IsConfirmed ? SmsNoticeReason.N9 : SmsNoticeReason.N10,
                                             Remark = "即时通知"
                                         };
                var sendResult = Utils.InvokeApi<ResponsePackage<SmsNoticeResult>>("SmsNotice/SendSingle", new { To = contact.MobileTelephone, Data = message });
                if (sendResult.Data != null)
                {
                    smsMessageNotice.IsSendSuccess = sendResult.Data.IsSuccess;
                }
                unitOfWork.SmsNoticeMessageRepository.Insert(smsMessageNotice);
                unitOfWork.Save();
            }
        }


快速开发平台消息通知中心之短信发送,短信发送是什么,用什么实现?快速开发平台中我们支持满意通和阿里百川的短信服务,他们的接口都有实现。

标签: 快速开发平台组件插件标签

网站&系统开发技术学习交流群:463167176

本站文章除注明转载外,均为本站原创或翻译,欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,共创和谐网络环境。
转载请注明:文章转载自:软件开发框架 » 快速开发平台消息通知中心之短信发送
本文标题:快速开发平台消息通知中心之短信发送
本文地址:http://www.hocode.com/OrgTec/Back/0031.html

相关文章: Web安全问题及防范规范之短信轰炸_B/S开发框架

电话
电话 18718672256

扫一扫
二维码