Ejemplo n.º 1
0
        private void SendMpMessage(string user, ResponseInfo <WeChatAnswerList> JsonResullt)
        {
            SendMPNewsRequest _SendMPNewsRequest = new SendMPNewsRequest();
            mpnews            _Mpnews            = new mpnews();

            _Mpnews.articles = new List <articles>();
            string str_AccessToken = TokenBiz.GetAccessToken(str_corpid, str_corpsecret);

            //string filePath = HttpContext.Current.Request.PhysicalApplicationPath + TSubResultNode.SelectSingleNode("content").InnerText;
            //string content = File.ReadAllText(filePath);

            _SendMPNewsRequest.touser  = user;
            _SendMPNewsRequest.msgtype = "mpnews";
            _SendMPNewsRequest.agentid = Agentid;
            _SendMPNewsRequest.safe    = "0";


            if (!_Mpnews.articles.Any())//只要一条就可以了
            {
                articles article = new articles();
                string   picPath = HttpContext.Current.Request.PhysicalApplicationPath + "LusiResult/Banner/" + JsonResullt.responseInfo._banner;
                _SendLog.WriteLog(picPath);
                UploadResponse media_UpLoadInfo = MediaBiz.CreateInstance().Upload(picPath, str_AccessToken, EnumMediaType.image);
                if (media_UpLoadInfo != null)
                {
                    article.title          = JsonResullt.responseInfo._title;
                    article.thumb_media_id = media_UpLoadInfo.media_id;
                    //article.author = "RR Donnelley";
                    article.show_cover_pic = "0";
                    article.digest         = JsonResullt.responseInfo._digest;
                    _Mpnews.articles.Add(article);
                }
            }

            _Mpnews.articles.ForEach(x => x.content = JsonResullt.responseInfo._content);
            _SendMPNewsRequest.mpnews = _Mpnews;
            messageBiz.Send <SendMPNewsRequest>(_SendMPNewsRequest);
        }
Ejemplo n.º 2
0
        private static SendMPNewsRequest GetSendMPNewsRequest(string monthkey, string user, DataTable ExcelTable)
        {
            DateTime nowtime = DateTime.Now;
            string   year1   = nowtime.Year.ToString();
            string   year    = nowtime.Year.ToString().Substring(2, 2);
            string   month   = nowtime.Month.ToString().PadLeft(2, '0');

            //微信中直接传年月过来(eg:201606)
            if (monthkey.Length == 6)
            {
                year1 = monthkey.Substring(0, 4);
                year  = monthkey.Substring(2, 2);
                month = monthkey.Substring(4, 2);
            }

            SendMPNewsRequest _SendMPNewsRequest = new SendMPNewsRequest();
            mpnews            _Mpnews            = new mpnews();

            _Mpnews.articles = new List <articles>();
            string content = "";

            _SendMPNewsRequest.touser  = user;
            _SendMPNewsRequest.msgtype = "mpnews";
            _SendMPNewsRequest.agentid = System.Configuration.ConfigurationSettings.AppSettings["Agentid"];
            _SendMPNewsRequest.safe    = "1";

            DataRow[] dataRow = ExcelTable.Select("Name='" + user + "'");
            for (int j = 0; j < dataRow.Length; j++)
            {
                articles article = new articles();
                string   name    = Convert.ToString(dataRow[j][2]);

                byte[] space    = new byte[] { 0xc2, 0xa0 };
                string UTFSpace = Encoding.GetEncoding("UTF-8").GetString(space);
                name = name.Replace(UTFSpace, " ");

                string title    = name.Split('_')[1];
                String fileName = year + month + "_" + name + ".jpg";

                string ImgName    = filePath + fileName;
                string ImgNameURL = fileURL + fileName;

                if (!System.IO.File.Exists(@"D:\WebSite\RRD_SalesForecast_Portal\RRD.BC.Portal.web\test1\" + fileName))
                {
                    _SendLog.WriteLog("图片缺失: " + fileName);
                    continue;
                }
                else
                {
                    content += "<div>" + title + "</div><div><img  src='" + ImgNameURL + "'/></div>";
                    if (!_Mpnews.articles.Any())//只要一条就可以了
                    {
                        UploadResponse media_UpLoadInfo = MediaBiz.CreateInstance().Upload(ImgName, str_AccessToken, EnumMediaType.image);
                        if (media_UpLoadInfo != null)
                        {
                            article.title          = "RRD Efficiency Metrics " + year1 + month;
                            article.thumb_media_id = media_UpLoadInfo.media_id;
                            article.author         = "RR Donnelley";
                            article.show_cover_pic = "0";
                            article.digest         = "RRD Efficiency Metrics " + year1 + month;
                            _Mpnews.articles.Add(article);
                        }
                    }
                }
            }

            if (!_Mpnews.articles.Any())
            {
                content = "<div>" + monthkey + "</div><div><img  src='" + fileURL + "nullImage.jpg" + "'/></div>";
                articles       article          = new articles();
                UploadResponse media_UpLoadInfo = MediaBiz.CreateInstance().Upload(filePath + "nullImage.jpg", str_AccessToken, EnumMediaType.image);
                if (media_UpLoadInfo != null)
                {
                    article.title          = "RRD Efficiency Metrics使用指南";
                    article.thumb_media_id = media_UpLoadInfo.media_id;
                    article.author         = "RR Donnelley";
                    article.show_cover_pic = "0";
                    article.digest         = "RRD Efficiency Metrics使用指南";
                    _Mpnews.articles.Add(article);
                }
            }

            _Mpnews.articles.ForEach(x => x.content = content);

            _SendMPNewsRequest.mpnews = _Mpnews;
            return(_SendMPNewsRequest);
        }