@@ -24,6 +24,7 @@ public class WxMpCustomMessage implements Serializable { | |||||
private String description; | private String description; | ||||
private String musicUrl; | private String musicUrl; | ||||
private String hqMusicUrl; | private String hqMusicUrl; | ||||
private String kfAccount; | |||||
private List<WxArticle> articles = new ArrayList<>(); | private List<WxArticle> articles = new ArrayList<>(); | ||||
public String getToUser() { | public String getToUser() { | ||||
@@ -180,4 +181,12 @@ public class WxMpCustomMessage implements Serializable { | |||||
return new NewsBuilder(); | return new NewsBuilder(); | ||||
} | } | ||||
public String getKfAccount() { | |||||
return kfAccount; | |||||
} | |||||
public void setKfAccount(String kfAccount) { | |||||
this.kfAccount = kfAccount; | |||||
} | |||||
} | } |
@@ -14,6 +14,8 @@ import me.chanjar.weixin.mp.bean.WxMpCustomMessage; | |||||
import java.lang.reflect.Type; | import java.lang.reflect.Type; | ||||
import org.apache.commons.lang3.StringUtils; | |||||
public class WxMpCustomMessageGsonAdapter implements JsonSerializer<WxMpCustomMessage> { | public class WxMpCustomMessageGsonAdapter implements JsonSerializer<WxMpCustomMessage> { | ||||
public JsonElement serialize(WxMpCustomMessage message, Type typeOfSrc, JsonSerializationContext context) { | public JsonElement serialize(WxMpCustomMessage message, Type typeOfSrc, JsonSerializationContext context) { | ||||
@@ -73,6 +75,12 @@ public class WxMpCustomMessageGsonAdapter implements JsonSerializer<WxMpCustomMe | |||||
messageJson.add("news", newsJsonObject); | messageJson.add("news", newsJsonObject); | ||||
} | } | ||||
if (StringUtils.isNotBlank(message.getKfAccount())){ | |||||
JsonObject newsJsonObject = new JsonObject(); | |||||
newsJsonObject.addProperty("kf_account", message.getKfAccount()); | |||||
messageJson.add("customservice", newsJsonObject); | |||||
} | |||||
return messageJson; | return messageJson; | ||||
} | } | ||||
@@ -26,7 +26,18 @@ public class WxMpCustomMessageAPITest { | |||||
message.setToUser(configStorage.getOpenId()); | message.setToUser(configStorage.getOpenId()); | ||||
message.setContent("欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>"); | message.setContent("欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>"); | ||||
wxService.customMessageSend(message); | |||||
this.wxService.customMessageSend(message); | |||||
} | |||||
public void testSendCustomMessageWithKfAccount() throws WxErrorException { | |||||
ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.wxMpConfigStorage; | |||||
WxMpCustomMessage message = new WxMpCustomMessage(); | |||||
message.setMsgType(WxConsts.CUSTOM_MSG_TEXT); | |||||
message.setToUser(configStorage.getOpenId()); | |||||
message.setKfAccount(configStorage.getKfAccount()); | |||||
message.setContent("欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>"); | |||||
this.wxService.customMessageSend(message); | |||||
} | } | ||||
} | } |