namespace WX.CRM.WebHelper { public class Phone { /// /// 得到用户的电话信息 /// /// 通话类别 0 为呼入, 1 为呼出 /// 主叫号码 /// 被叫类别 /// public static string GetUserPhone(int callState, string caller, string called, IPhone iphone) { string userPhone = string.Empty; BasePhone bp = new BasePhone(iphone); if (callState > -1) { if (callState == 0)//电话为呼入 { //string temp = caller.Substring(0, 1); //if (temp == "*") //{ // userPhone = caller.Substring(1);//TODO:据说新版的呼入的时候,都是直接的号码了,不加*号了?确认为真的话,去掉下面的注释 //} //else //{ // userPhone = caller; //} userPhone = bp.GetRealPhone(caller); } else//电话为呼出 { //if (called.Substring(1, 2) == "01")//电话号码为外地手机号 //{ // userPhone = called.Substring(2); //} //else //{ // userPhone = called.Substring(1);//电话号码为座机号 //} userPhone = bp.GetRealPhone(called); } } return userPhone; } //public static string GetUserPhone(TelephoneRecordInfo record, IPhone iphone) //{ // return GetUserPhone(record.CallState, record.CallerID, record.CalledID, iphone); //} /// /// 返回电话号码处理结果 /// /// 电话号码 /// [0] 为区号 [1]为电话号码  [0]="" 为手机号码 public static string[] GetPhoneDetail(string phone) { string[] phoneDetail = new string[2]; phoneDetail[0] = ""; phoneDetail[1] = ""; //Todo: ADD some function to operator the phone return phoneDetail; } /// /// 将电话号码做部分隐藏 /// /// 电话号码 /// 需要隐藏的长度 /// 起始位置(从右边数) /// 替换字符 /// public static string EncryptPhoneNumber(string phoneNumber, int length, int start, char replaceChar) { string result = null; if (phoneNumber == null) phoneNumber = ""; if (phoneNumber.Length < (length + start)) { result = phoneNumber; } else { string before = null; string last = null; before = phoneNumber.Substring(0, phoneNumber.Length - start - length); string replaceStr = new string(replaceChar, length); last = phoneNumber.Substring(phoneNumber.Length - start, start); result = string.Concat(before, replaceStr, last); } return result;//before + replaceStr + last; } /// /// 隐藏部分电话号码采用 * 号 /// /// 电话号码 /// 隐藏长度 /// 起始位置(从右边数) /// public static string EncryptPhoneNumber(string phoneNumber, int length, int start) { return EncryptPhoneNumber(phoneNumber, length, start, '*'); } /// /// 隐藏部分电话号码,隐藏四位,采用 * 号 /// /// 电话号码 /// 起始位置(从右边数) /// public static string EncryptPhoneNumber(string phoneNumber, int start) { return EncryptPhoneNumber(phoneNumber, 4, start, '*'); } /// /// 隐藏部分电话号码,隐藏四位,从右边数两位,之后采用 * 号隐藏 /// /// /// public static string EncryptPhoneNumber(string phoneNumber) { string result = null; if (string.IsNullOrEmpty(phoneNumber)) { return string.Empty; } if (phoneNumber.Length <= 4) { return phoneNumber; } if (phoneNumber.Length < 8) { int totalLength = phoneNumber.Length; string str = new string('*', totalLength - 4); result = string.Concat(str, phoneNumber.Substring(totalLength - 4)); } else { int totalLength = phoneNumber.Length; string str = new string('*', totalLength - 4 - 3); result = string.Concat(phoneNumber.Substring(0, 3), str, phoneNumber.Substring(totalLength - 4)); } return result; } } public class BasePhone { private BasePhone() { } public BasePhone(IPhone telephone) { this.tele = telephone; } private WX.CRM.Model.Enum.EnumPhoneType phoneType; private IPhone tele; private string realPhone; /// /// 去除特殊符号,取的正式号码 /// /// /// private string GetPhone(string phone) { if (phone.StartsWith("*")) { phone = phone.Substring(1);//截取前面的*号 } if (phone.StartsWith("9"))//外拨号码 { phone = phone.Substring(1);//截取前面的出局号9 if (phone.Length == 12 && phone.StartsWith("01"))//外地手机,前面加0 { phone = phone.Substring(1); if (phone.StartsWith("1")) { this.phoneType = WX.CRM.Model.Enum.EnumPhoneType.手机; } return phone; } if (phone.Length == 11 && phone.StartsWith("1"))//本地手机 { this.phoneType = WX.CRM.Model.Enum.EnumPhoneType.手机; return phone; } if (phone.Length <= 12 && phone.StartsWith("0")) { this.phoneType = WX.CRM.Model.Enum.EnumPhoneType.座机; return phone; } if (phone.Length == 8) { this.phoneType = WX.CRM.Model.Enum.EnumPhoneType.座机; return phone; } } else//呼入号码 { if (phone.Length == 12 && phone.StartsWith("01"))//外地手机,前面加0 { phone = phone.Substring(1); this.phoneType = WX.CRM.Model.Enum.EnumPhoneType.手机; return phone; } if (phone.Length == 11 && phone.StartsWith("1"))//本地手机 { this.phoneType = WX.CRM.Model.Enum.EnumPhoneType.手机; return phone; } else { this.phoneType = WX.CRM.Model.Enum.EnumPhoneType.座机; return phone; } } return phone; } public string GetRealPhone(string phone) { this.realPhone = this.GetPhone(phone); string result = realPhone; if (this.phoneType == WX.CRM.Model.Enum.EnumPhoneType.座机) { result = this.tele.ReplaceZone(this.phoneType, this.realPhone); } return result; } } /// /// 电话号码接口 /// 设置区号,可以给指定的座机号码加入本地的区号。 /// 若区号和替换号码设置成一致,将导致座机号码没有区号 /// 若区号和替换号码不一致,将先增加区号,然后在替换需要替换的号码 /// public interface IPhone { /// /// 区号 /// string AZone { get; } /// /// 需要替换的区号 /// string ReplaceString { get; } string ReplaceZone(WX.CRM.Model.Enum.EnumPhoneType type, string phoneNumber); } }