public MyResult <object> PubMessage([FromBody] MessageDto model) { if (string.IsNullOrEmpty(base.TokenModel.Id.ToString()) || base.TokenModel.Id < 0) { return(new MyResult <object>(-1, "请检查是否登录")); } //判断是否禁用 var flag = SetingService.UserStatus(base.TokenModel.Id); if (flag) { return(new MyResult <object>(-1, "用户已被禁用")); } List <string> urlList = new List <string>(); if (model.BasePics.Count > 0) { model.BasePics.ForEach(pic => { var fileName = DateTime.Now.GetTicket().ToString(); var url = ImageHandlerUtil.SaveBase64Image(pic, $"{fileName}.png", $"{Constants.Message_Path}/{base.TokenModel.Id}"); urlList.Add(url); }); } model.Pics = urlList.GetJson(); model.UserId = base.TokenModel.Id; return(SetingService.AddMessage(model)); }
public MyResult <object> BannerAdd_Updata([FromBody] BannerDto model) { if (!string.IsNullOrEmpty(model.Pic) && model.Pic.Length > 1000) { var fileName = DateTime.Now.GetTicket().ToString(); model.Pic = ImageHandlerUtil.SaveBase64Image(model.Pic, $"{fileName}.png", Constants.BANNER_PATH); } return(SetingService.AddBanner(model)); }
public MyResult <object> SaveMessageType([FromBody] MessageTypeDto model) { if (!string.IsNullOrEmpty(model.Pic) && model.Pic.Length > 1000) { var fileName = DateTime.Now.GetTicket().ToString(); model.Pic = ImageHandlerUtil.SaveBase64Image(model.Pic, $"{fileName}.png", Constants.MessageType_PATH); } if (model.Id.HasValue) { return(SetingService.UpdateMessageType(model)); } return(SetingService.AddMessageType(model)); }
public MyResult <object> PubShopDetail([FromBody] ShopDetailDto model) { if (string.IsNullOrEmpty(base.TokenModel.Id.ToString()) || base.TokenModel.Id < 0) { return(new MyResult <object>(-1, "请检查是否登录")); } if (!string.IsNullOrEmpty(model.Pic)) { var fileName = DateTime.Now.GetTicket().ToString(); var url = ImageHandlerUtil.SaveBase64Image(model.Pic, $"{fileName}.png", $"{Constants.Shop_Detail_Path}/{base.TokenModel.Id}"); model.Pic = url; } return(SetingService.AddShopDetail(model)); }
public MyResult <UploadModel> Image([FromBody] FileUploadModel model) { MyResult <UploadModel> result = new MyResult <UploadModel>(); var ext = Path.GetExtension(model.FileName); if (string.IsNullOrEmpty(ext)) { ext = ".png"; } if (string.IsNullOrEmpty(model.Id)) { return(result.SetError("Id 不能为空")); } var fileName = $"{model.Type}_{DateTime.Now.ToString("yyyyMMddHHmmssffffff")}_{ext}"; var virtualPath = PathUtil.Combine(Enum.GetName(typeof(FileType), model.Type), model.Id.ToString(), fileName); var reqUrl = PathUtil.CombineWithRoot("api/Upload/Base64File"); model.Picture = Convert.ToBase64String(ImageHandlerUtil.ShrinkImage(ImageHandlerUtil.Base64ToBytes(model.Picture))); string rep = HttpUtil.PostString(reqUrl, new { base64 = model.Picture, fileName = virtualPath, waterMarks = model.WaterMarks }.GetJson(), "application/json"); var repModel = rep.GetModel <MyResult <UploadModel> >(); result.Data = repModel.Data; return(result); }
//获取小程序码 public MyResult <object> GetUnlimited(int userId = 0) { MyResult result = new MyResult(); if (userId <= 0) { return(result.SetStatus(ErrorCode.InvalidData, "用户Id为空 请联重新登陆")); } var user = base.First <User>(predicate => predicate.Id == userId); if (user == null) { return(result.SetStatus(ErrorCode.InvalidData, "用户不存在")); } if (!string.IsNullOrEmpty(user.UPic)) { result.Data = PathUtil.CombineWithRoot(user.UPic); return(result); } var access_token = MemoryCacheUtil.Get(Constants.WxAccessToken); if (access_token == null) { SetAccessToken(); access_token = MemoryCacheUtil.Get(Constants.WxAccessToken); } var UnlimitedUrl = $"https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token={access_token}"; var _scene = $"inviter_id={userId}"; var rep = HttpUtil.PostByte(UnlimitedUrl, new { scene = _scene, is_hyaline = false }.GetJson(), "application/json"); var url = ImageHandlerUtil.SaveByteImage(rep, $"{Constants.WxPic}/{userId}"); user.UPic = url; base.Update(user, true); result.Data = PathUtil.CombineWithRoot(url); return(result); }
public MyResult <UploadModel> Base64File([FromBody] ReqModel model) { MyResult <UploadModel> result = new MyResult <UploadModel>(); if (string.IsNullOrEmpty(model.Base64) || string.IsNullOrEmpty(model.FileName)) { var di = PathUtil.MapPath(Constants.DefaultHeadPicture); LogUtil <UploadController> .Info("di" + di); FileInfo fileInfo = new FileInfo(di); UploadModel model1 = new UploadModel { FileName = fileInfo.Name, FullName = fileInfo.FullName, Extension = fileInfo.Extension, Length = fileInfo.Length, VirtualPath = model.FileName ?? Constants.DefaultHeadPicture, FullVirtualPath = PathUtil.CombineWithRoot(model.FileName ?? Constants.DefaultHeadPicture) }; result.Data = model1; } else { var filePath = PathUtil.MapPath(model.FileName); FileInfo fileInfo = new FileInfo(filePath); var bytes = ImageHandlerUtil.Base64ToBytes(model.Base64); if (!fileInfo.Directory.Exists) { fileInfo.Directory.Create(); if (!string.IsNullOrEmpty(model.WaterMarks)) { ImageHandlerUtil.WaterMarks(bytes, model.WaterMarks, filePath); } if (!fileInfo.Exists) { using (var fs = fileInfo.Create()) { fs.Write(bytes, 0, bytes.Length); fs.Flush(true); fileInfo.Refresh(); } } } else { if (!string.IsNullOrEmpty(model.WaterMarks)) { ImageHandlerUtil.WaterMarks(bytes, model.WaterMarks, filePath); } if (!fileInfo.Exists) { using (var fs = fileInfo.Create()) { fs.Write(bytes, 0, bytes.Length); fs.Flush(true); fileInfo.Refresh(); } } } UploadModel model2 = new UploadModel { FileName = fileInfo.Name, FullName = fileInfo.FullName, Extension = fileInfo.Extension, Length = fileInfo.Length, VirtualPath = model.FileName, FullVirtualPath = PathUtil.CombineWithRoot(model.FileName), }; result.Data = model2; } return(result); }