コード例 #1
0
        public SendAppMessageResultModel SendAppMessage(SendAppContentModel sendAppMessageModel)
        {
            IGtPush push = new IGtPush(Host, Appkey, Mastersecret);

            Target target = new Target();

            target.appId    = Appid;
            target.clientId = sendAppMessageModel.ClientId;

            ITemplate template = null;

            if (sendAppMessageModel.ClientType == "A")
            {
                //template = NotificationTemplateDemo(sendAppMessageModel.Title, sendAppMessageModel.Text,
                //    sendAppMessageModel.Content);

                template = TransmissionTemplateDemo(sendAppMessageModel.Title, sendAppMessageModel.Text,
                                                    sendAppMessageModel.Content);
            }
            else
            {
                template = TransmissionTemplateIOS(sendAppMessageModel.Title, sendAppMessageModel.Content,
                                                   sendAppMessageModel.Text);
            }


            // 单推消息模型
            SingleMessage message = new SingleMessage();

            message.IsOffline         = true;             // 用户当前不在线时,是否离线存储,可选
            message.OfflineExpireTime = 1000 * 3600 * 12; // 离线有效时间,单位为毫秒,可选
            message.Data = template;
            //判断是否客户端是否wifi环境下推送,2为4G/3G/2G,1为在WIFI环境下,0为不限制环境
            //message.PushNetWorkType = 1;

            string pushResult = push.pushMessageToSingle(message, target);

            SendAppMessageResultModel result = JsonConvert.DeserializeObject <SendAppMessageResultModel>(pushResult);

            result.ResultInfo = pushResult;
            return(result);
        }
コード例 #2
0
        /// <summary>
        /// 发送待推送信息
        /// </summary>
        /// <param name="sendAppMessageModels"></param>
        /// <param name="sendAppMessageType"></param>
        public void SendAppMessage(List <SendAppMessageModel> sendAppMessageModels, SendAppMessageTypeEnum sendAppMessageType)
        {
            if (sendAppMessageModels == null || sendAppMessageModels.Count == 0)
            {
                return;
            }
            List <int> cidList = sendAppMessageModels.Select(n => n.Cid).ToList();
            List <CustomerAppClientIdEntity> customerAppClientIdEntities =
                _customerAppClientIdDal.Query <CustomerAppClientIdEntity>(n => cidList.Contains(n.Cid), true).ToList();

            foreach (SendAppMessageModel waitSend in sendAppMessageModels)
            {
                SendAppMessageEntity entity = new SendAppMessageEntity();
                entity.SendId    = waitSend.SendId;
                entity.SendCount = waitSend.SendCount + 1;
                if (!waitSend.SendFirstTime.HasValue)
                {
                    entity.SendFirstTime = DateTime.Now;
                }
                else
                {
                    entity.SendFirstTime = waitSend.SendFirstTime;
                }
                entity.SendLastTime = DateTime.Now;
                CustomerAppClientIdEntity customerAppClientIdEntity = customerAppClientIdEntities.Find(n => n.Cid == waitSend.Cid);
                entity.ClientId = customerAppClientIdEntity?.ClientId;
                if (waitSend.SendCount <= 10 && !string.IsNullOrEmpty(waitSend.SendContent))//发送记录少于10次
                {
                    if (!string.IsNullOrEmpty(entity.ClientId))
                    {
                        #region 推送app消息

                        string message = waitSend.SendContent;
                        if (sendAppMessageType != SendAppMessageTypeEnum.AuditUrgeNotice)
                        {
                            message = string.Format("message={0}&cid={1}&sendType={2}&id={3}&orderType={4}",
                                                    waitSend.SendContent,
                                                    waitSend.Cid, (int)waitSend.SendType, waitSend.OrderId, (int)waitSend.OrderType);
                        }

                        SendAppContentModel content = new SendAppContentModel();
                        content.ClientId   = entity.ClientId;
                        content.ClientType = customerAppClientIdEntity?.ClientType;
                        content.Content    = message;
                        content.Title      = waitSend.SendType.ToDescription();
                        content.Text       = waitSend.SendContent;
                        if (sendAppMessageType == SendAppMessageTypeEnum.AuditUrgeNotice &&
                            !string.IsNullOrEmpty(message) && message.Contains("&"))
                        {
                            content.Text = message.Split('&')[0].Replace("message=", "");
                        }
                        SendAppMessageResultModel resultModel = new SendAppMessageResultModel();
                        try
                        {
                            resultModel        = _sendAppMessageBll.SendAppMessage(content);
                            entity.SendContent = content.Content;
                            entity.SendResult  = resultModel.ResultInfo;
                            if (resultModel.Result.ToLower() == "ok")
                            {
                                entity.SendStatus = 1;
                            }
                            else
                            {
                                entity.SendStatus = -1;
                            }
                        }
                        catch (Exception ex)
                        {
                            entity.SendResult = ex.Message;
                            entity.SendStatus = -2;
                        }

                        #endregion
                    }
                    else
                    {
                        entity.SendStatus = -3;
                        entity.SendResult = "没有找到对应的设备Id";
                    }
                }
                else
                {
                    entity.SendStatus = -4;
                    entity.SendResult = "已经超过10次,不再发送";
                }

                _sendAppMessageDal.Update(entity, new string[] { "SendCount", "SendFirstTime", "SendLastTime", "ClientId", "SendContent", "SendResult", "SendStatus" });
            }
        }