TG.WXCRM.V4/RiaService/CallRecord.svc.cs

968 lines
42 KiB
C#
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Ninject;
using RiaServiceLibrary;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Net;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using System.Web;
using WX.CRM.BLL.Util;
using WX.CRM.Common;
using WX.CRM.IBLL.Base;
using WX.CRM.IBLL.Csvr;
using WX.CRM.IBLL.Res;
using WX.CRM.Model.Entity;
using WX.CRM.Model.QueryMap;
using WX.CRM.WebHelper;
using WX.CRM.WebHelper.Infrastructure;
namespace RiaService
{
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[JavascriptCallbackBehavior(UrlParameterName = "jsoncallback")]
public class CallRecord : ICallRecord
{
private IBAS_INNERGROUP_Q _innergroupQ = NinjectControllerFactory.ninjectKernel.Get<IBAS_INNERGROUP_Q>();
private IBAS_INNERUSER_Q _inneruserQ = NinjectControllerFactory.ninjectKernel.Get<IBAS_INNERUSER_Q>();
private ICSVR_CALLRECORD_Q _callrecordQ = NinjectControllerFactory.ninjectKernel.Get<ICSVR_CALLRECORD_Q>();
public IRES_CUSTOMER _RES_CUSTOMER = NinjectControllerFactory.ninjectKernel.Get<IRES_CUSTOMER>();
public IRES_CUSTOMER_Q _RES_CUSTOMER_Q = NinjectControllerFactory.ninjectKernel.Get<IRES_CUSTOMER_Q>();
public IBAS_PARAMETER_Q _BAS_PARAMETER_Q = NinjectControllerFactory.ninjectKernel.Get<IBAS_PARAMETER_Q>();
public IRES_APPLY _RES_APPLY = NinjectControllerFactory.ninjectKernel.Get<IRES_APPLY>();
public ICSVR_CALLRECORD _CALLRECORD = NinjectControllerFactory.ninjectKernel.Get<ICSVR_CALLRECORD>();
public ICSVR_TODAYRECORD _CSVR_TODAYRECORD = NinjectControllerFactory.ninjectKernel.Get<ICSVR_TODAYRECORD>();
public IBAS_LOGINLOG_Q _BAS_LOGINLOG_Q = NinjectControllerFactory.ninjectKernel.Get<IBAS_LOGINLOG_Q>();
public ICSVR_CALLSTATIS _ICSVR_CALLSTATIS = NinjectControllerFactory.ninjectKernel.Get<ICSVR_CALLSTATIS>();
public ICSVR_APPLYVIP_Q applyvipBiz_Q = NinjectControllerFactory.ninjectKernel.Get<ICSVR_APPLYVIP_Q>();
public IRES_DISTRIBUTE res_Distribute_BLL = NinjectControllerFactory.ninjectKernel.Get<IRES_DISTRIBUTE>();
public ICSVR_VIPNUMBER_Q csvr_vipnumber_q = NinjectControllerFactory.ninjectKernel.Get<ICSVR_VIPNUMBER_Q>();
public IBAS_SUBCOMTYPE_Q _bassubcomtypeq = NinjectControllerFactory.ninjectKernel.Get<IBAS_SUBCOMTYPE_Q>();
ValidationErrors errors = new ValidationErrors();
public CallRecord()
{
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
}
}
public void test()
{
_CALLRECORD.DeleteByCOID("test");
}
/// <summary>
/// JMD录音接口
/// </summary>
/// <param name="serverID"></param>
/// <param name="file"></param>
/// <returns></returns>
public string GetCallFile(string serverID, string file)
{
if (string.IsNullOrEmpty(serverID) || string.IsNullOrEmpty(file))
{
return null;
}
var server = Utility.GetSettingByKey(serverID.ToUpper());
if (null == server)
{
LogHelper.Error("CallRecord.GetCallFile错误录音服务器" + server + "不存在");
return null;
}
var jsoncallback = HttpContext.Current.Request.QueryString["callback"];
string _localurl = "CallRecordFile//" + serverID.ToUpper() + "//" + file;
string localurl = HttpContext.Current.Server.MapPath(_localurl);
if (ChkRemoteFileExists(localurl))//文件已经存在
{
return "http://" + HttpContext.Current.Request.Url.Host + ":" + HttpContext.Current.Request.Url.Port + "/"
+ _localurl.Replace("//", "/");
}
else
{
string remoteUri = server + file;
string d = localurl.Substring(0, localurl.LastIndexOf("\\", System.StringComparison.Ordinal));
if (!Directory.Exists(d))
{
Directory.CreateDirectory(d);
}
try
{
Uri downUri = new Uri(remoteUri);
HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create(downUri);
using (Stream stream = hwr.GetResponse().GetResponseStream())
{
//文件流,流信息读到文件流中,读完关闭
using (FileStream fs = File.Create(localurl))
{
//建立字节组,并设置它的大小是多少字节
byte[] bytes = new byte[102400];
int n = 1;
while (n > 0)
{
//一次从流中读多少字节,并把值赋给N,当读完后,N为0,并退出循环
n = stream.Read(bytes, 0, 10240);
fs.Write(bytes, 0, n); //将指定字节的流信息写入文件流中
}
}
}
return "http://" + HttpContext.Current.Request.Url.Host + ":" + HttpContext.Current.Request.Url.Port + "/"
+ _localurl.Replace("//", "/");
}
catch (Exception ex)
{
LogHelper.Error(ex);
return null;
}
}
}
/// <summary>
/// 深海捷录音接口
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
public string GetSHJCallFile(string file)
{
if (string.IsNullOrEmpty(file))
{
return null;
}
var server = Utility.GetSettingByKey("SHJREC");
var jsoncallback = HttpContext.Current.Request.QueryString["callback"];
string _localurl = "CallRecordFile//" + file;
string localurl = HttpContext.Current.Server.MapPath(_localurl);
if (ChkRemoteFileExists(localurl))//文件已经存在
{
return "http://" + HttpContext.Current.Request.Url.Host + ":" + HttpContext.Current.Request.Url.Port + "/"
+ _localurl.Replace("//", "/");
}
else
{
string d = localurl.Substring(0, localurl.LastIndexOf("\\", System.StringComparison.Ordinal));
if (!Directory.Exists(d))
{
Directory.CreateDirectory(d);
}
try
{
string remoteUri = server + file;
Uri downUri = new Uri(remoteUri);
LogHelper.Error(downUri.ToString());
HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create(downUri);
using (Stream inputStream = hwr.GetResponse().GetResponseStream())
{
using (FileStream flieStream = new FileStream(localurl, FileMode.Create))
{
inputStream.CopyTo(flieStream);
}
}
return "http://" + HttpContext.Current.Request.Url.Host + ":" + HttpContext.Current.Request.Url.Port + "/"
+ _localurl.Replace("//", "/");
}
catch (Exception ex)
{
LogHelper.Error(ex);
return null;
}
}
}
/// <summary>
/// 获取艾讯录音NEW
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
public string GetAXNewCallFile(string file)
{
if (string.IsNullOrEmpty(file))
{
return null;
}
var server = Utility.GetSettingByKey("AXNEWREC");
var jsoncallback = HttpContext.Current.Request.QueryString["callback"];
string _localurl = "CallRecordFile//" + file;
string localurl = HttpContext.Current.Server.MapPath(_localurl);
if (ChkRemoteFileExists(localurl))//文件已经存在
{
return "http://" + HttpContext.Current.Request.Url.Host + ":" + HttpContext.Current.Request.Url.Port + "/"
+ _localurl.Replace("//", "/");
}
else
{
string d = localurl.Substring(0, localurl.LastIndexOf("\\", System.StringComparison.Ordinal));
if (!Directory.Exists(d))
{
Directory.CreateDirectory(d);
}
try
{
var isOLD = file.StartsWith("UP");
file = file.Replace("\\", "/");
string remoteUri = server + file;
if (isOLD)
{
remoteUri = server + "/home/" + file;
}
Uri downUri = new Uri(remoteUri);
HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create(downUri);
using (Stream inputStream = hwr.GetResponse().GetResponseStream())
{
using (FileStream flieStream = new FileStream(localurl, FileMode.Create))
{
inputStream.CopyTo(flieStream);
}
}
return "http://" + HttpContext.Current.Request.Url.Host + ":" + HttpContext.Current.Request.Url.Port + "/"
+ _localurl.Replace("//", "/");
}
catch (Exception ex)
{
LogHelper.Error(ex);
return null;
}
}
}
/// <summary>
/// 深海捷通话推送接口
/// </summary>
public void SHJ_CDRHandler(Stream input)
{
try
{
string body = new StreamReader(input).ReadToEnd();
NameValueCollection nvc = HttpUtility.ParseQueryString(body);
var Source = nvc["Source"];// 主叫号码(长度 80 字符)
var Destination = nvc["Destination"];// 被叫号码(长度 80 字符)
var DestinationContext = nvc["DestinationContext"];//目的地 context执行的上下文 (长度 80 字符)
var CallerID = nvc["CallerID"];// 主叫认息(长度 80 字符)
var Channel = nvc["Channel"];// 主叫通道(长度 80 字符)
var DestinationChannel = nvc["DestinationChannel"];//被叫通道(长度 80 字符)
var LastApplication = nvc["LastApplication"];// 最后执行的应用(长度 80 字符)
var LastData = nvc["LastData"];// 最后执行 context(长度 80 字符)
var StartTime = nvc["StartTime"];// 呼叫开始的时间0000-00-00 00:00:00
var EndTime = nvc["EndTime"];
var Duration = nvc["Duration"];// 整个呼叫的时间,从呼叫开始到结束,使用秒来计费(数据类型:整数)
var BillableSeconds = nvc["BillableSeconds"];// 整个呼叫通话的时间,从呼叫接通开始到结束,使用秒来计费(数据类型:整数)
var Disposition = nvc["Disposition"];// 呼叫状态(接通-'ANSWERED',没有接通-'NO ANSWER',忙音-'BUSY',失败-'FAILED'
var _UniqueID = nvc["UniqueID"];// 通话记录的唯一标识
var UserField = nvc["UserField"];// 录音文件名
var Exten = nvc["Exten"]; //电话呼出信元即呼出电话时cdr 信息有此参数,表示分机号
var Dname = nvc["Dname"]; //被叫分机座席名称
var Sname = nvc["Sname"]; //主叫分机座席名称
var _CallType = nvc["CallType"]; //呼叫类型0:内部通话1外线呼入2内部呼出3未知
if (string.IsNullOrEmpty(Source) || string.IsNullOrEmpty(Destination) || Disposition != "ANSWERED")
{
LogHelper.Info("SHJ_CDRHandler失败" + body + System.Environment.NewLine);
return;
}
int CallType = -1;
if (_CallType == "1")//呼入
{
CallType = 0;
}
if (_CallType == "2")//呼出
{
CallType = 1;
}
var _ag = new CSVR_CALLRECORD();
_ag.RECORDID = Convert.ToDecimal(_UniqueID);
_ag.SERVERID = "";
_ag.FILENAME = UserField;
var fjh = "";
var num = "";
if (CallType == 0)//呼入
{
fjh = Destination;
num = Source;
}
if (CallType == 1)//呼出
{
fjh = Source;
num = Destination;
}
if (num.StartsWith("01") && num.Length == 12)
{
num = num.Substring(1);
}
_ag.RESID = "";
if (!string.IsNullOrEmpty(num) && num.Trim() != "")
{
num = num.Trim();
var resid = GetRes(num);
_ag.RESID = resid;
}
_ag.SERVICENUMBER = fjh;
if (num.Length > 4)
_ag.TELNUMBERLAST4 = num.Substring(num.Length - 4);
else
_ag.TELNUMBERLAST4 = num;
var lstlog = _BAS_LOGINLOG_Q.GetLoginLogLst(fjh, Convert.ToDateTime(StartTime));
_ag.SALESEID = null;
if (null != lstlog)
{
_ag.SALESEID = lstlog.LOGINEID;
}
_ag.TIMELENGTH = int.Parse(BillableSeconds);
_ag.CALLTYPE = CallType;
_ag.TIMESTART = Convert.ToDateTime(StartTime);
_ag.CTIME = DateTime.Now;
_ag.TIMEEND = Convert.ToDateTime(EndTime);
// new CreateRecord().AddRecordList(new List<CSVR_CALLRECORD> { _ag });
_CALLRECORD.AddListRecord(new List<CSVR_CALLRECORD> { _ag });
var _ag2 = new CSVR_TODAYRECORD()
{
CALLTYPE = _ag.CALLTYPE,
COID = _ag.COID,
CTIME = _ag.CTIME,
RECORDID = _ag.RECORDID,
FILENAME = _ag.FILENAME,
RESID = _ag.RESID,
SALESEID = _ag.SALESEID,
SERVERID = _ag.SERVERID,
SERVICENUMBER = _ag.SERVICENUMBER,
TELNUMBERLAST4 = _ag.TELNUMBERLAST4,
TIMELENGTH = _ag.TIMELENGTH,
TIMESTART = _ag.TIMESTART,
TIMEEND = _ag.TIMEEND
};
_CSVR_TODAYRECORD.AddListRecord(new List<CSVR_TODAYRECORD> { _ag2 });
}
catch (Exception ex)
{
LogHelper.Info("SHJ_CDRHandler异常" + ex.Message + ex.StackTrace + System.Environment.NewLine);
}
}
/// <summary>
/// 艾讯通话推送接口
/// </summary>
public void MakeCallLog()
{
try
{
var req = HttpContext.Current.Request;
LogHelper.Debug("MakeCallLog:" + req["obj"]);
}
catch (Exception e)
{
LogHelper.Error(e);
}
}
/// <summary>
/// 艾讯通话推送接口
/// </summary>
public void AX_CDRHandler()
{
try
{
var nvc = HttpContext.Current.Request;
if (nvc == null)
LogHelper.Info("nvc is null");
var Source = nvc["Source"];// 主叫号码(长度 80 字符)
var Destination = nvc["Destination"];// 被叫号码(长度 80 字符)
var CallerID = nvc["CallerID"];// 主叫认息(长度 80 字符)
var StartTime = nvc["StartTime"];// 呼叫开始的时间0000-00-00 00:00:00
var EndTime = nvc["EndTime"];
var Duration = nvc["Duration"];// 整个呼叫的时间,从呼叫开始到结束,使用秒来计费(数据类型:整数)
var BillableSeconds = nvc["BillableSeconds"];// 整个呼叫通话的时间,从呼叫接通开始到结束,使用秒来计费(数据类型:整数)
var Disposition = nvc["Disposition"];// 呼叫状态(接通-'ANSWERED',没有接通-'NO ANSWER',忙音-'BUSY',失败-'FAILED'
var _UniqueID = nvc["UniqueID"];// 通话记录的唯一标识
var UserField = nvc["UserField"];// 录音文件名
var Exten = nvc["Exten"]; //电话呼出信元即呼出电话时cdr 信息有此参数,表示分机号
var _CallType = nvc["CallType"]; //呼叫类型0:内部通话1外线呼入2内部呼出3未知
var Action = nvc["Action"];
var _isTran = nvc["isTran"];
if (string.IsNullOrEmpty(Source) || string.IsNullOrEmpty(Destination))
{
LogHelper.Info("AX_CDRHandler失败没有主叫号码或被叫号码");
HttpContext.Current.Response.Write(Utility.ConvertToJSON(new { result = 0, message = "处理失败:没有主叫号码或被叫号码" }));
return;
}
if (Source == Destination)
{
LogHelper.Info("AX_CDRHandler失败主叫号码和被叫号码相同Source:" + Source + ",Destination:" + Destination + ",_UniqueID:" + _UniqueID);
HttpContext.Current.Response.Write(Utility.ConvertToJSON(new { result = 0, message = "处理失败:主叫号码和被叫号码相同" }));
return;
}
if (Disposition.Trim().ToUpper() != "ANSWER")
{
AX_UNCDRHandler_Handle(1);
return;
}
if (_CallType == "3")
{
_CallType = "2";
}
//if (_CallType != "1" && _CallType != "2")
//{
// LogHelper.Info("AX_CDRHandler失败呼叫类型不正确" + _CallType + ")。");
// HttpContext.Current.Response.Write(Utility.ConvertToJSON(new { result = 0, message = "处理失败:呼叫类型不正确(" + _CallType + "" }));
// return;
//}
#region
var _num_encypt = _BAS_PARAMETER_Q.GetModel_Patameter("SYS_CALLOUT_NUM_ENCYPTDES");
var _bol_encypt = false;
if (_num_encypt != null && _num_encypt.PARAVALUE.ToLower() == "true")
{
_bol_encypt = true;
}
if (_bol_encypt)
{
Destination = new SecurityHelper().decyptCtiNumStr(Destination);
Source = new SecurityHelper().decyptCtiNumStr(Source);
}
#endregion
int CallType = -1;
if (_CallType == "1")//呼入
{
CallType = 0;
}
if (_CallType == "2")//呼出
{
CallType = 1;
}
int? isTran = null; int _int;
if (!string.IsNullOrEmpty(_isTran) && int.TryParse(_isTran, out _int))
{
isTran = _int;
}
var _ag = new CSVR_CALLRECORD();
_ag.RECORDID = 0;
_ag.COID = _UniqueID;
_ag.SERVERID = "";
_ag.FILENAME = UserField;
var fjh = "";
var num = "";
if (CallType == 0)//呼入
{
fjh = Destination;
num = Source;
}
if (CallType == 1)//呼出
{
fjh = Source;
num = Destination;
}
if (num.StartsWith("01") && num.Length == 12)
{
num = num.Substring(1);
}
num = num.Replace("+86", "");
if (num.Length == 12 && num.StartsWith("01"))//长度必须是12位且是01开头必然是手机号去除前面的0
{
num = num.Substring(num.Length - 11, 11);
}
else if (num.Length > 12)//大于12位的取后面的11位
{
num = num.Substring(num.Length - 11, 11);
}//小于等于11的不做处理
_ag.RESID = "";
if (!string.IsNullOrEmpty(num) && num.Trim() != "")
{
num = num.Trim();
var resid = GetRes(num);
_ag.RESID = resid;
}
_ag.SERVICENUMBER = fjh;
if (num.Length > 4)
_ag.TELNUMBERLAST4 = num.Substring(num.Length - 4);
else
_ag.TELNUMBERLAST4 = num;
var lstlog = _BAS_LOGINLOG_Q.GetLoginLogLst(fjh, Convert.ToDateTime(StartTime));
_ag.SALESEID = null;
if (null != lstlog)
{
_ag.SALESEID = lstlog.LOGINEID;
}
_ag.TIMELENGTH = int.Parse(BillableSeconds);
_ag.CALLTYPE = CallType;
_ag.TIMESTART = Convert.ToDateTime(StartTime);
_ag.CTIME = DateTime.Now;
_ag.TIMEEND = Convert.ToDateTime(EndTime);
_ag.ISTRAN = isTran;
if (Action == "Reload")
{
_CALLRECORD.AddListRecord2(new List<CSVR_CALLRECORD> { _ag });
}
else
{
_CALLRECORD.AddListRecord(new List<CSVR_CALLRECORD> { _ag });
}
var _ag2 = new CSVR_TODAYRECORD()
{
CALLTYPE = _ag.CALLTYPE,
COID = _UniqueID,
CTIME = _ag.CTIME,
RECORDID = 0,
FILENAME = _ag.FILENAME,
RESID = _ag.RESID,
SALESEID = _ag.SALESEID,
SERVERID = _ag.SERVERID,
SERVICENUMBER = _ag.SERVICENUMBER,
TELNUMBERLAST4 = _ag.TELNUMBERLAST4,
TIMELENGTH = _ag.TIMELENGTH,
TIMESTART = _ag.TIMESTART,
TIMEEND = _ag.TIMEEND,
ISTRAN = _ag.ISTRAN
};
if (Action == "Reload")
{
}
else
{
_CSVR_TODAYRECORD.AddListRecord(new List<CSVR_TODAYRECORD> { _ag2 });
}
try
{
var _satis = nvc["satis"]; //3未评价1非常满意2不满意4客户听了满意度放音后未评价或通话结束后客户先挂机时的值
if (!string.IsNullOrEmpty(_satis))
{
var csvr_statis = new CSVR_CALLSTATISDETAIL();
csvr_statis.PKID = Guid.NewGuid().ToString();
csvr_statis.SALESEID = _ag2.SALESEID ?? 0;
csvr_statis.INSERTTIME = DateTime.Now;
csvr_statis.SATISFACTION = Convert.ToInt32(_satis);
csvr_statis.SESSIONID = _UniqueID;
if (Action == "Reload")
{
}
else
{
_ICSVR_CALLSTATIS.AddModel(csvr_statis);
}
}
res_Distribute_BLL.UpdateCacheResCountLastCallTime(_ag.RESID, _ag.CTIME);
}
catch (Exception ex)
{
LogHelper.Error("插入满意度出错!", ex);
}
HttpContext.Current.Response.Write(Utility.ConvertToJSON(new { result = 1, message = "处理成功" }));
}
catch (Exception ex)
{
LogHelper.Error(ex.ToString());
HttpContext.Current.Response.Write(Utility.ConvertToJSON(new { result = 0, message = "处理失败" }));
}
}
public void VipCheck()
{
try
{
var nvc = HttpContext.Current.Request;
var num = nvc["mobile"];// 客户号码(长度 80 字符)
var number = nvc["number"];// 客服 热线编号(长度 80 字符)
if (string.IsNullOrWhiteSpace(num))
{
//HttpContext.Current.Response.Write(Utility.ConvertToJSON(new { result = 1, message = "oh no,mobile can not null !", isvip = false }));
HttpContext.Current.Response.Write("false");
return;
}
if (string.IsNullOrWhiteSpace(number))
{
//HttpContext.Current.Response.Write(Utility.ConvertToJSON(new { result = 1, message = "oh no,number can not null !", isvip = false }));
HttpContext.Current.Response.Write("false");
return;
}
//var _num_encypt = _BAS_PARAMETER_Q.GetModel_Patameter("SYS_CALLOUT_NUM_ENCYPTDES");
//var _bol_encypt = false;
//if (_num_encypt != null && _num_encypt.PARAVALUE.ToLower() == "true")
//{
// _bol_encypt = true;
//}
//if (_bol_encypt)
//{
// num = new SecurityHelper().decyptCtiNumStr(num);
// number = new SecurityHelper().decyptCtiNumStr(number);
//}
if (num.StartsWith("01") && num.Length == 12)
{
num = num.Substring(1);
}
num = num.Replace("+86", "");
if (num.Length == 12 && num.StartsWith("01"))//长度必须是12位且是01开头必然是手机号去除前面的0
{
num = num.Substring(num.Length - 11, 11);
}
else if (num.Length > 12)//大于12位的取后面的11位
{
num = num.Substring(num.Length - 11, 11);
}
string resid = ResUtil.CreateResId(num);
bool result = csvr_vipnumber_q.IsVipNumber(ref errors, resid, number);
if (result)
{
//HttpContext.Current.Response.Write(Utility.ConvertToJSON(new { result = 1, message = "vip", isvip = true }));
HttpContext.Current.Response.Write("true");
}
else
{
//HttpContext.Current.Response.Write(Utility.ConvertToJSON(new { result = 1, message = "not vip", isvip = false }));
HttpContext.Current.Response.Write("false");
}
}
catch (Exception e)
{
LogHelper.Error(e.ToString());
HttpContext.Current.Response.Write("false");
}
}
/// <summary>
/// 艾讯通话推送接口-未接通
/// </summary>
public void AX_UNCDRHandler()
{
AX_UNCDRHandler_Handle(2);
}
/// <summary>
/// 未接通入库
/// </summary>
/// <param name="ntype">ntype=1 实时推 ntype=2晚上推</param>
private void AX_UNCDRHandler_Handle(int ntype)
{
try
{
var nvc = HttpContext.Current.Request;
var Source = nvc["Source"];// 主叫号码(长度 80 字符)
var Destination = nvc["Destination"];// 被叫号码(长度 80 字符)
var CallerID = nvc["CallerID"];// 主叫认息(长度 80 字符)
var StartTime = nvc["StartTime"];// 呼叫开始的时间0000-00-00 00:00:00
var EndTime = nvc["EndTime"];
var Duration = nvc["Duration"];// 整个呼叫的时间,从呼叫开始到结束,使用秒来计费(数据类型:整数)
var BillableSeconds = nvc["BillableSeconds"];// 整个呼叫通话的时间,从呼叫接通开始到结束,使用秒来计费(数据类型:整数)
var Disposition = nvc["Disposition"];// 呼叫状态(接通-'ANSWERED',没有接通-'NO ANSWER',忙音-'BUSY',失败-'FAILED'
var _UniqueID = nvc["UniqueID"];// 通话记录的唯一标识
var UserField = nvc["UserField"];// 录音文件名
var Exten = nvc["Exten"]; //电话呼出信元即呼出电话时cdr 信息有此参数,表示分机号
var _CallType = nvc["CallType"]; //呼叫类型0:内部通话1外线呼入2内部呼出3未知
var Action = nvc["Action"];
if (string.IsNullOrEmpty(Source) || string.IsNullOrEmpty(Destination))
{
LogHelper.Info("AX_CDRHandler失败没有主叫号码或被叫号码");
HttpContext.Current.Response.Write(Utility.ConvertToJSON(new { result = 0, message = "处理失败:没有主叫号码或被叫号码" }));
return;
}
if (Source == Destination)
{
LogHelper.Info("AX_CDRHandler失败主叫号码和被叫号码相同Source:" + Source + ",Destination:" + Destination + ",_UniqueID:" + _UniqueID);
HttpContext.Current.Response.Write(Utility.ConvertToJSON(new { result = 0, message = "处理失败:主叫号码和被叫号码相同" }));
return;
}
if (_CallType == "3")
{
_CallType = "2";
}
//if (_CallType != "1" && _CallType != "2")
//{
// LogHelper.Info("AX_CDRHandler失败呼叫类型不正确" + _CallType + ")。");
// HttpContext.Current.Response.Write(Utility.ConvertToJSON(new { result = 0, message = "处理失败:呼叫类型不正确(" + _CallType + "" }));
// return;
//}
#region
if (ntype == 1)
{
var _num_encypt = _BAS_PARAMETER_Q.GetModel_Patameter("SYS_CALLOUT_NUM_ENCYPTDES");
var _bol_encypt = false;
if (_num_encypt != null && _num_encypt.PARAVALUE.ToLower() == "true")
{
_bol_encypt = true;
}
if (_bol_encypt)
{
Destination = new SecurityHelper().decyptCtiNumStr(Destination);
Source = new SecurityHelper().decyptCtiNumStr(Source);
}
}
#endregion
int CallType = -1;
if (_CallType == "1")//呼入
{
CallType = 0;
}
if (_CallType == "2")//呼出
{
CallType = 1;
}
var _ag = new CSVR_CALLRECORDUN();
_ag.RECORDID = 0;
_ag.COID = _UniqueID;
_ag.SERVERID = "";
_ag.FILENAME = UserField;
var fjh = "";
var num = "";
if (CallType == 0)//呼入
{
fjh = Destination;
num = Source;
}
if (CallType == 1)//呼出
{
fjh = Source;
num = Destination;
}
if (num.StartsWith("01") && num.Length == 12)
{
num = num.Substring(1);
}
num = num.Replace("+86", "");
if (num.Length == 12 && num.StartsWith("01"))//长度必须是12位且是01开头必然是手机号去除前面的0
{
num = num.Substring(num.Length - 11, 11);
}
else if (num.Length > 12)//大于12位的取后面的11位
{
num = num.Substring(num.Length - 11, 11);
}//小于等于11的不做处理
_ag.RESID = "";
if (!string.IsNullOrEmpty(num) && num.Trim() != "")
{
num = num.Trim();
var resid = GetRes(num);
_ag.RESID = resid;
}
_ag.SERVICENUMBER = fjh;
if (num.Length > 4)
_ag.TELNUMBERLAST4 = num.Substring(num.Length - 4);
else
_ag.TELNUMBERLAST4 = num;
var lstlog = _BAS_LOGINLOG_Q.GetLoginLogLst(fjh, Convert.ToDateTime(StartTime));
_ag.SALESEID = null;
if (null != lstlog)
{
_ag.SALESEID = lstlog.LOGINEID;
}
_ag.TIMELENGTH = int.Parse(BillableSeconds);
_ag.CALLTYPE = CallType;
_ag.TIMESTART = Convert.ToDateTime(StartTime);
_ag.CTIME = DateTime.Now;
_ag.TIMEEND = Convert.ToDateTime(EndTime);
_ag.DISPOSITION = Disposition;
_CALLRECORD.AddListRecordUN(new List<CSVR_CALLRECORDUN> { _ag });
var _ag2 = new CSVR_TODAYRECORDUN()
{
CALLTYPE = _ag.CALLTYPE,
COID = _UniqueID,
CTIME = _ag.CTIME,
RECORDID = 0,
FILENAME = _ag.FILENAME,
RESID = _ag.RESID,
SALESEID = _ag.SALESEID,
SERVERID = _ag.SERVERID,
SERVICENUMBER = _ag.SERVICENUMBER,
TELNUMBERLAST4 = _ag.TELNUMBERLAST4,
TIMELENGTH = _ag.TIMELENGTH,
TIMESTART = _ag.TIMESTART,
TIMEEND = _ag.TIMEEND,
DISPOSITION = _ag.DISPOSITION
};
_CSVR_TODAYRECORD.AddListRecordUn(new List<CSVR_TODAYRECORDUN> { _ag2 });
try
{
res_Distribute_BLL.UpdateCacheResCountLastCallTime(_ag.RESID, _ag.CTIME);
}
catch (Exception ex)
{
LogHelper.Error("插入满意度出错!", ex);
}
HttpContext.Current.Response.Write(Utility.ConvertToJSON(new { result = 1, message = "处理成功" }));
}
catch (Exception ex)
{
LogHelper.Error("AX_UNCDRHandler异常", ex);
HttpContext.Current.Response.Write(Utility.ConvertToJSON(new { result = 0, message = "处理失败" }));
}
}
/// <summary>
/// 注册或获取客户ID
/// </summary>
/// <param name="regmobile"></param>
/// <returns></returns>
private string GetRes(string regmobile)
{
string resid = string.Empty;
if (regmobile.Length > 5)
{
resid = WX.CRM.Common.ResUtil.CreateResId(regmobile);
if (_RES_CUSTOMER_Q.getResCustomerByResId(resid) == null)
{
LogHelper.Info("需要注册的手机号码:" + regmobile + "resid:" + resid);
var cusFrom = _BAS_PARAMETER_Q.GetModel_Patameter("CustomerFrom");
if (cusFrom != null)
{
_RES_CUSTOMER.ResgisterCustomer(regmobile, resid, cusFrom.PARAVALUE);
#region
RES_APPLY applyinfo = new RES_APPLY();
applyinfo.CTIME = DateTime.Now;
applyinfo.JSONDATA = string.Empty;
applyinfo.JSONTYPE = 0;
applyinfo.MOBILE = regmobile;
applyinfo.RESID = resid;
applyinfo.RESOURCETAG = cusFrom.PARAVALUE;
applyinfo.RTIME = DateTime.Now;
applyinfo.STATUS = 0;
applyinfo.USERNAME = "";
_RES_APPLY.Create(ref errors, applyinfo);
#endregion
}
}
}
return resid;
}
//判断远程文件是否存在
private bool ChkRemoteFileExists(string fileUrl)
{
bool result = false;//判断结果
WebResponse response = null;
try
{
WebRequest req = WebRequest.Create(fileUrl);
response = req.GetResponse();
result = true;
}
catch (Exception ex)
{
result = false;
}
finally
{
if (response != null)
{
response.Close();
}
}
return result;
}
public Stream GetCallRecordList(string key)
{
CallRecordModel recordModel = null;
try
{
recordModel = Utility.JSONToObject<CallRecordModel>(key);
}
catch (Exception ex)
{
LogHelper.Error("GetCallRecordList数据转换" + ex.ToString());
}
if (recordModel != null)
{
try
{
Pager pg = new Pager()
{
page = recordModel.pageIndex,
rows = recordModel.pageSize
};
DateTime? ctime = recordModel.stime.GetDateTime();
DateTime? etime = recordModel.etime.GetDateTime();
int? maxLength = recordModel.maxLength.GetInt();
int? minLength = recordModel.minLength.GetInt();
decimal? eid = recordModel.usereid.GetDecimal();
decimal? calltype = recordModel.calltype.GetDecimal();
decimal? recordid = recordModel.recordid.GetDecimal();
List<getCallRecord> list = _callrecordQ.GetOACallRecord(ref pg, recordModel.groupname, eid, ctime, etime, maxLength, minLength, recordModel.customerid, recordid, calltype).Tables[0].ToList<getCallRecord>();
if (list.Count > 0)
{
getCallRecord model = list.FirstOrDefault(p => p.RECORDID == 0 && p.nrow > 0);
pg.totalRows = Convert.ToInt32(model.nrow);
list.Remove(model);
}
string data = Utility.ObjectToJsonAndConvertTime<getCallRecord>(list);
data = HttpUtility.UrlEncode(data, Encoding.UTF8);
return Utility.GetStream(Utility.ObjectToJson(new { result = true, total = pg.totalRows, data = data }));
}
catch (Exception ex)
{
LogHelper.Error(ex);
return Utility.GetStream(Utility.ObjectToJson(new { result = false, total = 0, data = HttpUtility.UrlEncode("系统错误!", Encoding.UTF8) }));
}
}
else
{
return Utility.GetStream(Utility.ObjectToJson(new { result = false, total = 0, data = HttpUtility.UrlEncode("参数转换错误!", Encoding.UTF8) }));
}
}
public void IsVipNum()
{
try
{
var mobile = HttpContext.Current.Request["mobile"];
var encypt = HttpContext.Current.Request["encypt"];
if (string.IsNullOrEmpty(mobile))
{
HttpContext.Current.Response.Write("0");
HttpContext.Current.Response.End();
}
if (encypt == "true")
{
mobile = new SecurityHelper().decyptCtiNumStr(mobile);
}
var resid = WX.CRM.Common.ResUtil.CreateResId(mobile);
var model = applyvipBiz_Q.Get(m => m.RESID == resid && m.STATUS == (decimal)WX.CRM.Model.Enum.EnumApplyModifyPrimayNumberStatus.);
if (model != null)
{
HttpContext.Current.Response.Write("1");
}
else
{
HttpContext.Current.Response.Write("0");
}
}
catch (Exception ex)
{
LogHelper.Error(ex);
HttpContext.Current.Response.Write("0");
}
}
}
}