注册

服务端发送消息给用户


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[]{"123456789"}, "admin", ext, JSON.toJSONString(msg));
ResponseWrapper rw = (ResponseWrapper)message.sendMessage(tmb); System.out.println(rw.getResponseStatus());
 
环信返回
Response Body: {"action":"post","application":"7f791f50-e9a8-11e5-bda4-7b1406037610","uri":"https://a1.easemob.com/91430103096041818g/upark","entities":[],"data":{"123456789":"success"},"timestamp":1459318880085,"duration":1,"organization":"91430103096041818g","applicationName":"upark"}
 
 
1.环信配置正确,用下面的接口可以创建用户
 BodyWrapper userBody = new IMUserBody("xxxxxxxx","111111","Coca-Cola");
 
2: 消息发送后 用户123456789应该可以收到,但是收不到。如果  123456789 不存在于app下面那么还是会收到发送成功的消息。
已邀请:
TextMessageBody tmb = new TextMessageBody("users", new String[]{"123456789"}, "admin", new HashMap<String, String>(), JSON.toJSONString(msg));
 
刚看了论坛,已经排除扩展消息问题。还是收不到
TextMessageBody tmb = new TextMessageBody("users", new String[]{"uparkadmin"}, "admin",null, JSON.toJSONString(msg));
这种方式也不行 估计不是扩展消息的问题
官方的demo有点问题,你需要稍微改动一下,
public class TextMessageBody extends MessageBody {
private String msg;

public TextMessageBody(String targetType, String[] targets, String from, Map<String, String> ext, String msg) {
super(targetType, targets, from, ext);
this.msg = msg;
}

public String getMsg() {
return msg;
}

public ContainerNode<?> getBody() {
if(!isInit()){
//这里有改动!
ObjectNode objectNode = this.getMsgBody().putObject("msg");
objectNode.put("type",MsgType.TEXT);
objectNode.put("msg",msg);
this.setInit(true);
}

return this.getMsgBody();
}

public Boolean validate() {
return super.validate() && StringUtils.isNotBlank(msg);
}
}
​还有你要重新换一个账号去测试,用官方的demo发送后就收不到正确的了!
更换一个账号测试?我用的就是admin发送消息,环信后台应该是admin(我猜测)应为没有用户登录。
换用户的话那怎么操作?
 
用你的代码拼装参数回事错误的
Body:
{"target_type":"users","target":["uparkadmin"],"from":"admin","msg":{"type":"txt","msg":"{\"type\":\"text\",\"msg\":\"baidu\"}"}}

要回复问题请先登录注册