发送消息

发送对象

一条消息的发送对象可以是单个用户或多个用户,请注意Java和.Net的常量和调用函数是不同的。

单个用户

对象 具体参数 类型 是否必须 描述
PersonMessageReceiver loginId String 登录Id
name String 用户名

Java

    SendMessageResult result = messageClient.sendSingleMessage(
            new TextMessageContent("简单文本消息"), 
            new PersonMessageReceiver("zhongt", "钟涛"));

.Net


    SendMessageResult result = messageClient.SendSingleMessage(
            new TextMessageContent("简单文本消息"), 
            new PersonMessageReceiver("zhongt", "钟涛"));

多个用户

对象 具体参数 类型 是否必须 描述
MultiMessageReceiver PersonMessageReceiver Object 消息的接收者
PersonMessageReceiverIdType Object 区分接收者的id类型,是登录id还是用户id
PersonMessageReceiver loginId / userId String 登录id或用户id
name String 用户名
PersonMessageReceiverIdType USER_ID (JAVA)
UserId (.Net)
常量 用户id类型
LOGIN_ID (JAVA)
LoginId (.Net)
常量 登录id类型

Java


    List<PersonMessageReceiver> personMessageReceivers = new ArrayList<PersonMessageReceiver>();
    personMessageReceivers.add(new PersonMessageReceiver("zhongt", "钟涛"));
    personMessageReceivers.add(new PersonMessageReceiver("wuyang", "武扬"));
    MultiMessageReceiver multiMessageReceiver = new MultiMessageReceiver(personMessageReceivers, PersonMessageReceiverIdType.LOGIN_ID);
    SendMessageResult result = messageClient.sendMultiMessage(new TextMessageContent("简单文本消息"), multiMessageReceiver);

.Net

    List<PersonMessageReceiver> personMessageReceivers = new List<PersonMessageReceiver>
    {
        new PersonMessageReceiver("zhongt", "钟涛"),
        new PersonMessageReceiver("wuyang", "武扬")
    };
    MultiMessageReceiver multiMessageReceiver = new MultiMessageReceiver(personMessageReceivers, PersonMessageReceiverIdType.LoginId);
    SendMessageResult result = messageClient.SendMultiMessage(new TextMessageContent("简单文本消息"), multiMessageReceiver);
上一篇:服务号消息 下一篇:接收消息