public ActionResult UploadVoice() { try { var file = System.Web.HttpContext.Current.Request.Files[0]; if (file.InputStream.Length == 0) { return(Json(new { isok = false, msg = "上传失败,音频大小不能空", Path = "" }, JsonRequestBehavior.AllowGet)); } if ((file.InputStream.Length / 1024.0 / 1024.0) > 10) { return(Json(new { isok = false, msg = "上传失败,音频文件不能超过10M", Path = "" }, JsonRequestBehavior.AllowGet)); } if (!file.FileName.Substring(file.FileName.LastIndexOf(".")).Contains("mp3")) { return(Json(new { isok = false, msg = "上传失败,音频格式必须是MP3", Path = "" }, JsonRequestBehavior.AllowGet)); } int storeid = int.Parse(Context.GetRequest("storeid", "0")); int voicetype = Context.GetRequestInt("voicetype", (int)AttachmentItemType.小程序语音); byte[] byteData = new byte[file.InputStream.Length]; file.InputStream.Position = 0; file.InputStream.Read(byteData, 0, byteData.Length); file.InputStream.Close(); //将下载的语音放到AliOss临时文件夹 string voiceAliOssKey = string.Empty; //上传目录 string voiceAliOssFolder = AliOSSHelper.GetOssVoiceKey("mp3", true, "voice/folder", out voiceAliOssKey); bool putResult = AliOSSHelper.PutObjectFromByteArray(voiceAliOssFolder, byteData); if (!putResult)// 未能成功同步到AliOss { return(Json(new { isok = false, msg = "上传失败", Path = "" }, JsonRequestBehavior.AllowGet)); } List <C_Attachment> attachlist = C_AttachmentBLL.SingleModel.GetListByCache(storeid, voicetype); if (storeid > 0 && attachlist != null && attachlist.Count > 0) { C_AttachmentBLL.SingleModel.RemoveRedis(storeid, voicetype); return(Json(new { isok = true, msg = "上传成功", Path = voiceAliOssKey, voiceId = attachlist[0].id }, JsonRequestBehavior.AllowGet)); } else { C_Attachment attach = new C_Attachment(); attach.itemId = 0; attach.itemType = voicetype; attach.filepath = voiceAliOssKey; attach.createDate = DateTime.Now; attach.VoiceServerId = Guid.NewGuid().ToString(); attach.thumbnail = voiceAliOssKey; int voiceId = Convert.ToInt32(C_AttachmentBLL.SingleModel.Add(attach)); if (voiceId > 0) { return(Json(new { isok = true, msg = "上传成功", Path = voiceAliOssKey, voiceId = voiceId }, JsonRequestBehavior.AllowGet)); } } return(Json(new { isok = false, msg = "系统错误,请重新尝试", Path = "" })); } catch (Exception) { return(Json(new { isok = false, msg = "系统错误,请重新尝试", Path = "" })); } }
public JsonResult DeleteStoreImage(int imageId, string openId) { C_UserInfo loginCUser = C_UserInfoBLL.SingleModel.GetModelFromCache(openId); if (loginCUser == null) { return(Json(new BaseResult { errcode = 1, result = false, msg = "登录信息过期,刷新试试" }, JsonRequestBehavior.AllowGet)); } C_Attachment catt = C_AttachmentBLL.SingleModel.GetModel(imageId); if (catt == null) { return(Json(new BaseResult { errcode = 1, result = false, msg = "该图片已不存在" }, JsonRequestBehavior.AllowGet)); } //bool auth = false; //权限验证 //switch (catt.itemType) //{ // case (int)C_Enums.AttachmentItemType.信息附件: // C_Post cpost = new C_PostBLL().GetModel(catt.itemId); // if (cpost == null) // { // auth = true; // } // else // { // auth = cpost.OpenId == loginCUser.OpenId; // } // break; // case (int)C_Enums.AttachmentItemType.公司介绍图: // C_Company ccy = new C_CompanyBLL().GetModel(catt.itemId); // if (ccy == null) // { // auth = true; // } // else // { // auth = ccy.OpenId == loginCUser.OpenId; // } // break; // case (int)C_Enums.AttachmentItemType.商户轮播图: // case (int)C_Enums.AttachmentItemType.商户介绍图: // case (int)C_Enums.AttachmentItemType.商户介绍语音: // C_Store cstore = new C_StoreBLL().GetModel(catt.itemId); // if (cstore == null) // { // auth = true; // } // else // { // auth = cstore.OpenId == loginCUser.OpenId; // } // break; // case (int)C_Enums.AttachmentItemType.五折卡服务图片: // C_HalfOffServices chalfs = new C_HalfOffServicesBLL().GetModel(catt.itemId); // if (chalfs == null) // { // auth = true; // } // else // { // auth = chalfs.OpenId == loginCUser.OpenId; // } // break; // case (int)C_Enums.AttachmentItemType.五折卡服务详情图片: // C_HalfOffServices chalfs2 = new C_HalfOffServicesBLL().GetModel(catt.itemId); // if (chalfs2 == null) // { // auth = true; // } // else // { // auth = chalfs2.OpenId == loginCUser.OpenId; // } // break; // case (int)C_Enums.AttachmentItemType.活动图片: // C_Active active = new C_ActiveBLL().GetModel(catt.itemId); // if (active == null) // { // auth = true; // } // else // { // auth = active.Openid == loginCUser.OpenId; // } // break; // case (int)C_Enums.AttachmentItemType.优惠券轮播图: // case (int)C_Enums.AttachmentItemType.优惠券详情图: // C_StoreCoupon coupon = new C_StoreCouponBLL().GetModel(catt.itemId); // if (coupon == null) // { // auth = true; // } // else // { // C_Store cctore = new C_StoreBLL().GetModel(coupon.StoreId); // if (cctore == null) // { // auth = true; // } // else // { // auth = cctore.OpenId == loginCUser.OpenId; // } // } // break; // default: // return Json(new BaseResult { errcode = 1, result = false, msg = "系统繁忙c_param_err" }, JsonRequestBehavior.AllowGet); //} //if (!auth) //{ // return Json(new BaseResult { errcode = 1, result = false, msg = "系统繁忙auth_limited" }, JsonRequestBehavior.AllowGet); //} if (C_AttachmentBLL.SingleModel.Delete(catt.id) > 0) { C_AttachmentBLL.SingleModel.RemoveRedis(catt.itemId, catt.itemType);//清除缓存 return(Json(new BaseResult { errcode = 1, result = true, msg = "删除成功" }, JsonRequestBehavior.AllowGet)); } return(Json(new BaseResult { errcode = 1, result = false, msg = "系统繁忙db_err" }, JsonRequestBehavior.AllowGet)); }