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 .");
                }
            }
        }
Beispiel #2
0
        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);
        }