relay send message to offline user - communicator 2007
发布日期:2021-08-16 15:55:32 浏览次数:5 分类:技术文章

本文共 1954 字,大约阅读时间需要 6 分钟。

用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.com);
                contactArray.Add(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.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();
                }

 

转载于:https://www.cnblogs.com/sdikerdong/archive/2012/03/18/2404938.html

转载地址:https://blog.csdn.net/weixin_30810239/article/details/98588720 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Dubbo源码分析:设计总结
下一篇:SpringBoot的服务入门(Get、Post)

发表评论

最新留言

逛到本站,mark一下
[***.202.152.39]2024年04月12日 17时11分10秒