relay send message to offline user - communicator 2007
用OC如何像QQ一样发送离线消息呢?今天学习了一整天,有一点结果。最简单的方法是用OC Auamation API. 下述是伪代码,只用来表示如果使用automation API实现。
//在调用前,oc客户端要被运行起来,可能没有登录
CommunicatorAPI.MessengerClass communicatorObj = new CommunicatorAPI.MessengerClass();
if (communicatorObj.MyStatus != MISTATUS.MISTATUS_OFFLINE)
{
//If already signed in, then set connected status to true and return.
connected = true; // Set the connected status to true.
}
else
{
try
{
//communicatorObj.Signin();
communicatorObj.AutoSignin(); //如果自动登录,用gpedit可以设定
}
catch { }
}
//方法一:
//load selected contacts into ArrayList.
ArrayList contactArray = new ArrayList() ;
contactArray.Add(a@a.com);
contactArray.Add(b@a.com);
//dimension object array to the number of contacts selected
object[] sipUris = new object[contactArray.Count];
int currentObject = 0;
//iterate over contactArray and load each individual
//contact into object array element.
foreach (object contactObject in contactArray)
{
sipUris[currentObject] = contactObject;
currentObject ++;
}
//communicatorObj.OnIMWindowCreated += new DMessengerEvents_OnIMWindowCreatedEventHandler(communicatorObj_OnIMWindowCreated);
CommunicatorAPI.IMessengerAdvanced msgrAdv = communicatorObj as CommunicatorAPI.IMessengerAdvanced;
object obj = msgrAdv .StartConversation(CONVERSATION_TYPE.CONVERSATION_TYPE_IM,sipUris,null,"Notify","1",null) ;
long imWindowHandle = long.Parse(obj.ToString());
if (null != imWindowHandle)
{
IMessengerConversationWndAdvanced IM_Window2 = obj as IMessengerConversationWndAdvanced;
IM_Window2.SendText("hi");
IM_Window2.Show();
}
//方法二
string sipuri = "a@a.com";
IMessengerContactAdvanced contact = FindContact(sipuri);
if (contact.Status == MISTATUS.MISTATUS_OFFLINE)
{
return;
}
IMessengerConversationWndAdvanced IM_Window = communicatorObj.InstantMessage((object)sipuri) as IMessengerConversationWndAdvanced;
if (IM_Window != null)
{
IM_Window.SendText("hello");
IM_Window.Show();
}