/// <summary> /// 发送图文消息 /// 文档:https://work.weixin.qq.com/api/doc#10167 /// </summary> /// <param name="request">请求参数</param> /// <returns>返回结果</returns> public SendMessageResult SendNews(SendNewsRequest request) { if (request.agentid == 0) { request.agentid = Client.AgentId; } return(Send(request)); }
private void SendNewsMessage(string user, ResponseInfo <WeChatAnswerList> JsonResullt) { BotService.WebService1SoapClient BotService = new BotService.WebService1SoapClient(); string str_AccessToken = TokenBiz.GetAccessToken(str_corpid, str_corpsecret); SendNewsRequest str = new SendNewsRequest(); str.agentid = Agentid; str.touser = user; str.msgtype = "news"; SendNewsRequest.newsRequest news = new SendNewsRequest.newsRequest(); news.articles = new List <SendNewsRequest.articles>(); if (!string.IsNullOrEmpty(JsonResullt.responseInfo._title)) { SendNewsRequest.articles article = new SendNewsRequest.articles(); article.title = JsonResullt.responseInfo._title; article.description = JsonResullt.responseInfo._description; article.url = JsonResullt.responseInfo._url; if (!string.IsNullOrEmpty(JsonResullt.responseInfo._picurl)) { article.picurl = JsonResullt.responseInfo._picurl; } news.articles.Add(article); str.news = news; messageBiz.Send <SendNewsRequest>(str); } else { var booksResult = BotService.GetBooksList(JsonResullt.responseInfo._actionsid.ToString()); List <Books> booksListResult = JsonHelper.JsonDeserialize <List <Books> >(booksResult); if (booksListResult.Any()) { booksListResult.ForEach(x => { SendNewsRequest.articles article = new SendNewsRequest.articles(); article.title = x._name; article.description = x._description; article.url = x._url; if (!string.IsNullOrEmpty(x._picurl)) { article.picurl = x._picurl; } news.articles.Add(article); }); str.news = news; messageBiz.Send <SendNewsRequest>(str); } else { SendSingleMessage(user, "Sorry,we haven't that kinds of books ."); } } }
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)); }
public void SendNewsMessage(string user, XmlNode TSubResultNode) { string str_AccessToken = TokenBiz.GetAccessToken(str_corpid, str_corpsecret); SendNewsRequest str = new SendNewsRequest(); str.agentid = Agentid; str.touser = user; str.msgtype = TSubResultNode.SelectSingleNode("msgtype").InnerText; SendNewsRequest.newsRequest news = new SendNewsRequest.newsRequest(); news.articles = new List <SendNewsRequest.articles>(); SendNewsRequest.articles article = new SendNewsRequest.articles(); article.title = TSubResultNode.SelectSingleNode("title").InnerText; article.description = TSubResultNode.SelectSingleNode("description").InnerText; article.url = TSubResultNode.SelectSingleNode("url").InnerText; article.picurl = TSubResultNode.SelectSingleNode("picurl").InnerText; news.articles.Add(article); str.news = news; messageBiz.Send <SendNewsRequest>(str); }