mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-04-23 23:58:44 +08:00
发送客服消息接口支持以某个客服的名义发送消息
This commit is contained in:
parent
ff801044c2
commit
b88560d9af
@ -24,6 +24,7 @@ public class WxMpCustomMessage implements Serializable {
|
||||
private String description;
|
||||
private String musicUrl;
|
||||
private String hqMusicUrl;
|
||||
private String kfAccount;
|
||||
private List<WxArticle> articles = new ArrayList<>();
|
||||
|
||||
public String getToUser() {
|
||||
@ -180,4 +181,12 @@ public class WxMpCustomMessage implements Serializable {
|
||||
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 org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class WxMpCustomMessageGsonAdapter implements JsonSerializer<WxMpCustomMessage> {
|
||||
|
||||
public JsonElement serialize(WxMpCustomMessage message, Type typeOfSrc, JsonSerializationContext context) {
|
||||
@ -73,6 +75,12 @@ public class WxMpCustomMessageGsonAdapter implements JsonSerializer<WxMpCustomMe
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,18 @@ public class WxMpCustomMessageAPITest {
|
||||
message.setToUser(configStorage.getOpenId());
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user