コード例 #1
0
        /// <summary>
        /// 查询宇通用户
        /// </summary>
        /// <returns></returns>
        public static DataTable SearchContact()
        {
            //如果没有接入码或者sap代码,则不调用接口
            if (string.IsNullOrEmpty(GlobalStaticObj_YT.ClientID) ||
                string.IsNullOrEmpty(GlobalStaticObj_YT.SAPCode))
            {
                return null;
            }
            ServicePointManager.ServerCertificateValidationCallback = WebServUtil.ValidateServerCertificate;
            QueryContact.clientInfo clientInfo = new QueryContact.clientInfo();
            clientInfo.clientID = GlobalStaticObj_YT.ClientID;
            clientInfo.serviceID = "queryContact";
            QueryContact.portTypeService serv = new QueryContact.portTypeService();
            string updateTime = Secret.Encrypt3DES_UTF8("1900-01-01", GlobalStaticObj_YT.KeySecurity_YT);//查询所有日期的
            string priovinceCode = Secret.Encrypt3DES_UTF8(GlobalStaticObj_Server.Instance.ServiceStationProvince, GlobalStaticObj_YT.KeySecurity_YT);
            //string priovinceCode = Secret.Encrypt3DES_UTF8("620000", GlobalStaticObj_YT.KeySecurity_YT);
            string stationCode = Secret.Encrypt3DES_UTF8(GlobalStaticObj_YT.SAPCode, GlobalStaticObj_YT.KeySecurity_YT);
            string dateStr = Secret.Encrypt3DES_UTF8(GlobalStaticObj_Server.Instance.CurrentDateTime.ToString("yyyy-MM-dd HH:mm:ss"), GlobalStaticObj_YT.KeySecurity_YT);
            string requestType = Secret.Encrypt3DES_UTF8("QUERY", GlobalStaticObj_YT.KeySecurity_YT);
            clientInfo = WebServUtil.EncModel<QueryContact.clientInfo>(clientInfo);
            string contType = Secret.Encrypt3DES_UTF8("03", GlobalStaticObj_YT.KeySecurity_YT);//用户类型
            List<ListItem> listContact = new List<ListItem>();
            DataTable dt = new DataTable();
            dt.Columns.Add("cont_crm_guid");
            dt.Columns.Add("cont_name");
            dt.Columns.Add("cont_phone");
            QueryContact.Result result = new QueryContact.Result();
            string message = string.Empty;//错误消息
            try
            {
                result = serv.queryContact(updateTime, priovinceCode, contType, stationCode, dateStr, requestType, clientInfo);
            }
            catch (InvalidOperationException ioe)
            {
                //Utility.Log.Log.writeLineToLog(ioe, "联系人信息同步");
                GlobalStaticObj_Server.YTInterfaceLogService.WriteLog("联系人信息同步", ioe);
                return null;
            }
            string state = Secret.Decrypt3DES_UTF8(result.state, GlobalStaticObj_YT.KeySecurity_YT);
            if (state == "F")
            {
                string errMsg = Secret.Decrypt3DES_UTF8(result.errorMsg, GlobalStaticObj_YT.KeySecurity_YT);
                //Utility.Log.Log.writeLineToLog("【联系人信息同步】" + errMsg, "接口");
                GlobalStaticObj_Server.YTInterfaceLogService.WriteLog("联系人信息同步", errMsg);
                return null;
            }
            QueryContact.contact[] contactArr = WebServUtil.DesList(result.Details);
            if (contactArr.Length == 0)
            {
                return dt;
            }
            foreach (QueryContact.contact cont in contactArr)
            {
                DataRow dr = dt.NewRow();
                dr["cont_crm_guid"] = cont.cont_crm_guid;
                dr["cont_name"] = cont.cont_name;
                dr["cont_phone"] = cont.cont_phone;
                dt.Rows.Add(dr);
            }

            return dt;
        }
コード例 #2
0
        /// <summary> 联系人信息同步
        /// </summary>
        /// <param name="updateTime">最后更新时间</param>
        /// <param name="contType">联系人类别</param>
        /// <returns>返回同步联系人条数,如为-1,同步失败</returns>
        public static string LoadContact(string updateTime, string contType)
        {
            //如果没有接入码或者sap代码,则不调用接口
            if (string.IsNullOrEmpty(GlobalStaticObj_YT.ClientID) ||
                string.IsNullOrEmpty(GlobalStaticObj_YT.SAPCode))
            {
                return "";
            }
            ServicePointManager.ServerCertificateValidationCallback = WebServUtil.ValidateServerCertificate;
            QueryContact.clientInfo clientInfo = new QueryContact.clientInfo();
            clientInfo.clientID = GlobalStaticObj_YT.ClientID;
            clientInfo.serviceID = "queryContact";
            QueryContact.portTypeService serv = new QueryContact.portTypeService();
            updateTime = Secret.Encrypt3DES_UTF8(updateTime, GlobalStaticObj_YT.KeySecurity_YT);
            string priovinceCode = Secret.Encrypt3DES_UTF8(GlobalStaticObj_Server.Instance.ServiceStationProvince, GlobalStaticObj_YT.KeySecurity_YT);
            //string priovinceCode = Secret.Encrypt3DES_UTF8("620000", GlobalStaticObj_YT.KeySecurity_YT);
            string stationCode = Secret.Encrypt3DES_UTF8(GlobalStaticObj_YT.SAPCode, GlobalStaticObj_YT.KeySecurity_YT);
            string dateStr = Secret.Encrypt3DES_UTF8(GlobalStaticObj_Server.Instance.CurrentDateTime.ToString("yyyy-MM-dd HH:mm:ss"), GlobalStaticObj_YT.KeySecurity_YT);
            string requestType = Secret.Encrypt3DES_UTF8("QUERY", GlobalStaticObj_YT.KeySecurity_YT);
            clientInfo = WebServUtil.EncModel<QueryContact.clientInfo>(clientInfo);
            contType = Secret.Encrypt3DES_UTF8(contType, GlobalStaticObj_YT.KeySecurity_YT);
            DateTime dtStart = GlobalStaticObj_Server.Instance.CurrentDateTime;//开始时间
            string message = string.Empty;//错误信息
            QueryContact.Result result = new QueryContact.Result();
            try
            {
                result = serv.queryContact(updateTime, priovinceCode, contType, stationCode, dateStr, requestType, clientInfo);
            }
            catch (InvalidOperationException ioe)
            {
                message = ioe.Message;
                //Utility.Log.Log.writeLineToLog(ioe, "联系人信息同步");
                GlobalStaticObj_Server.YTInterfaceLogService.WriteLog("联系人信息同步", ioe);
                return "联系人接口调用超时!";
            }
            catch (Exception e)
            {
                message = e.Message;
                //Utility.Log.Log.writeLineToLog(e, "联系人信息同步");
                GlobalStaticObj_Server.YTInterfaceLogService.WriteLog("联系人信息同步", e);
                return "联系人接口调用出错";
            }
            string state = Secret.Decrypt3DES_UTF8(result.state, GlobalStaticObj_YT.KeySecurity_YT);
            if (state == "F")
            {
                string errMsg = Secret.Decrypt3DES_UTF8(result.errorMsg, GlobalStaticObj_YT.KeySecurity_YT);
                //Utility.Log.Log.writeLineToLog("【联系人信息同步】" + errMsg, "接口");
                GlobalStaticObj_Server.YTInterfaceLogService.WriteLog("联系人信息同步", errMsg);
                return "联系人调用接口失败!";
            }
            QueryContact.contact[] contactArr = result.Details;
            //if (contactArr.Length == 0)
            //{
            //    return "";
            //}
            contactArr = WebServUtil.DesList<QueryContact.contact>(contactArr);
            //bool flag = SaveContact(contactArr);
            bool flag = true;
            int updateCount = 0;
            int totalCount = 0;
            switch (Secret.Decrypt3DES_UTF8(contType, GlobalStaticObj_YT.KeySecurity_YT))
            {
                case "01":
                    flag = SaveContactNotBatch(contactArr, ref updateCount);
                    totalCount = int.Parse(DBHelper.GetSingleValue("", GlobalStaticObj_Server.DbPrefix + GlobalStaticObj_Server.Instance.MainAccCode, "select COUNT(1) from tb_contacts where data_source='2'"));
                    break;
                case "02":
                    flag = SaveUserNotBatch(contactArr, ref updateCount);
                    totalCount = int.Parse(DBHelper.GetSingleValue("", GlobalStaticObj_Server.DbPrefix + GlobalStaticObj_Server.Instance.MainAccCode, "select COUNT(1) from sys_user where data_sources='2'"));
                    break;
            }
            if (!flag)
            {
                GlobalStaticObj_Server.YTInterfaceLogService.WriteLog("联系人信息同步", "联系人更新失败");
                return "联系人更新失败";
            }
            DateTime dtEnd = GlobalStaticObj_Server.Instance.CurrentDateTime;//结束时间
            WebServUtil.WriteInterficeSync(DataSources.EnumInterfaceType.Contact, DataSources.EnumExternalSys.YTCRM, totalCount, updateCount, GlobalStaticObj_Server.Instance.CurrentDateTime);
            WebServUtil.WriteInterficeSyncLog(DataSources.EnumInterfaceType.Contact, DataSources.EnumExternalSys.YTCRM, DataSources.EnumSyncDirection.DownLoad, "tb_contacts", dtStart, dtEnd, updateCount, message);

            return ""; ;
        }