C# 从 SIP 地址获取电话



我正在使用LyncClient库来创建小部件,当外部呼叫传入时,如果联系人在用户Outlook联系人中,远程参与者有时会显示为"sip:emailaddress@domain"。

想知道是否有一种方法或库可以让我打开该电子邮件地址的联系卡片,然后获取电话号码(如果有(。

揪了好一会儿头发,想不通。任何提示或经验(好的和坏的(都会很棒!如果你们需要更多信息,请告诉我。

我做了一个程序,从SIP URL中获取电话号码。一个 SIP 网址基本上是这样的格式(不带引号(:"sip:username@domain">

    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);
    }

我不认为这是电子邮件地址。

SIP URI的格式与电子邮件地址相同:sip:username@sipdomain,所以也许Lync只是发送对等的sip地址。

在这种情况下,您只需获取"sip:"和"@"之间的子字符串即可获取来电显示。

另一个问题是SIP有多种方式发送主叫方ID。也许您应该查找断言/首选标识(Lync 只是从 SIP"联系人"标头中提取它(。

最新更新