服务端发送消息给用户或者聊天室
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有人遇到过吗,请大神指教
.getAPIFactory();
SendMessageAPI message = (SendMessageAPI)factory.newInstance(EasemobRestAPIFactory.SEND_MESSAGE_CLASS);
Map
Map
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有人遇到过吗,请大神指教
没有找到相关结果
已邀请:
6 个回复
好运来
JSONObject json = JSONObject();
json.put("type", "cmd");
json.put("action","action1");
json.put("username", username);
json.put("zan", 1);
String msg = json.toString(); 也不可以
lizg - ……
lizg - ……
好运来
lizg - ……
[已注销]