Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public class WxMaKefuMessage implements Serializable {
@SerializedName("miniprogrampage")
private KfMaPage maPage;

@SerializedName("aimsgcontext")
private AiMsgContext aiMsgContext;

@Data
@AllArgsConstructor
@NoArgsConstructor
Expand Down Expand Up @@ -90,6 +93,16 @@ public static class KfMaPage implements Serializable {
private String thumbMediaId;
}

@Data
@AllArgsConstructor
@NoArgsConstructor
public static class AiMsgContext implements Serializable {
private static final long serialVersionUID = 1L;

@SerializedName("msgid")
private String msgId;
}

/**
* 获得文本消息builder.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,30 @@
public class BaseBuilder<T> {
protected String msgType;
protected String toUser;
protected String aiMsgContextMsgId;

@SuppressWarnings("unchecked")
public T toUser(String toUser) {
this.toUser = toUser;
return (T) this;
}

@SuppressWarnings("unchecked")
public T aiMsgContextMsgId(String msgId) {
this.aiMsgContextMsgId = msgId;
return (T) this;
}

/**
* 构造器方法.
*/
public WxMaKefuMessage build() {
WxMaKefuMessage m = new WxMaKefuMessage();
m.setMsgType(this.msgType);
m.setToUser(this.toUser);
if (this.aiMsgContextMsgId != null) {
m.setAiMsgContext(new WxMaKefuMessage.AiMsgContext(this.aiMsgContextMsgId));
}
return m;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,14 @@ public void testURLEscaped() {
"\"link\":{\"title\":\"title\",\"description\":\"description\",\"url\":\"https://mp.weixin.qq.com/s?__biz=MzI0MDA2OTY5NQ==\",\"thumb_url\":\"thumbUrl\"}}");
}

public void testTextBuilderWithAiMsgContext() {
WxMaKefuMessage reply = WxMaKefuMessage.newTextBuilder()
.toUser("OPENID")
.content("回复内容")
.aiMsgContextMsgId("MSG_ID_123")
.build();
assertThat(reply.toJson())
.isEqualTo("{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"回复内容\"},\"aimsgcontext\":{\"msgid\":\"MSG_ID_123\"}}");
}

}