C#从SIP地址获取电话
我正在使用LyncClient库创建一个小部件,当外部传入呼叫时,远程参与者有时会显示为“sip:emailaddress@domain'如果联系人位于用户outlook联系人中 想知道是否有一种方法或库允许我打开该电子邮件地址的联系卡,然后获取电话号码(如果有)C#从SIP地址获取电话,c#,sip,lync-client-sdk,C#,Sip,Lync Client Sdk,我正在使用LyncClient库创建一个小部件,当外部传入呼叫时,远程参与者有时会显示为“sip:emailaddress@domain'如果联系人位于用户outlook联系人中 想知道是否有一种方法或库允许我打开该电子邮件地址的联系卡,然后获取电话号码(如果有) 我一直在拉我的头发,但现在想不出来了。任何提示或经验(好的和坏的)都会很棒!如果你们需要更多信息,请告诉我。我认为这不是电子邮件地址 SIP URI的格式与电子邮件地址相同:SIP:username@sipdomain,因此Lync可
我一直在拉我的头发,但现在想不出来了。任何提示或经验(好的和坏的)都会很棒!如果你们需要更多信息,请告诉我。我认为这不是电子邮件地址 SIP URI的格式与电子邮件地址相同:SIP:username@sipdomain,因此Lync可能只是发送对等sip地址 在这种情况下,您只需获取“sip:”和“@”之间的子字符串即可获得呼叫者id
另一个问题是SIP有多种方式发送呼叫者id。也许您应该查找断言/首选标识(Lync只是从SIP“联系人”标题中提取它)。我制作了一个程序,从SIP URL中获取电话地址。 SIP Url基本上采用这种格式(不带引号):“SIP:username@domain"
试试看
{
LyncClient LyncClient=LyncClient.GetClient();
接触;
列表端点=新列表();
字典电话号码=新字典();
contact=lyncClient.ContactManager.GetContactByUri(“sip:myusername@domain.com“”;//在此处传递SIP地址
var电话号码=(列表)contact.GetContactInformation(ContactInformationType.ContactEndpoints);
//var contactName=contact.GetContactInformation(ContactInformationType.DisplayName).ToString();
//var availability=contact.GetContactInformation(ContactInformationType.Activity).ToString();
//foreach(电话号码中的对象端点)
//{
//Console.WriteLine(((ContactEndpoint)endPoint.DisplayName++)((ContactEndpoint)endPoint.Type.ToString());
//}
端点=电话号码。其中(N=>((ContactEndpoint)N)。类型==ContactEndpointType.HomePhone | |((ContactEndpoint)N)。类型==ContactEndpointType.MobilePhone | |((ContactEndpoint)N)。类型==ContactEndpointType.WorkPhone)。ToList();
foreach(端点中的var端点)
{
//Console.WriteLine(((ContactEndpoint)test.DisplayName.ToString());
string numberType=Regex.Replace(((ContactEndpoint)endPoint).Type.ToString(),@“Phone”,“”);
//字符串编号=Regex.Replace(((ContactEndpoint)endPoint.DisplayName.ToString(),@“[^0-9]”,“”);
字符串编号=”;
//仅带破折号的数字
if(Regex.IsMatch(((ContactEndpoint)endPoint.DisplayName.ToString(),@“^\d{3}-\d{3}-\d{4}$”)
{
number=((ContactEndpoint)endPoint.DisplayName.ToString();
尝试
{
添加(numberType,number);
}
抓住
{
}
}
//Console.WriteLine(numberType+“”+数字);
}
foreach(PhoneNumber中的var条目)
{
//entry.Key是电话类型
//输入。值是电话号码
}
}
捕获(例外情况除外)
{
MessageBox.Show(“出现错误:“+ex.Message”);
}
这肯定是我与网络团队交谈时的电子邮件地址。所以我的主要问题是,我有什么选择来确定SIP地址在哪张卡上,并获得卡上的其他详细信息emailaddress@domain如果它存在于我们的数据库中,那么我的应用程序将完成它的任务。这很好,但是如果emailaddress@domain是在一张卡片上。请随意玩转评论,他们会给你更多关于sip联系人的信息。当我回到项目中时,我们将再次讨论这个问题。但在此期间,我只是检查了数据库的电子邮件地址以及。因此,如果一个客户机打电话来,它产生了sip:email@domain如果我们发现它,我们会通知接收者,否则什么也没有。但是我也要试着弄到电话号码,这样我们也可以检查一下。我会让你知道事情的进展。是否为公司完成了side/MVP项目。希望不久能有一些停机时间。
try
{
LyncClient lyncClient = LyncClient.GetClient();
Contact contact;
List<object> endPoints = new List<object>();
Dictionary<string, string> phoneNumbers = new Dictionary<string, string>();
contact = lyncClient.ContactManager.GetContactByUri("sip:myusername@domain.com"); //PASS THE SIP ADDRESS HERE
var telephoneNumber = (List<object>)contact.GetContactInformation(ContactInformationType.ContactEndpoints);
//var contactName = contact.GetContactInformation(ContactInformationType.DisplayName).ToString();
//var availability = contact.GetContactInformation(ContactInformationType.Activity).ToString();
//foreach (object endPoint in telephoneNumber)
//{
//Console.WriteLine(((ContactEndpoint)endPoint).DisplayName + " " + ((ContactEndpoint)endPoint).Type.ToString());
//}
endPoints = telephoneNumber.Where<object>(N => ((ContactEndpoint)N).Type == ContactEndpointType.HomePhone || ((ContactEndpoint)N).Type == ContactEndpointType.MobilePhone || ((ContactEndpoint)N).Type == ContactEndpointType.OtherPhone || ((ContactEndpoint)N).Type == ContactEndpointType.WorkPhone).ToList<object>();
foreach (var endPoint in endPoints)
{
//Console.WriteLine(((ContactEndpoint)test).DisplayName.ToString());
string numberType = Regex.Replace(((ContactEndpoint)endPoint).Type.ToString(), @"Phone", "");
//string number = Regex.Replace(((ContactEndpoint)endPoint).DisplayName.ToString(), @"[^0-9]", "");
string number = "";
//Numbers only with dashes
if (Regex.IsMatch(((ContactEndpoint)endPoint).DisplayName.ToString(), @"^\d{3}-\d{3}-\d{4}$"))
{
number = ((ContactEndpoint)endPoint).DisplayName.ToString();
try
{
phoneNumbers.Add(numberType, number);
}
catch
{
}
}
//Console.WriteLine(numberType + " " + number);
}
foreach (var entry in phoneNumbers)
{
//entry.Key is the PhoneType
//entry.Value is the Phone Number
}
}
catch (Exception ex)
{
MessageBox.Show("An error occurred: " + ex.Message);
}