public static AgentNumber GetInstance() { if (_object == null) { lock (LockHelper) { if (_object == null) { _object = new AgentNumber(); } } } return(_object); }
private bool SyncAgentNumber(Model.Entity.DeviceContact contact, Model.Entity.Device device, string callerNum, string calledNum, string callInMidNum, string callOutMidNum, int opt) { try { SetBindNum sbn = new SetBindNum(); sbn.header.SERVICENAME = "setBindNum"; sbn.header.OPERATE = opt; CloudPlatformInfo cpi = AgentNumber.GetInstance().GetCloudPlatformInfo(2); string time = DateTime.Now.ToString("yyyyMMddHHmmss"); string token = MD5Helper.MD5Encrypt(cpi.Key + time, null); sbn.header.TOKEN = token.ToLower(); sbn.header.VCCID = int.Parse(cpi.VccId); sbn.body.TYPE = 1; sbn.body.STREAMNUMBER = Guid.NewGuid().ToString(); sbn.body.MESSAGEID = DateTime.Now.ToString("yyyyMMddHHmmssfff"); sbn.body.WAYBILLNUM = ""; sbn.body.CALLERNUM = callerNum; sbn.body.MIDDLEINNUM = callInMidNum; sbn.body.MIDDLEOUTNUM = callOutMidNum; sbn.body.CALLEDNUM = calledNum; sbn.body.MAXDURATION = 3600; sbn.body.ISRECORD = 0; sbn.body.STATE = 0; sbn.body.VALIDTIME = ""; var client = new RestClient(cpi.UrlNumberAnalysis); client.AddHandler("application/json", new CommAnalysisResponseDeserializer()); var request = new RestRequest(Method.POST); request.AddJsonBody(sbn); request.Timeout = 5000; request.ReadWriteTimeout = 5000; JsonSerializer jsonSerializer = new JsonSerializer { ContentType = "application/json" }; request.JsonSerializer = jsonSerializer; Logger.Error("开始同步通讯录绑定关系,内容为:" + jsonSerializer.Serialize(sbn)); var response = client.Execute <CommAnalysisResponse>(request); return(ProcessResponse(contact, opt, response)); } catch (Exception e) { Logger.Error("同步通讯录绑定关系出错:", e); return(false); } }
public void PreModAgentNumber(Model.Entity.DeviceContact contact, int opt) { var enabled = AppConfig.GetValue(Constants.CLOUDPLATFORM_ENABLED); if (!"1".Equals(enabled)) { return; } Model.Entity.Device device = Device.GetInstance().Get(contact.DeviceID); if (device == null || string.IsNullOrEmpty(device.PhoneNumber) || device.CloudPlatform == 0) { Logger.Debug("设备数据异常,不用同步!"); return; } // Logger.Error("获取中间号列表"); List <Model.Entity.AgentNumber> list = AgentNumber.GetInstance().Get(device.CloudPlatform); if (list == null || list.Count == 0) { Logger.Error("中间号为空,请先添加中间号"); return; } if (string.IsNullOrEmpty(contact.AgentNumber) || string.IsNullOrEmpty(contact.CallOutNumber)) { // Logger.Info("计算中间号:"+contact.PhoneNumber); List <Model.Entity.DeviceContact> dcList = GetByDeviceId(contact.DeviceID); dcList.Remove(contact); List <string> agNumList = dcList.ConvertAll(x => x.AgentNumber).ToList(); List <Model.Entity.AgentNumber> availableANs = list.Where(x => !agNumList.Contains(x.Number)).ToList(); if (availableANs.Count == 0) { Logger.Error("没有可用的中间号,请先添加足够的中间号!"); return; } contact.AgentNumber = availableANs[0].Number; contact.CallOutNumber = availableANs[0].CallOutNumber; } object[] obj = { contact, opt }; new Thread(ProcessSync).Start(obj); }