mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-02-16 21:36:27 +08:00
添加对发送模板消息的单元测试
This commit is contained in:
@@ -257,9 +257,8 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
@Override
|
||||
public String templateSend(WxMpTemplateMessage templateMessage) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/message/template/send";
|
||||
String responseContent = execute(new SimplePostRequestExecutor(), url, templateMessage.toJson());
|
||||
JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent);
|
||||
final JsonObject jsonObject = tmpJsonElement.getAsJsonObject();
|
||||
String responseContent = this.post(url, templateMessage.toJson());
|
||||
final JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
|
||||
if (jsonObject.get("errcode").getAsInt() == 0){
|
||||
return jsonObject.get("msgid").getAsString();
|
||||
}
|
||||
|
||||
@@ -7,9 +7,6 @@ import java.io.Serializable;
|
||||
*/
|
||||
public class WxMpTemplateData implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 6301835292940277870L;
|
||||
private String name;
|
||||
private String value;
|
||||
@@ -48,6 +45,7 @@ public class WxMpTemplateData implements Serializable {
|
||||
public String getColor() {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
public void setColor(String color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
package me.chanjar.weixin.mp.bean;
|
||||
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WxMpTemplateMessage implements Serializable {
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class WxMpTemplateMessage implements Serializable {
|
||||
private static final long serialVersionUID = 5063374783759519418L;
|
||||
|
||||
private String toUser;
|
||||
private String templateId;
|
||||
private String url;
|
||||
@@ -65,4 +62,61 @@ public class WxMpTemplateMessage implements Serializable {
|
||||
public String toJson() {
|
||||
return WxMpGsonBuilder.INSTANCE.create().toJson(this);
|
||||
}
|
||||
|
||||
public static WxMpTemplateMessageBuilder builder() {
|
||||
return new WxMpTemplateMessageBuilder();
|
||||
}
|
||||
|
||||
public static class WxMpTemplateMessageBuilder {
|
||||
private String toUser;
|
||||
private String templateId;
|
||||
private String url;
|
||||
private String topColor;
|
||||
private List<WxMpTemplateData> data = new ArrayList<>();
|
||||
|
||||
public WxMpTemplateMessageBuilder toUser(String toUser) {
|
||||
this.toUser = toUser;
|
||||
return this;
|
||||
}
|
||||
|
||||
public WxMpTemplateMessageBuilder templateId(String templateId) {
|
||||
this.templateId = templateId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public WxMpTemplateMessageBuilder url(String url) {
|
||||
this.url = url;
|
||||
return this;
|
||||
}
|
||||
|
||||
public WxMpTemplateMessageBuilder topColor(String topColor) {
|
||||
this.topColor = topColor;
|
||||
return this;
|
||||
}
|
||||
|
||||
public WxMpTemplateMessageBuilder data(List<WxMpTemplateData> data) {
|
||||
this.data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
public WxMpTemplateMessageBuilder from(WxMpTemplateMessage origin) {
|
||||
this.toUser(origin.toUser);
|
||||
this.templateId(origin.templateId);
|
||||
this.url(origin.url);
|
||||
this.topColor(origin.topColor);
|
||||
this.data(origin.data);
|
||||
return this;
|
||||
}
|
||||
|
||||
public WxMpTemplateMessage build() {
|
||||
WxMpTemplateMessage m = new WxMpTemplateMessage();
|
||||
m.toUser = this.toUser;
|
||||
m.templateId = this.templateId;
|
||||
m.url = this.url;
|
||||
m.topColor = this.topColor;
|
||||
m.data = this.data;
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user