注册

服务端发送消息给用户或者聊天室

EasemobRestAPIFactory factory = ClientContext.getInstance().init(ClientContext.INIT_FROM_PROPERTIES)
                .getAPIFactory();
        SendMessageAPI message = (SendMessageAPI)factory.newInstance(EasemobRestAPIFactory.SEND_MESSAGE_CLASS);
        Map ext = new HashMap(); 
        Map msg = new HashMap();
        ext.put("time", "0000xxxxx0000xxxx");
        msg.put("type", "text");
        msg.put("msg", "hello 环信");
        TextMessageBody tmb = new TextMessageBody("users", new String[]{"1468836748307"}, "admin", ext, JSON.toJSONString(msg));
        TextMessageBody tmb2 = new TextMessageBody("chatrooms", new String[]{"220159378467062200","220163128963367352"}, "admin", ext, JSON.toJSONString(msg));
        ResponseWrapper rw = (ResponseWrapper)message.sendMessage(tmb); 
        ResponseWrapper rw2 = (ResponseWrapper)message.sendMessage(tmb2); 
        System.out.println(rw.getResponseStatus());
        System.out.println(rw2.getResponseStatus());
 
 
环信返回:
Status: 400 Response Body: {"error":"illegal_argument","timestamp":1468914122601,"duration":0,"exception":"java.lang.IllegalArgumentException","error_description":"msg must be JSONObject"}
 
Status: 400 Response Body: {"error":"illegal_argument","timestamp":1468914122212,"duration":0,"exception":"java.lang.IllegalArgumentException","error_description":"msg must be JSONObject"}
 
1.环信配置正确,可以创建用户
2: 消息发送后,都是失败的,都是返回400有人遇到过吗,请大神指教
 
 
已邀请:
打印出来是json格式的,而且我用
        JSONObject json = JSONObject();
        json.put("type", "cmd");
        json.put("action","action1");
        json.put("username", username);
        json.put("zan", 1);
        String msg = json.toString(); 也不可以

lizg - ……

必须是json格式的,检查一下

lizg - ……

@好运来  QQ留一个,加你看下
946866718我的QQ号
发送消息请求体使用json去发送

 

要回复问题请先登录注册