コード例 #1
0
ファイル: MessageImpl.cs プロジェクト: simcu/wechat-gateway
        public override Task <SendMessageResponse> SendNews(SendNewsRequest request, ServerCallContext context)
        {
            var isWxApp       = _redis.KeyExists(CacheKey.UserIsWxAppPrefix + request.AppId);
            var targets       = _processTarget(request.Targets);
            var messageStatus = new MessageStatus(_redis);

            messageStatus.GenMessageId();
            var now  = Util.GetTimestamp();
            var resp = new SendMessageResponse
            {
                MessageId = messageStatus.GetMessageId(),
                SendTime  = request.Time == 0 ? now : request.Time
            };

            if (request.NoStatus)
            {
                resp.MessageId = string.Empty;
                messageStatus.SetMessageId(null);
            }
            else
            {
                messageStatus.Create(targets.Keys.ToArray(), resp.SendTime);
            }
            foreach (var item in targets)
            {
                var tmpTitle       = _processValue(item.Value, request.Title);
                var tmpDescription = _processValue(item.Value, request.Description);
                var tmpLink        = _processValue(item.Value, request.Link);
                if (request.Time == 0)
                {
                    if (request.HighPriority)
                    {
                        BackgroundJob.Enqueue <SendMessage>(x => x.HighPriorityNews(messageStatus.GetMessageId(), request.AppId, item.Key, tmpTitle, tmpDescription, tmpLink, request.Image, isWxApp, null));
                    }
                    else
                    {
                        BackgroundJob.Enqueue <SendMessage>(x => x.News(messageStatus.GetMessageId(), request.AppId, item.Key, tmpTitle, tmpDescription, tmpLink, request.Image, isWxApp, null));
                    }
                }
                else
                {
                    var tmpJobId = string.Empty;
                    if (request.HighPriority)
                    {
                        tmpJobId = BackgroundJob.Schedule <SendMessage>(x => x.HighPriorityNews(messageStatus.GetMessageId(), request.AppId, item.Key, tmpTitle, tmpDescription, tmpLink, request.Image, isWxApp, null), TimeSpan.FromSeconds(request.Time - now));
                    }
                    else
                    {
                        tmpJobId = BackgroundJob.Schedule <SendMessage>(x => x.News(messageStatus.GetMessageId(), request.AppId, item.Key, tmpTitle, tmpDescription, tmpLink, request.Image, isWxApp, null), TimeSpan.FromSeconds(request.Time - now));
                    }
                    messageStatus.AddJobId(tmpJobId);
                }
            }
            return(Task.FromResult(resp));
        }
コード例 #2
0
ファイル: MessageImpl.cs プロジェクト: simcu/wechat-gateway
        public override Task <SendMessageResponse> SendWxAppCard(SendWxAppCardRequest request, ServerCallContext context)
        {
            var targets       = _processTarget(request.Targets);
            var messageStatus = new MessageStatus(_redis);

            messageStatus.GenMessageId();
            var now  = Util.GetTimestamp();
            var resp = new SendMessageResponse
            {
                MessageId = messageStatus.GetMessageId(),
                SendTime  = request.Time == 0 ? now : request.Time
            };

            if (request.NoStatus)
            {
                resp.MessageId = string.Empty;
                messageStatus.SetMessageId(null);
            }
            else
            {
                messageStatus.Create(targets.Keys.ToArray(), resp.SendTime);
            }
            foreach (var item in targets)
            {
                var tmpTitle    = _processValue(item.Value, request.Title);
                var tmpPagePath = _processValue(item.Value, request.PagePath);
                if (request.Time == 0)
                {
                    if (request.HighPriority)
                    {
                        BackgroundJob.Enqueue <SendMessage>(x => x.HighPriorityWxAppCard(messageStatus.GetMessageId(), request.AppId, item.Key, tmpTitle, tmpPagePath, request.WxAppId, request.ImageId, null));
                    }
                    else
                    {
                        BackgroundJob.Enqueue <SendMessage>(x => x.WxAppCard(messageStatus.GetMessageId(), request.AppId, item.Key, tmpTitle, tmpPagePath, request.WxAppId, request.ImageId, null));
                    }
                }
                else
                {
                    var tmpJobId = string.Empty;
                    if (request.HighPriority)
                    {
                        tmpJobId = BackgroundJob.Schedule <SendMessage>(x => x.HighPriorityWxAppCard(messageStatus.GetMessageId(), request.AppId, item.Key, tmpTitle, tmpPagePath, request.WxAppId, request.ImageId, null), TimeSpan.FromSeconds(request.Time - now));
                    }
                    else
                    {
                        tmpJobId = BackgroundJob.Schedule <SendMessage>(x => x.WxAppCard(messageStatus.GetMessageId(), request.AppId, item.Key, tmpTitle, tmpPagePath, request.WxAppId, request.ImageId, null), TimeSpan.FromSeconds(request.Time - now));
                    }
                    messageStatus.AddJobId(tmpJobId);
                }
            }
            return(Task.FromResult(resp));
        }
コード例 #3
0
ファイル: MessageImpl.cs プロジェクト: simcu/wechat-gateway
        public override Task <SendMessageResponse> SendTemplate(SendTemplateRequest request, ServerCallContext context)
        {
            string formId = null;

            if (_redis.KeyExists(CacheKey.UserIsWxAppPrefix + request.AppId))
            {
                formId = request.FormId;
            }
            var targets       = _processTarget(request.Targets);
            var messageStatus = new MessageStatus(_redis);

            messageStatus.GenMessageId();
            var now  = Util.GetTimestamp();
            var resp = new SendMessageResponse
            {
                MessageId = messageStatus.GetMessageId(),
                SendTime  = request.Time == 0 ? now : request.Time
            };

            if (request.NoStatus)
            {
                resp.MessageId = string.Empty;
                messageStatus.SetMessageId(null);
            }
            else
            {
                messageStatus.Create(targets.Keys.ToArray(), resp.SendTime);
            }
            foreach (var item in targets)
            {
                var data = new Dictionary <string, WxWebSendTemplateRequest.DataItem>();
                foreach (var dItem in request.Data)
                {
                    data.Add(dItem.Key, new WxWebSendTemplateRequest.DataItem
                    {
                        Value = _processValue(item.Value, dItem.Value),
                        Color = dItem.Color
                    });
                }
                var tmpUrl = _processValue(item.Value, request.Url);
                if (request.Time == 0)
                {
                    if (request.HighPriority)
                    {
                        BackgroundJob.Enqueue <SendMessage>(x => x.HighPriorityTemplate(messageStatus.GetMessageId(), request.AppId, item.Key, request.TemplateId, tmpUrl, data, formId, null));
                    }
                    else
                    {
                        BackgroundJob.Enqueue <SendMessage>(x => x.Template(messageStatus.GetMessageId(), request.AppId, item.Key, request.TemplateId, tmpUrl, data, formId, null));
                    }
                }
                else
                {
                    var tmpJobId = string.Empty;
                    if (request.HighPriority)
                    {
                        tmpJobId = BackgroundJob.Schedule <SendMessage>(x => x.HighPriorityTemplate(messageStatus.GetMessageId(), request.AppId, item.Key, request.TemplateId, tmpUrl, data, formId, null), TimeSpan.FromSeconds(request.Time - now));
                    }
                    else
                    {
                        tmpJobId = BackgroundJob.Schedule <SendMessage>(x => x.Template(messageStatus.GetMessageId(), request.AppId, item.Key, request.TemplateId, tmpUrl, data, formId, null), TimeSpan.FromSeconds(request.Time - now));
                    }
                    messageStatus.AddJobId(tmpJobId);
                }
            }
            return(Task.FromResult(resp));
        }