下面是构造一个虚设SIP NOTIFY请求可被发送到一个思科IP电话(仅与Cisco 7960测试),使该可视消息等待指示器被设置和取消一些粗代码。
您需要将sip:[email protected]更改为思科手机可识别的SIP URI。当然也可以根据需要调整IP地址和端口。
更新:更新了代码示例,使其在SIP请求中需要进入的IP地址更清晰一些。
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Cisco MWI Test Console:");
string setMWIRequest =
"NOTIFY {0} SIP/2.0\r\n" +
"Via: SIP/2.0/UDP {1}:{2};branch=z9hG4bK{3}\r\n" +
"To: <{0}>\r\n" +
"From: <{0}>\r\n" +
"Call-ID: {4}\r\n" +
"CSeq: 1 NOTIFY\r\n" +
"Max-Forwards: 70\r\n" +
"Contact: {1}:{2}\r\n" +
"Content-Length: {5}\r\n" +
"Content-Type: application/simple-message-summary\r\n" +
"Event: message-summary\r\n" +
"\r\n" +
"{6}";
string mwiBody = "Messages-Waiting: no"; // Change to no to unset MWI.
var localSIPEP = new IPEndPoint(IPAddress.Parse("192.168.33.116"), 5091);
Socket udpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
udpSocket.Bind(localSIPEP);
setMWIRequest = String.Format(setMWIRequest, "sip:[email protected]", localSIPEP.Address.ToString(), localSIPEP.Port, Guid.NewGuid().ToString().Replace("-", ""), Guid.NewGuid().ToString().Replace("-", ""), mwiBody.Length, mwiBody);
byte[] buffer = Encoding.UTF8.GetBytes(setMWIRequest);
Console.WriteLine("Sending to Cisco:");
Console.WriteLine(setMWIRequest);
udpSocket.SendTo(buffer, new IPEndPoint(IPAddress.Parse("192.168.33.155"), 5060));
byte[] recvBuffer = new byte[4096];
int bytesRead = udpSocket.Receive(recvBuffer);
Console.WriteLine(Encoding.UTF8.GetString(recvBuffer.Take(bytesRead).ToArray()));
Console.ReadLine();
}
}
您可以通过向手机发送SIP NOTIFY请求来完成此操作。如果这就是你想要的,我可以提供一个如何在代码中完成的例子。 – sipwiz
是的。对我来说这是OKEY。其实我更喜欢SIP消息而不是自定义思科API。 –