コード例 #1
0
        public ResponseEntity <long> AddWeChatNews(GraphicMessage msg)
        {
            msg.isTop = false;
            if (!string.IsNullOrEmpty(msg.poster) && msg.poster.IndexOf("base64,") > -1)
            {
                try
                {
                    var    img      = Utils.GetImageFromBase64(msg.poster.Substring(msg.poster.IndexOf("base64,") + 7));
                    string fileName = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".jpg";
                    string fullPath = ConfigurationManager.AppSettings["UploadFolderPath"] + fileName;
                    img.Save(fullPath);

                    msg.poster = fileName;
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                }
            }

            ResponseEntity <long> response = new ResponseEntity <long>();

            var  dao      = new GraphicMessageDao(ConfigurationManager.AppSettings["mysqlConnStr"]);
            bool isExists = dao.MediaIdExist(msg.wechatMediaId);

            if (isExists)
            {
                response = new ResponseEntity <long>(true, "图文已存在", 0);
            }
            else
            {
                response = new ResponseEntity <long>(true, "图文导入成功", 0);
                dao.AddGraphicMessage(msg);
            }

            return(response);
        }