Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add example for sending message with image #95

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion emchat-server-java/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<contextName>logback</contextName>

<property name="log.path" value="c:/java-client-log/log.log" />
<property name="log.path" value="/java-client-log/log.log" />

<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<!-- <filter class="com.example.logback.filter.MyFilter" /> -->
Expand Down
55 changes: 54 additions & 1 deletion emchat-server-java/src/test/com/easemob/SendMessageTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.easemob;

import com.easemob.server.example.api.impl.EasemobSendMessage;
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.SerializedName;
import io.swagger.client.model.Msg;
import io.swagger.client.model.MsgContent;
import io.swagger.client.model.UserName;
Expand All @@ -13,7 +15,7 @@ public class SendMessageTest {
private EasemobSendMessage easemobSendMessage = new EasemobSendMessage();

@Test
public void send() {
public void sendText() {
Msg msg = new Msg();
MsgContent msgContent = new MsgContent();
msgContent.type(MsgContent.TypeEnum.TXT).msg("helloword");
Expand All @@ -23,4 +25,55 @@ public void send() {
Object result = easemobSendMessage.sendMessage(msg);
System.out.println(result);
}

@Test
public void sendImage() {
Msg msg = new Msg();
ImageMsgContent msgContent = new ImageMsgContent();
msgContent.url("http://test_url").secret("test_sec").filename("filename").size(new ImageMsgContent.Size(480, 720))
.type(MsgContent.TypeEnum.IMG).msg("this is an image message");
UserName userName = new UserName();
userName.add("receiver");
msg.from("sender").target(userName).targetType("users").msg(msgContent);
System.out.println(new GsonBuilder().create().toJson(msg));
Object result = easemobSendMessage.sendMessage(msg);
System.out.println(result);
}

static class ImageMsgContent extends MsgContent {
private String url;
private String filename;
private String secret;
private Size size;

ImageMsgContent url(String url) {
this.url = url;
return this;
}

ImageMsgContent filename(String filename) {
this.filename = filename;
return this;
}

ImageMsgContent secret(String secret) {
this.secret = secret;
return this;
}

ImageMsgContent size(Size size) {
this.size = size;
return this;
}

static class Size {
private long width;
private long height;

Size(long width, long height) {
this.width = width;
this.height = height;
}
}
}
}