简体   繁体   English

C#从SIP地址获取电话

[英]C# get phone from SIP address

I am using LyncClient library to create a widget and when a call comes in externally the remote participant sometimes comes up as 'sip:emailaddress@domain' if the contact is in the users outlook contacts. 我正在使用LyncClient库创建窗口小部件,并且当外部呼叫时,如果该联系人位于用户Outlook联系人中,则远程参与者有时会显示为“ sip:emailaddress @ domain”。

Wondering if there is a way or library that allows me to open up the contact card for that email address and then get phone numbers if there are any. 想知道是否有一种方法或库可以让我打开该电子邮件地址的联系卡,然后获取电话号码(如果有)。

Been pulling at my hair for a while now and can't figure it out. 现在拉扯我的头发已经有一段时间了,无法弄清。 Any tips or experiences (good and bad) would be great! 任何技巧或经验(好的和坏的)都会很棒! Let me know if you guys need more information. 让我知道你们是否需要更多信息。

I made a program that gets the phone address out of a SIP URL. 我编写了一个程序,用于从SIP URL中获取电话地址。 a SIP Url is basically in this format(Without quotes): "sip:username@domain" 一个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);
    }

I don't think that this is the email address. 我认为这不是电子邮件地址。

SIP URI's has the same format as an email address: sip:username@sipdomain, so maybe Lync is just sending the peer sip address. SIP URI的格式与电子邮件地址相同:sip:username @ sipdomain,因此Lync可能只是发送对等sip地址。

In this case you just have to grab the sub-string between "sip:" and "@" to get the caller id. 在这种情况下,您只需要获取“ sip:”和“ @”之间的子字符串即可获得呼叫者ID。

Another problem is that there are multiple ways for SIP to send the caller id. 另一个问题是SIP有多种发送呼叫方ID的方法。 Maybe you should look for Asserted/Preferred identity (and Lync just extracts it from the SIP "Contact" header). 也许您应该寻找断言/首选身份(Lync只是从SIP“联系人”标头中提取身份)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM