| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- using CallCenter.Utility;
- using CallCenterApi.Interface.Controllers.Base;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Web;
- using System.Web.Mvc;
- namespace CallCenterApi.Interface.Controllers
- {
- public class UploadFileController : BaseController
- {
- // GET: UploadFile
- //public ActionResult Index()
- //{
- // return View();
- //}
- public ActionResult UploadToFTP()
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- #region 前后端分离上传并修改文件格式
- HttpPostedFile _upFile = RequestString.GetFile("upFile");
- if (_upFile != null)
- {
- string datename = DateTime.Now.ToString("yyyyMMddHHMMss");
- string fullFileName = datename + "_" + _upFile.FileName;
- string ffmpegLocation = Server.MapPath("~/");
- string dirpath = Server.MapPath(this.Request.ApplicationPath + "\\auoupload");
- //string dirpath = Configs.GetValue("saveloc");
- if (!System.IO.Directory.Exists(dirpath))
- {
- System.IO.Directory.CreateDirectory(dirpath);
- }
- string path = this.Request.ApplicationPath + "/auoupload/" + fullFileName;
- //string physicalpath = dirpath + fullFileName;
- string physicalpath = Server.MapPath(path);
- _upFile.SaveAs(physicalpath);
- #region 修改音频格式
- if (!string.IsNullOrEmpty(physicalpath))
- {
- //通过cmd执行ffmpeg改变音频采样率
- Process p = new Process();
- p.StartInfo.FileName = "cmd.exe";
- p.StartInfo.UseShellExecute = false;
- p.StartInfo.RedirectStandardOutput = true;
- p.StartInfo.RedirectStandardInput = true;
- p.StartInfo.RedirectStandardError = true;
- p.StartInfo.CreateNoWindow = true;
- //p.StartInfo.Arguments = "ffmpeg -i "+fileName+ " -ar 16000 "+ namePart + "New.wav";//参数以空格分隔,如果某个参数为空,可以传入””
- //p.Start();
- ////先进入cmd命令
- ////再打开FFmpeg.exe
- ////p.StandardInput.WriteLine("exit");
- //p.StandardInput.WriteLine("cd d/ " + ffmpegLocation + "ffmpeg.exe");
- //p.StandardInput.WriteLine(ffmpegLocation.TrimEnd('\\'));
- string temp_filename = physicalpath.Split('\\').Last().Split('.')[0] + "_temp";
- string savedir = Configs.GetValue("saveloc");
- if (!System.IO.Directory.Exists(savedir))
- {
- System.IO.Directory.CreateDirectory(savedir);
- }
- p.Start();
- //先进入cmd命令
- //再打开FFmpeg.exe
- //p.StandardInput.WriteLine("exit");
- //cd d/ D:\项目\公司5.1\codegit\CallCenterApi\CallCenterApi.Interface\CallCenterApi.Interface\ffmpeg.exe
- p.StandardInput.WriteLine("cd " + ffmpegLocation);
- p.StandardInput.WriteLine(ffmpegLocation.Split('\\').First());
- p.StandardInput.WriteLine("ffmpeg.exe");
- //p.StandardInput.WriteLine(ffmpegLocation.TrimEnd('\\'));
- //p.StandardInput.WriteLine("ffmpeg -i " + temp_filename + i + ".mp3 -f pcm -ar 16000 -ac 1 -ab 16 " + namepart.Replace(@"/", @"\"));
- //string changefile = "ffmpeg -i " + physicalpath + " -acodec pcm_u8 -ab 64 -ar 8000 -ac 1 " + dirpath + "\\" + temp_filename + ".wav";
- string changefile = "ffmpeg -i " + physicalpath + " -acodec pcm_u8 -ab 64 -ar 8000 -ac 1 " + savedir + "\\" + temp_filename + ".wav";
- //ffmpeg -i D:\项目\公司5.1\codegit\CallCenterApi\CallCenterApi.Interface\CallCenterApi.Interface\upload\20180131150114_2566994_913583164044.wav -acodec pcm_s16le -f s16le -ar 8000 -ac 1 D:\项目\公司5.1\codegit\CallCenterApi\CallCenterApi.Interface\CallCenterApi.Interface\20180131150114_2566994_913583164044_temp.pcm
- p.StandardInput.WriteLine(changefile);
- Thread.Sleep(3000);
- p.StandardInput.WriteLine("exit");
- //Kill 是终止没有图形化界面的进程的唯一方法。
- //p.Kill();
- #region 上传
- uploadFile upfile = new uploadFile();
- //通过读取配置文件,获取数据库
- string _ftp = Configs.GetValue("ftp");
- string _acc = Configs.GetValue("account");
- string _pwd = Configs.GetValue("password");
- upfile.ftpPath = _ftp;
- upfile.ftpUserID = _acc;
- upfile.ftpPassword = _pwd;
- //FileInfo fi = new FileInfo(path);
- FileInfo fi = new FileInfo(physicalpath);
- //string res = upfile.UploadLocalToFtp(path);
- //string res = upfile.UploadLocalToFtp(physicalpath);
- //D:\项目\公司5.1\codegit\CallCenterApi\CallCenterApi.Interface\CallCenterApi.Interface\20180131150114_2566994_913583164044_temp.pcm
- //string uploadres = upfile.UploadLocalToFtp(dirpath + "\\" + temp_filename + ".wav");
- string uploadres = upfile.UploadLocalToFtp(savedir + "\\" + temp_filename + ".wav");
- if (uploadres == "上传成功!")
- {
- //写入日志
- string logfile = Server.MapPath("~/log.txt");
- if (!System.IO.File.Exists(logfile))
- {
- System.IO.File.Create(logfile);
- }
- //开始写入
- string str = DateTime.Now.ToString() + " 文件" + fullFileName + "上传成功";
- System.IO.File.AppendAllLines(logfile, new string[] { str }, Encoding.GetEncoding("gb2312"));
- //存入表中
- //string title = RequestString.GetFormString("title");
- //string content = RequestString.GetFormString("content");
- //string type = RequestString.GetFormString("type");
- //string stime = RequestString.GetFormString("stime");
- //string etime = RequestString.GetFormString("etime");
- //string remark = RequestString.GetFormString("remark");
- //string isstate = RequestString.GetFormString("isstate");
- string title = "123";
- string content = "123";
- string type = "1";
- string stime = "2018-01-30 17:27:57";
- string etime = "2018-01-30 17:27:57";
- string remark = "123";
- string isstate = "1";
- int userId = CurrentUser.UserData.F_UserId;
- string ucode = "";
- if (userId != 0)
- {
- Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
- if (ua != null)
- ucode = ua.F_UserCode;
- }
- new BLL.T_Sys_IVRWords().Add(new Model.T_Sys_IVRWords()
- {
- F_Title = title,
- F_Content = content,
- F_Type = Convert.ToInt32(type),
- F_StartDate = DateTime.Parse(stime),
- F_EndDate = DateTime.Parse(etime),
- F_Remark = remark,
- F_IsState = int.Parse(isstate),
- F_CreateTime = DateTime.Now,
- F_CreateUser = ucode,
- F_IsDel = 0,
- F_WavOldName = fullFileName,
- F_WavNewName = temp_filename + ".wav",
- F_WavPath = dirpath + "\\" + temp_filename + ".wav"
- });
- res = Success("上传成功");
- }
- #endregion
- }
- #endregion
- }
- else
- res = Error("参数传入失败");
- #endregion
- return res;
- }
- }
- }
|