ComplianceServer/oldcode/WebHelper/Phone.cs

267 lines
9.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

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.

namespace WX.CRM.WebHelper
{
public class Phone
{
/// <summary>
/// 得到用户的电话信息
/// </summary>
/// <param name="callState">通话类别 0 为呼入, 1 为呼出</param>
/// <param name="caller">主叫号码</param>
/// <param name="called">被叫类别</param>
/// <returns></returns>
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);
//}
/// <summary>
/// 返回电话号码处理结果
/// </summary>
/// <param name="phone">电话号码</param>
/// <returns>[0] 为区号 [1]为电话号码  [0]="" 为手机号码</returns>
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;
}
/// <summary>
/// 将电话号码做部分隐藏
/// </summary>
/// <param name="phoneNumber">电话号码</param>
/// <param name="length">需要隐藏的长度</param>
/// <param name="start">起始位置(从右边数)</param>
/// <param name="replaceStr">替换字符</param>
/// <returns></returns>
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;
}
/// <summary>
/// 隐藏部分电话号码采用 * 号
/// </summary>
/// <param name="phoneNumber">电话号码</param>
/// <param name="length">隐藏长度</param>
/// <param name="start">起始位置(从右边数)</param>
/// <returns></returns>
public static string EncryptPhoneNumber(string phoneNumber, int length, int start)
{
return EncryptPhoneNumber(phoneNumber, length, start, '*');
}
/// <summary>
/// 隐藏部分电话号码,隐藏四位,采用 * 号
/// </summary>
/// <param name="phoneNumber">电话号码</param>
/// <param name="start">起始位置(从右边数)</param>
/// <returns></returns>
public static string EncryptPhoneNumber(string phoneNumber, int start)
{
return EncryptPhoneNumber(phoneNumber, 4, start, '*');
}
/// <summary>
/// 隐藏部分电话号码,隐藏四位,从右边数两位,之后采用 * 号隐藏
/// </summary>
/// <param name="phoneNumber"></param>
/// <returns></returns>
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;
/// <summary>
/// 去除特殊符号,取的正式号码
/// </summary>
/// <param name="phone"></param>
/// <returns></returns>
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;
}
}
/// <summary>
/// 电话号码接口
/// 设置区号,可以给指定的座机号码加入本地的区号。
/// 若区号和替换号码设置成一致,将导致座机号码没有区号
/// 若区号和替换号码不一致,将先增加区号,然后在替换需要替换的号码
/// </summary>
public interface IPhone
{
/// <summary>
/// 区号
/// </summary>
string AZone
{
get;
}
/// <summary>
/// 需要替换的区号
/// </summary>
string ReplaceString
{
get;
}
string ReplaceZone(WX.CRM.Model.Enum.EnumPhoneType type, string phoneNumber);
}
}