|
|
@@ -162,15 +162,28 @@ public class EasemobUtils implements InitializingBean, DisposableBean {
|
|
|
}
|
|
|
|
|
|
public void sendMessage(String from, String to, String msg, Object... value) {
|
|
|
+ sendAsync(new EasemobInfo().uri("/messages").data(buildMessage(from, to, null, String.format(msg, value)))
|
|
|
+ .method(HttpMethod.POST));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void sendMessage(String from, String to, Object ext, String msg, Object... value) {
|
|
|
+ sendAsync(new EasemobInfo().uri("/messages").data(buildMessage(from, to, ext, String.format(msg, value)))
|
|
|
+ .method(HttpMethod.POST));
|
|
|
+ }
|
|
|
+
|
|
|
+ private String buildMessage(String from, String to, Object ext, String msg) {
|
|
|
JSONObject message = new JSONObject();
|
|
|
message.put("type", "txt");
|
|
|
- message.put("msg", String.format(msg, value));
|
|
|
+ message.put("msg", msg);
|
|
|
JSONObject jo = new JSONObject();
|
|
|
jo.put("target_type", "users");
|
|
|
jo.put("target", new String[] { to });
|
|
|
jo.put("msg", message);
|
|
|
jo.put("from", from);
|
|
|
- sendAsync(new EasemobInfo().uri("/messages").data(jo.toJSONString()).method(HttpMethod.POST));
|
|
|
+ if (ext != null) {
|
|
|
+ jo.put("ext", ext);
|
|
|
+ }
|
|
|
+ return jo.toJSONString();
|
|
|
}
|
|
|
|
|
|
private Optional<Integer> getResCode(HttpResponse response) {
|