using LitJson; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Text; namespace WindowsServiceClient { class MyServlet : Servlet { public override void onCreate() { base.onCreate(); } public class Info { public string state { get; set; } public string message { get; set; } public List CallList { get; set; } public config config { get; set; } } /// /// onGet请求 /// /// /// public override void onGet(HttpListenerRequest request, HttpListenerResponse response) { Console.WriteLine("GET:" + request.Url); bool isContains = request.Url.ToString().Contains("?"); if (isContains) { string msg = request.Url.ToString().Split('?')[1]; string ral = Get("http://117.160.143.199:4624/Callrecords/Sound?" + msg); Info rt = JsonMapper.ToObject(ral); byte[] buffer = null; if (rt.CallList.Count > 0) { ExitSound(rt.CallList, rt.config); buffer = Encoding.UTF8.GetBytes("{state:\"success\",message:\"success\",\"data\":\""+ rt.CallList.Count + "\"}"); } else { buffer = Encoding.UTF8.GetBytes("{state:\"success\",message:\"success\",\"data\":\"0\"}"); } System.IO.Stream output = response.OutputStream; output.Write(buffer, 0, buffer.Length); output.Close(); } //You must close the output stream. // listener.Stop(); } Dictionary header = new Dictionary(); /// /// Get请求 /// /// /// private string Get(string url) { string result = ""; StringBuilder builder = new StringBuilder(); builder.Append(url); HttpWebRequest req = (HttpWebRequest)WebRequest.Create(builder.ToString()); if (header != null) { foreach (var keyValuePair in header) { req.Headers.Add(keyValuePair.Key, keyValuePair.Value); } } //添加参数 HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); Stream stream = resp.GetResponseStream(); try { //获取内容 using (StreamReader reader = new StreamReader(stream)) { result = reader.ReadToEnd(); } } finally { stream.Close(); } return result; } /// /// onPost请求 /// /// /// public override void onPost(HttpListenerRequest request, HttpListenerResponse response) { Console.WriteLine("POST:" + request.Url); byte[] res = Encoding.UTF8.GetBytes("OK2"); response.OutputStream.Write(res, 0, res.Length); } /// /// StartLoop请求 /// /// private void StartLoop(string msg) { string ral = Get("http://117.160.143.199:4624/Callrecords/Sound?" + msg); Console.Write(ral); } #region 批量下载录音文件 /// /// 批量下载录音文件 /// /// public void ExitSound(List CallList, config config) { // string filePath = Configs.GetValue("Sound_recording"); System.IO.DriveInfo[] allDrives = System.IO.DriveInfo.GetDrives(); string filePath = string.Empty; // 判断磁盘是否存在,不存在直接保存在C盘 string disk = "D:"; if (!Directory.Exists(disk)) filePath = "C:" + "\\CallCenter_Sound\\"; else filePath = "D:" + "\\CallCenter_Sound\\"; // 如果文件不存在,创建文件; 如果存在,跳过  try { if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } if (CallList != null) { int iii = 0; foreach (var it in CallList) { string FilePath = ""; if (it.FilePath != "" && config != null && !string.IsNullOrEmpty(config.F_ParamValue)) { var ym = config.F_ParamValue; if (ym.Substring(ym.Length - 1) == "/") { ym = ym.Substring(0, ym.Length - 1); } FilePath = ym + it.FilePath.Substring(it.FilePath.IndexOf(':') + 1).Replace('\\', '/'); } string filename = "l" + it.FilePath.Split('l')[1]; filename = filename.Split('.')[0] + "_" + it.CallNumber + ".mp3"; try { string[] sArray = filename.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries); string flie = filePath + "\\" + sArray[0] + "\\" + sArray[1] + "\\" + sArray[2]; if (!Directory.Exists(flie)) { Directory.CreateDirectory(flie); } if (System.IO.File.Exists(flie + "\\" + sArray[3])) { continue; } HttpWebRequest request = (HttpWebRequest)WebRequest.Create(FilePath); HttpWebResponse response = request.GetResponse() as HttpWebResponse; Stream responseStream = response.GetResponseStream(); Stream stream = new FileStream(flie + "\\" + sArray[3], FileMode.Create); byte[] bArr = new byte[1024]; int size = responseStream.Read(bArr, 0, bArr.Length); while (size > 0) { stream.Write(bArr, 0, size); size = responseStream.Read(bArr, 0, bArr.Length); } iii += 1; stream.Close(); responseStream.Close(); } catch (Exception e) { continue; } } } } catch (Exception e) { throw; } } #endregion } } #region Model public class config { public int F_ParamId { get; set; } /// /// /// public string F_ParamCode { get; set; } /// /// /// public string F_ParamValue { get; set; } /// /// /// public string F_ParamDes { get; set; } /// /// /// public int? F_State { get; set; } } public class T_Call_CallRecords { /// /// 呼叫编号 /// public string CallId { get; set; } /// /// 来电号码 /// public string CallNumber { get; set; } /// /// 客户id /// public string CusId { get; set; } /// /// 客户编号 /// public string CusCode { get; set; } /// /// 呼叫类型,0呼入1呼出 /// public int? CallType { get; set; } /// /// 呼叫状态,0:未接通电话1已接通电话 /// public int? CallState { get; set; } /// /// 处理方式0:IVR处理1骚扰电话2自助服务3转值班电话4留言5呼损6人工处理 /// public int? DealType { get; set; } /// /// 开始时间 /// public DateTime? BeginTime { get; set; } /// /// ivr开始时间 /// public DateTime? IvrStartTime { get; set; } /// /// ivr结束时间 /// public DateTime? IvrEndTime { get; set; } /// /// 振铃开始时间 /// public DateTime? RingStartTime { get; set; } /// /// 振铃结束时间 /// public DateTime? RingEndTime { get; set; } /// /// 通话开始时间 /// public DateTime? TalkStartTime { get; set; } /// /// 通话结束时间 /// public DateTime? TalkEndTime { get; set; } /// /// 结束时间 /// public DateTime? EndTime { get; set; } /// /// 总时长(s) /// public int? LongTime { get; set; } /// /// IVR时长(s) /// public int? IvrLongTime { get; set; } /// /// 振铃时长(s) /// public int? RingLongTime { get; set; } /// /// 通话时长(s) /// public int? TalkLongTime { get; set; } /// /// 坐席id /// public int? UserId { get; set; } /// /// 坐席工号 /// public string UserCode { get; set; } /// /// 坐席姓名 /// public string UserName { get; set; } /// /// 坐席分机号 /// public string ExtNumber { get; set; } /// /// 用于获取录音的编号 /// public string FilePath { get; set; } /// /// 是否录入工单 /// public bool IsExitWorkOrder { get; set; } /// /// 是否处理0未处理1已处理2注销 /// public int? IsDeal { get; set; } /// /// 操作类型,0正常1转移2三方通话 /// public int? OperateType { get; set; } /// /// 操作目标 /// public string OperateObject { get; set; } /// /// 操作时间 /// public DateTime? OperateTime { get; set; } /// /// 备注 /// public string Remark { get; set; } /// /// 满意度,1非常满意、2基本满意、3不满意 /// public int? MYD { get; set; } /// /// IVR中选择的业务类型 /// public int? BusinessType { get; set; } /// /// /// public string Location { get; set; } /// /// 来电自增Id /// public int CallRecordsId { get; set; } /// /// 排队开始时间 /// public DateTime? WaitStartTime { get; set; } /// /// 排队结束时间 /// public DateTime? WaitEndTime { get; set; } /// /// 排队时长 /// public int? WaitLongTime { get; set; } /// /// 未接通状态(0其他、1坐席未登录、2坐席忙、3振铃) /// public int? NoCallState { get; set; } /// /// 与工作时间间隔秒数 /// public int? WorkTimesDiff { get; set; } /// /// 质检状态(0未质检、1已质检) /// public int? F_QCState { get; set; } /// /// 质检分值 /// public decimal? F_QCScore { get; set; } /// /// 质检备注 /// public string F_QCRemark { get; set; } /// /// 质检人Id /// public int? F_QCUserId { get; set; } /// /// 质检人名称 /// public string F_QCUserName { get; set; } /// /// 质检时间 /// public DateTime? F_QCTime { get; set; } /// /// 是否推荐 /// public int? F_QCIsSelect { get; set; } /// /// /// public int? F_HJJGId { get; set; } /// /// /// public string F_HJJGName { get; set; } /// /// 质检客服-存在的问题 /// public string F_QCQuestion { get; set; } /// /// 质检客服-修改意见 /// public string F_QCAdvise { get; set; } /// /// 拨号类型:0:拨号外呼;1:95005回访外呼;2:电销回访外呼 /// public string TaskType { get; set; } /// /// 回访的电话ID /// public string TaskPhoneID { get; set; } /// /// 回访记录编号:GUID编号唯一 /// public string TaskID { get; set; } } #endregion