添加富通知消息的发送测试
This commit is contained in:
+19
@@ -0,0 +1,19 @@
|
||||
package cn.wildfirechat.messagecontentbuilder;
|
||||
|
||||
import cn.wildfirechat.pojos.MessagePayload;
|
||||
|
||||
abstract public class MediaMessageContentBuilder extends MessageContentBuilder{
|
||||
private String remoteMediaUrl;
|
||||
|
||||
public MediaMessageContentBuilder remoteMediaUrl(String remoteMediaUrl) {
|
||||
this.remoteMediaUrl = remoteMediaUrl;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MessagePayload encodeBase() {
|
||||
MessagePayload payload = super.encodeBase();
|
||||
payload.setRemoteMediaUrl(remoteMediaUrl);
|
||||
return payload;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package cn.wildfirechat.messagecontentbuilder;
|
||||
|
||||
import cn.wildfirechat.pojos.MessagePayload;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class MessageContentBuilder {
|
||||
private int mentionedType;
|
||||
private List<String> mentionedTargets;
|
||||
private String extra;
|
||||
public MessageContentBuilder mentionedType(int mentionedType) {
|
||||
this.mentionedType = mentionedType;
|
||||
return this;
|
||||
}
|
||||
public MessageContentBuilder mentionedTargets(List<String> mentionedTargets) {
|
||||
this.mentionedTargets = mentionedTargets;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MessageContentBuilder extra(String extra) {
|
||||
this.extra = extra;
|
||||
return this;
|
||||
}
|
||||
|
||||
protected MessagePayload encodeBase() {
|
||||
MessagePayload payload = new MessagePayload();
|
||||
payload.setMentionedType(mentionedType);
|
||||
payload.setMentionedTarget(mentionedTargets);
|
||||
payload.setExtra(extra);
|
||||
return payload;
|
||||
}
|
||||
abstract public MessagePayload build();
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
package cn.wildfirechat.messagecontentbuilder;
|
||||
|
||||
import cn.wildfirechat.pojos.MessagePayload;
|
||||
import cn.wildfirechat.proto.ProtoConstants;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
|
||||
public class RichNotificationContentBuilder extends MessageContentBuilder{
|
||||
private String title;
|
||||
private String desc;
|
||||
private String remark;
|
||||
private JSONArray datas;
|
||||
private String exName;
|
||||
private String exPortrait;
|
||||
private String exUrl;
|
||||
private String appId;
|
||||
|
||||
public static RichNotificationContentBuilder newBuilder(String title, String desc, String exUrl) {
|
||||
RichNotificationContentBuilder builder = new RichNotificationContentBuilder();
|
||||
builder.title = title;
|
||||
builder.desc = desc;
|
||||
builder.exUrl = exUrl;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public RichNotificationContentBuilder remark(String remark) {
|
||||
this.remark = remark;
|
||||
return this;
|
||||
}
|
||||
public RichNotificationContentBuilder exName(String exName) {
|
||||
this.exName = exName;
|
||||
return this;
|
||||
}
|
||||
public RichNotificationContentBuilder exPortrait(String exPortrait) {
|
||||
this.exPortrait = exPortrait;
|
||||
return this;
|
||||
}
|
||||
public RichNotificationContentBuilder appId(String appId) {
|
||||
this.appId = appId;
|
||||
return this;
|
||||
}
|
||||
public RichNotificationContentBuilder addItem(String key, String value) {
|
||||
return addItem(key, value, null);
|
||||
}
|
||||
public RichNotificationContentBuilder addItem(String key, String value, String color) {
|
||||
if(this.datas == null) {
|
||||
this.datas = new JSONArray();
|
||||
}
|
||||
JSONObject item = new JSONObject();
|
||||
item.put("key", key);
|
||||
item.put("value", value);
|
||||
if(!StringUtil.isNullOrEmpty(color)) {
|
||||
item.put("color", color);
|
||||
}
|
||||
this.datas.add(item);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessagePayload build() {
|
||||
MessagePayload payload = encodeBase();
|
||||
payload.setType(ProtoConstants.ContentType.Rich_Notification);
|
||||
payload.setPersistFlag(ProtoConstants.PersistFlag.Persist_And_Count);
|
||||
payload.setPushContent(title);
|
||||
payload.setContent(desc);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
if(!StringUtil.isNullOrEmpty(remark))
|
||||
jsonObject.put("remark", remark);
|
||||
if(!StringUtil.isNullOrEmpty(exName))
|
||||
jsonObject.put("exName", exName);
|
||||
if(!StringUtil.isNullOrEmpty(exPortrait))
|
||||
jsonObject.put("exPortrait", exPortrait);
|
||||
if(!StringUtil.isNullOrEmpty(exUrl))
|
||||
jsonObject.put("exUrl", exUrl);
|
||||
if(!StringUtil.isNullOrEmpty(appId))
|
||||
jsonObject.put("appId", appId);
|
||||
if(datas != null && !datas.isEmpty())
|
||||
jsonObject.put("datas", datas);
|
||||
|
||||
payload.setBase64edData(Base64.getEncoder().encodeToString(jsonObject.toJSONString().getBytes(StandardCharsets.UTF_8)));
|
||||
|
||||
return payload;
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package cn.wildfirechat.messagecontentbuilder;
|
||||
|
||||
import cn.wildfirechat.pojos.MessagePayload;
|
||||
import cn.wildfirechat.proto.ProtoConstants;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class SoundMessageContentBuilder extends MediaMessageContentBuilder {
|
||||
private int duration;
|
||||
public static SoundMessageContentBuilder newBuilder(int duration) {
|
||||
SoundMessageContentBuilder builder = new SoundMessageContentBuilder();
|
||||
builder.duration = duration;
|
||||
return builder;
|
||||
}
|
||||
@Override
|
||||
public MessagePayload build() {
|
||||
MessagePayload payload = encodeBase();
|
||||
payload.setType(ProtoConstants.ContentType.Voice);
|
||||
payload.setMediaType(ProtoConstants.MessageMediaType.VOICE);
|
||||
payload.setPersistFlag(ProtoConstants.PersistFlag.Persist_And_Count);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("duration", duration);
|
||||
payload.setContent(jsonObject.toJSONString());
|
||||
return payload;
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package cn.wildfirechat.messagecontentbuilder;
|
||||
|
||||
import cn.wildfirechat.pojos.MessagePayload;
|
||||
import cn.wildfirechat.proto.ProtoConstants;
|
||||
|
||||
public class TextMessageContentBuilder extends MessageContentBuilder{
|
||||
private String text;
|
||||
public static TextMessageContentBuilder newBuilder(String text) {
|
||||
TextMessageContentBuilder builder = new TextMessageContentBuilder();
|
||||
builder.text = text;
|
||||
return builder;
|
||||
}
|
||||
@Override
|
||||
public MessagePayload build() {
|
||||
MessagePayload payload = encodeBase();
|
||||
payload.setType(ProtoConstants.ContentType.Text);
|
||||
payload.setPersistFlag(ProtoConstants.PersistFlag.Persist_And_Count);
|
||||
payload.setSearchableContent(text);
|
||||
return payload;
|
||||
}
|
||||
}
|
||||
@@ -84,7 +84,59 @@ public class ProtoConstants {
|
||||
int File = 5;
|
||||
int Video = 6;
|
||||
int Sticker = 7;
|
||||
int RichMedia = 8;
|
||||
int Link = 8;
|
||||
int P_TEXT = 9;
|
||||
int Name_Card = 10;
|
||||
int Composited = 11;
|
||||
int Rich_Notification = 12;
|
||||
int Enter_Channel_Chat = 71;
|
||||
int Leave_Channel_Chat = 72;
|
||||
int Recall = 80;
|
||||
int Delete = 81;
|
||||
int Tip = 90;
|
||||
int Typing = 91;
|
||||
int Friend_Greeting = 92;
|
||||
int Friend_Added = 93;
|
||||
int PC_Login_Request = 94;
|
||||
int Create_Group = 104;
|
||||
int Add_Group_Member = 105;
|
||||
int Kickoff_Group_Member = 106;
|
||||
int Quit_Group = 107;
|
||||
int Dismiss_Group = 108;
|
||||
int Transfer_Group_Owner = 109;
|
||||
int Change_Group_Name = 110;;
|
||||
int Modify_Group_Alias = 111;
|
||||
int Change_Group_Portrait = 112;
|
||||
int Change_Group_Mute = 113;
|
||||
int Change_Group_JoinType = 114;
|
||||
int Change_Group_PrivateChat = 115;
|
||||
int Change_Group_Searchable = 116;
|
||||
int Set_Group_Manager = 117;
|
||||
int Mute_Group_Member = 118;
|
||||
int Allow_Group_Member = 119;
|
||||
int Kickoff_Group_Member_Visible_Notification = 120;
|
||||
int Quit_Group_Visible_Notification = 121;
|
||||
int Modify_Group_Extra = 122;
|
||||
int Modify_Group_Member_Extra = 123;
|
||||
}
|
||||
|
||||
public interface MessagePersistFlag {
|
||||
int NOT_PERSIST = 0;
|
||||
int PERSIST = 1;
|
||||
int PERSIST_AND_COUNT = 3;
|
||||
int TRANSPARENT = 4;
|
||||
}
|
||||
|
||||
public interface MessageMediaType {
|
||||
int GENERAL = 0;
|
||||
int IMAGE = 1;
|
||||
int VOICE = 2;
|
||||
int VIDEO = 3;
|
||||
int FILE = 4;
|
||||
int PORTRAIT = 5;
|
||||
int FAVORITE = 6;
|
||||
int STICKER = 7;
|
||||
int MOMENTS = 8;
|
||||
}
|
||||
|
||||
//ModifyGroupInfoRequest -> type
|
||||
|
||||
Reference in New Issue
Block a user