@@ -1,17 +1,12 @@ | |||
package me.chanjar.weixin.mp.api; | |||
import java.io.File; | |||
import java.util.Date; | |||
import me.chanjar.weixin.common.exception.WxErrorException; | |||
import me.chanjar.weixin.mp.bean.WxMpCustomMessage; | |||
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; | |||
import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest; | |||
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfList; | |||
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfMsgList; | |||
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfOnlineList; | |||
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfSessionGetResult; | |||
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfSessionList; | |||
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfSessionWaitCaseList; | |||
import me.chanjar.weixin.mp.bean.kefu.result.*; | |||
import java.io.File; | |||
import java.util.Date; | |||
/** | |||
* 客服接口 , | |||
@@ -29,7 +24,7 @@ public interface WxMpKefuService { | |||
* 详情请见: <a href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140547&token=&lang=zh_CN">发送客服消息</a> | |||
* </pre> | |||
*/ | |||
boolean customMessageSend(WxMpCustomMessage message) throws WxErrorException; | |||
boolean sendKefuMessage(WxMpKefuMessage message) throws WxErrorException; | |||
//*******************客服管理接口***********************// | |||
@@ -3,6 +3,7 @@ package me.chanjar.weixin.mp.api.impl; | |||
import java.io.File; | |||
import java.util.Date; | |||
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
@@ -14,7 +15,6 @@ import me.chanjar.weixin.common.exception.WxErrorException; | |||
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor; | |||
import me.chanjar.weixin.mp.api.WxMpKefuService; | |||
import me.chanjar.weixin.mp.api.WxMpService; | |||
import me.chanjar.weixin.mp.bean.WxMpCustomMessage; | |||
import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest; | |||
import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfSessionRequest; | |||
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfList; | |||
@@ -41,7 +41,7 @@ public class WxMpKefuServiceImpl implements WxMpKefuService { | |||
} | |||
@Override | |||
public boolean customMessageSend(WxMpCustomMessage message) | |||
public boolean sendKefuMessage(WxMpKefuMessage message) | |||
throws WxErrorException { | |||
String url = "https://api.weixin.qq.com/cgi-bin/message/custom/send"; | |||
String responseContent = this.wxMpService.post(url, message.toJson()); | |||
@@ -6,13 +6,13 @@ import me.chanjar.weixin.common.api.WxConsts; | |||
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter; | |||
@XStreamAlias("xml") | |||
public class WxMpXmlOutTransferCustomerServiceMessage extends WxMpXmlOutMessage { | |||
public class WxMpXmlOutTransferKefuMessage extends WxMpXmlOutMessage { | |||
private static final long serialVersionUID = 1850903037285841322L; | |||
@XStreamAlias("TransInfo") | |||
protected TransInfo transInfo; | |||
public WxMpXmlOutTransferCustomerServiceMessage() { | |||
public WxMpXmlOutTransferKefuMessage() { | |||
this.msgType = WxConsts.CUSTOM_MSG_TRANSFER_CUSTOMER_SERVICE; | |||
} | |||
@@ -1,6 +1,6 @@ | |||
package me.chanjar.weixin.mp.bean.custombuilder; | |||
import me.chanjar.weixin.mp.bean.WxMpCustomMessage; | |||
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; | |||
public class BaseBuilder<T> { | |||
protected String msgType; | |||
@@ -11,8 +11,8 @@ public class BaseBuilder<T> { | |||
return (T) this; | |||
} | |||
public WxMpCustomMessage build() { | |||
WxMpCustomMessage m = new WxMpCustomMessage(); | |||
public WxMpKefuMessage build() { | |||
WxMpKefuMessage m = new WxMpKefuMessage(); | |||
m.setMsgType(this.msgType); | |||
m.setToUser(this.toUser); | |||
return m; | |||
@@ -1,12 +1,12 @@ | |||
package me.chanjar.weixin.mp.bean.custombuilder; | |||
import me.chanjar.weixin.common.api.WxConsts; | |||
import me.chanjar.weixin.mp.bean.WxMpCustomMessage; | |||
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; | |||
/** | |||
* 获得消息builder | |||
* <pre> | |||
* 用法: WxMpCustomMessage m = WxMpCustomMessage.IMAGE().mediaId(...).toUser(...).build(); | |||
* 用法: WxMpKefuMessage m = WxMpKefuMessage.IMAGE().mediaId(...).toUser(...).build(); | |||
* </pre> | |||
* @author chanjarster | |||
* | |||
@@ -24,8 +24,8 @@ public final class ImageBuilder extends BaseBuilder<ImageBuilder> { | |||
} | |||
@Override | |||
public WxMpCustomMessage build() { | |||
WxMpCustomMessage m = super.build(); | |||
public WxMpKefuMessage build() { | |||
WxMpKefuMessage m = super.build(); | |||
m.setMediaId(this.mediaId); | |||
return m; | |||
} | |||
@@ -1,12 +1,12 @@ | |||
package me.chanjar.weixin.mp.bean.custombuilder; | |||
import me.chanjar.weixin.common.api.WxConsts; | |||
import me.chanjar.weixin.mp.bean.WxMpCustomMessage; | |||
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; | |||
/** | |||
* 音乐消息builder | |||
* <pre> | |||
* 用法: WxMpCustomMessage m = WxMpCustomMessage.MUSIC() | |||
* 用法: WxMpKefuMessage m = WxMpKefuMessage.MUSIC() | |||
* .musicUrl(...) | |||
* .hqMusicUrl(...) | |||
* .title(...) | |||
@@ -53,8 +53,8 @@ public final class MusicBuilder extends BaseBuilder<MusicBuilder> { | |||
} | |||
@Override | |||
public WxMpCustomMessage build() { | |||
WxMpCustomMessage m = super.build(); | |||
public WxMpKefuMessage build() { | |||
WxMpKefuMessage m = super.build(); | |||
m.setMusicUrl(this.musicUrl); | |||
m.setHqMusicUrl(this.hqMusicUrl); | |||
m.setTitle(this.title); | |||
@@ -1,7 +1,7 @@ | |||
package me.chanjar.weixin.mp.bean.custombuilder; | |||
import me.chanjar.weixin.common.api.WxConsts; | |||
import me.chanjar.weixin.mp.bean.WxMpCustomMessage; | |||
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
@@ -10,27 +10,27 @@ import java.util.List; | |||
* 图文消息builder | |||
* <pre> | |||
* 用法: | |||
* WxMpCustomMessage m = WxMpCustomMessage.NEWS().addArticle(article).toUser(...).build(); | |||
* WxMpKefuMessage m = WxMpKefuMessage.NEWS().addArticle(article).toUser(...).build(); | |||
* </pre> | |||
* @author chanjarster | |||
* | |||
*/ | |||
public final class NewsBuilder extends BaseBuilder<NewsBuilder> { | |||
private List<WxMpCustomMessage.WxArticle> articles = new ArrayList<>(); | |||
private List<WxMpKefuMessage.WxArticle> articles = new ArrayList<>(); | |||
public NewsBuilder() { | |||
this.msgType = WxConsts.CUSTOM_MSG_NEWS; | |||
} | |||
public NewsBuilder addArticle(WxMpCustomMessage.WxArticle article) { | |||
public NewsBuilder addArticle(WxMpKefuMessage.WxArticle article) { | |||
this.articles.add(article); | |||
return this; | |||
} | |||
@Override | |||
public WxMpCustomMessage build() { | |||
WxMpCustomMessage m = super.build(); | |||
public WxMpKefuMessage build() { | |||
WxMpKefuMessage m = super.build(); | |||
m.setArticles(this.articles); | |||
return m; | |||
} | |||
@@ -1,12 +1,12 @@ | |||
package me.chanjar.weixin.mp.bean.custombuilder; | |||
import me.chanjar.weixin.common.api.WxConsts; | |||
import me.chanjar.weixin.mp.bean.WxMpCustomMessage; | |||
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; | |||
/** | |||
* 文本消息builder | |||
* <pre> | |||
* 用法: WxMpCustomMessage m = WxMpCustomMessage.TEXT().content(...).toUser(...).build(); | |||
* 用法: WxMpKefuMessage m = WxMpKefuMessage.TEXT().content(...).toUser(...).build(); | |||
* </pre> | |||
* @author chanjarster | |||
* | |||
@@ -24,8 +24,8 @@ public final class TextBuilder extends BaseBuilder<TextBuilder> { | |||
} | |||
@Override | |||
public WxMpCustomMessage build() { | |||
WxMpCustomMessage m = super.build(); | |||
public WxMpKefuMessage build() { | |||
WxMpKefuMessage m = super.build(); | |||
m.setContent(this.content); | |||
return m; | |||
} | |||
@@ -1,12 +1,12 @@ | |||
package me.chanjar.weixin.mp.bean.custombuilder; | |||
import me.chanjar.weixin.common.api.WxConsts; | |||
import me.chanjar.weixin.mp.bean.WxMpCustomMessage; | |||
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; | |||
/** | |||
* 视频消息builder | |||
* <pre> | |||
* 用法: WxMpCustomMessage m = WxMpCustomMessage.VOICE() | |||
* 用法: WxMpKefuMessage m = WxMpKefuMessage.VOICE() | |||
* .mediaId(...) | |||
* .title(...) | |||
* .thumbMediaId(..) | |||
@@ -48,8 +48,8 @@ public final class VideoBuilder extends BaseBuilder<VideoBuilder> { | |||
} | |||
@Override | |||
public WxMpCustomMessage build() { | |||
WxMpCustomMessage m = super.build(); | |||
public WxMpKefuMessage build() { | |||
WxMpKefuMessage m = super.build(); | |||
m.setMediaId(this.mediaId); | |||
m.setTitle(this.title); | |||
m.setDescription(this.description); | |||
@@ -1,12 +1,12 @@ | |||
package me.chanjar.weixin.mp.bean.custombuilder; | |||
import me.chanjar.weixin.common.api.WxConsts; | |||
import me.chanjar.weixin.mp.bean.WxMpCustomMessage; | |||
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; | |||
/** | |||
* 语音消息builder | |||
* <pre> | |||
* 用法: WxMpCustomMessage m = WxMpCustomMessage.VOICE().mediaId(...).toUser(...).build(); | |||
* 用法: WxMpKefuMessage m = WxMpKefuMessage.VOICE().mediaId(...).toUser(...).build(); | |||
* </pre> | |||
* @author chanjarster | |||
* | |||
@@ -24,8 +24,8 @@ public final class VoiceBuilder extends BaseBuilder<VoiceBuilder> { | |||
} | |||
@Override | |||
public WxMpCustomMessage build() { | |||
WxMpCustomMessage m = super.build(); | |||
public WxMpKefuMessage build() { | |||
WxMpKefuMessage m = super.build(); | |||
m.setMediaId(this.mediaId); | |||
return m; | |||
} | |||
@@ -1,12 +1,12 @@ | |||
package me.chanjar.weixin.mp.bean.custombuilder; | |||
import me.chanjar.weixin.common.api.WxConsts; | |||
import me.chanjar.weixin.mp.bean.WxMpCustomMessage; | |||
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; | |||
/** | |||
* 卡券消息builder | |||
* <pre> | |||
* 用法: WxMpCustomMessage m = WxMpCustomMessage.WXCARD().cardId(...).toUser(...).build(); | |||
* 用法: WxMpKefuMessage m = WxMpKefuMessage.WXCARD().cardId(...).toUser(...).build(); | |||
* </pre> | |||
* @author mgcnrx11 | |||
* | |||
@@ -24,8 +24,8 @@ public final class WxCardBuilder extends BaseBuilder<WxCardBuilder> { | |||
} | |||
@Override | |||
public WxMpCustomMessage build() { | |||
WxMpCustomMessage m = super.build(); | |||
public WxMpKefuMessage build() { | |||
WxMpKefuMessage m = super.build(); | |||
m.setCardId(this.cardId); | |||
return m; | |||
} | |||
@@ -1,24 +1,18 @@ | |||
package me.chanjar.weixin.mp.bean; | |||
package me.chanjar.weixin.mp.bean.kefu; | |||
import me.chanjar.weixin.mp.bean.custombuilder.*; | |||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||
import java.io.Serializable; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import me.chanjar.weixin.mp.bean.custombuilder.ImageBuilder; | |||
import me.chanjar.weixin.mp.bean.custombuilder.MusicBuilder; | |||
import me.chanjar.weixin.mp.bean.custombuilder.NewsBuilder; | |||
import me.chanjar.weixin.mp.bean.custombuilder.TextBuilder; | |||
import me.chanjar.weixin.mp.bean.custombuilder.VideoBuilder; | |||
import me.chanjar.weixin.mp.bean.custombuilder.VoiceBuilder; | |||
import me.chanjar.weixin.mp.bean.custombuilder.WxCardBuilder; | |||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||
/** | |||
* 客服消息 | |||
* @author chanjarster | |||
* | |||
*/ | |||
public class WxMpCustomMessage implements Serializable { | |||
public class WxMpKefuMessage implements Serializable { | |||
private static final long serialVersionUID = -9196732086954365246L; | |||
private String toUser; |
@@ -1,17 +1,17 @@ | |||
package me.chanjar.weixin.mp.bean.outxmlbuilder; | |||
import me.chanjar.weixin.common.util.StringUtils; | |||
import me.chanjar.weixin.mp.bean.WxMpXmlOutTransferCustomerServiceMessage; | |||
import me.chanjar.weixin.mp.bean.WxMpXmlOutTransferKefuMessage; | |||
/** | |||
* 客服消息builder | |||
* <pre> | |||
* 用法: WxMpCustomMessage m = WxMpXmlOutMessage.TRANSFER_CUSTOMER_SERVICE().content(...).toUser(...).build(); | |||
* 用法: WxMpKefuMessage m = WxMpXmlOutMessage.TRANSFER_CUSTOMER_SERVICE().content(...).toUser(...).build(); | |||
* </pre> | |||
* | |||
* @author chanjarster | |||
*/ | |||
public final class TransferCustomerServiceBuilder extends BaseBuilder<TransferCustomerServiceBuilder, WxMpXmlOutTransferCustomerServiceMessage> { | |||
public final class TransferCustomerServiceBuilder extends BaseBuilder<TransferCustomerServiceBuilder, WxMpXmlOutTransferKefuMessage> { | |||
private String kfAccount; | |||
public TransferCustomerServiceBuilder kfAccount(String kf) { | |||
@@ -20,11 +20,11 @@ public final class TransferCustomerServiceBuilder extends BaseBuilder<TransferCu | |||
} | |||
@Override | |||
public WxMpXmlOutTransferCustomerServiceMessage build() { | |||
WxMpXmlOutTransferCustomerServiceMessage m = new WxMpXmlOutTransferCustomerServiceMessage(); | |||
public WxMpXmlOutTransferKefuMessage build() { | |||
WxMpXmlOutTransferKefuMessage m = new WxMpXmlOutTransferKefuMessage(); | |||
setCommon(m); | |||
if(StringUtils.isNotBlank(this.kfAccount)){ | |||
WxMpXmlOutTransferCustomerServiceMessage.TransInfo transInfo = new WxMpXmlOutTransferCustomerServiceMessage.TransInfo(); | |||
WxMpXmlOutTransferKefuMessage.TransInfo transInfo = new WxMpXmlOutTransferKefuMessage.TransInfo(); | |||
transInfo.setKfAccount(this.kfAccount); | |||
m.setTransInfo(transInfo); | |||
} | |||
@@ -4,7 +4,7 @@ import com.google.gson.Gson; | |||
import com.google.gson.GsonBuilder; | |||
import me.chanjar.weixin.mp.bean.WxMpCard; | |||
import me.chanjar.weixin.mp.bean.WxMpCustomMessage; | |||
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; | |||
import me.chanjar.weixin.mp.bean.WxMpMassNews; | |||
import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage; | |||
import me.chanjar.weixin.mp.bean.WxMpMassPreviewMessage; | |||
@@ -38,7 +38,7 @@ public class WxMpGsonBuilder { | |||
static { | |||
INSTANCE.disableHtmlEscaping(); | |||
INSTANCE.registerTypeAdapter(WxMpCustomMessage.class, new WxMpCustomMessageGsonAdapter()); | |||
INSTANCE.registerTypeAdapter(WxMpKefuMessage.class, new WxMpKefuMessageGsonAdapter()); | |||
INSTANCE.registerTypeAdapter(WxMpMassNews.class, new WxMpMassNewsGsonAdapter()); | |||
INSTANCE.registerTypeAdapter(WxMpMassTagMessage.class, new WxMpMassTagMessageGsonAdapter()); | |||
INSTANCE.registerTypeAdapter(WxMpMassOpenIdsMessage.class, new WxMpMassOpenIdsMessageGsonAdapter()); | |||
@@ -10,20 +10,19 @@ package me.chanjar.weixin.mp.util.json; | |||
import com.google.gson.*; | |||
import me.chanjar.weixin.common.api.WxConsts; | |||
import me.chanjar.weixin.mp.bean.WxMpCustomMessage; | |||
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; | |||
import org.apache.commons.lang3.StringUtils; | |||
import java.lang.reflect.Type; | |||
import org.apache.commons.lang3.StringUtils; | |||
public class WxMpCustomMessageGsonAdapter implements JsonSerializer<WxMpCustomMessage> { | |||
public class WxMpKefuMessageGsonAdapter implements JsonSerializer<WxMpKefuMessage> { | |||
@Override | |||
public JsonElement serialize(WxMpCustomMessage message, Type typeOfSrc, JsonSerializationContext context) { | |||
public JsonElement serialize(WxMpKefuMessage message, Type typeOfSrc, JsonSerializationContext context) { | |||
JsonObject messageJson = new JsonObject(); | |||
messageJson.addProperty("touser", message.getToUser()); | |||
messageJson.addProperty("msgtype", message.getMsgType()); | |||
if (WxConsts.CUSTOM_MSG_TEXT.equals(message.getMsgType())) { | |||
JsonObject text = new JsonObject(); | |||
text.addProperty("content", message.getContent()); | |||
@@ -60,11 +59,11 @@ public class WxMpCustomMessageGsonAdapter implements JsonSerializer<WxMpCustomMe | |||
music.addProperty("hqmusicurl", message.getHqMusicUrl()); | |||
messageJson.add("music", music); | |||
} | |||
if (WxConsts.CUSTOM_MSG_NEWS.equals(message.getMsgType())) { | |||
JsonObject newsJsonObject = new JsonObject(); | |||
JsonArray articleJsonArray = new JsonArray(); | |||
for (WxMpCustomMessage.WxArticle article : message.getArticles()) { | |||
for (WxMpKefuMessage.WxArticle article : message.getArticles()) { | |||
JsonObject articleJson = new JsonObject(); | |||
articleJson.addProperty("title", article.getTitle()); | |||
articleJson.addProperty("description", article.getDescription()); | |||
@@ -81,13 +80,13 @@ public class WxMpCustomMessageGsonAdapter implements JsonSerializer<WxMpCustomMe | |||
wxcard.addProperty("card_id", message.getCardId()); | |||
messageJson.add("wxcard", wxcard); | |||
} | |||
if (StringUtils.isNotBlank(message.getKfAccount())){ | |||
JsonObject newsJsonObject = new JsonObject(); | |||
newsJsonObject.addProperty("kf_account", message.getKfAccount()); | |||
messageJson.add("customservice", newsJsonObject); | |||
messageJson.add("customservice", newsJsonObject); | |||
} | |||
return messageJson; | |||
} | |||
@@ -13,7 +13,7 @@ import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage; | |||
import me.chanjar.weixin.mp.bean.WxMpXmlOutMusicMessage; | |||
import me.chanjar.weixin.mp.bean.WxMpXmlOutNewsMessage; | |||
import me.chanjar.weixin.mp.bean.WxMpXmlOutTextMessage; | |||
import me.chanjar.weixin.mp.bean.WxMpXmlOutTransferCustomerServiceMessage; | |||
import me.chanjar.weixin.mp.bean.WxMpXmlOutTransferKefuMessage; | |||
import me.chanjar.weixin.mp.bean.WxMpXmlOutVideoMessage; | |||
import me.chanjar.weixin.mp.bean.WxMpXmlOutVoiceMessage; | |||
@@ -62,7 +62,7 @@ public class XStreamTransformer { | |||
map.put(WxMpXmlOutImageMessage.class, config_WxMpXmlOutImageMessage()); | |||
map.put(WxMpXmlOutVideoMessage.class, config_WxMpXmlOutVideoMessage()); | |||
map.put(WxMpXmlOutVoiceMessage.class, config_WxMpXmlOutVoiceMessage()); | |||
map.put(WxMpXmlOutTransferCustomerServiceMessage.class, config_WxMpXmlOutTransferCustomerServiceMessage()); | |||
map.put(WxMpXmlOutTransferKefuMessage.class, config_WxMpXmlOutTransferCustomerServiceMessage()); | |||
return map; | |||
} | |||
@@ -127,8 +127,8 @@ public class XStreamTransformer { | |||
private static XStream config_WxMpXmlOutTransferCustomerServiceMessage() { | |||
XStream xstream = XStreamInitializer.getInstance(); | |||
xstream.processAnnotations(WxMpXmlOutMessage.class); | |||
xstream.processAnnotations(WxMpXmlOutTransferCustomerServiceMessage.class); | |||
xstream.processAnnotations(WxMpXmlOutTransferCustomerServiceMessage.TransInfo.class); | |||
xstream.processAnnotations(WxMpXmlOutTransferKefuMessage.class); | |||
xstream.processAnnotations(WxMpXmlOutTransferKefuMessage.TransInfo.class); | |||
return xstream; | |||
} | |||
@@ -3,6 +3,7 @@ package me.chanjar.weixin.mp.api.impl; | |||
import java.io.File; | |||
import java.util.Date; | |||
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; | |||
import org.joda.time.DateTime; | |||
import org.testng.Assert; | |||
import org.testng.annotations.DataProvider; | |||
@@ -15,7 +16,6 @@ import me.chanjar.weixin.common.api.WxConsts; | |||
import me.chanjar.weixin.common.exception.WxErrorException; | |||
import me.chanjar.weixin.mp.api.ApiTestModule; | |||
import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; | |||
import me.chanjar.weixin.mp.bean.WxMpCustomMessage; | |||
import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest; | |||
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfInfo; | |||
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfList; | |||
@@ -40,26 +40,26 @@ public class WxMpKefuServiceImplTest { | |||
public void testSendCustomMessage() throws WxErrorException { | |||
WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService | |||
.getWxMpConfigStorage(); | |||
WxMpCustomMessage message = new WxMpCustomMessage(); | |||
WxMpKefuMessage message = new WxMpKefuMessage(); | |||
message.setMsgType(WxConsts.CUSTOM_MSG_TEXT); | |||
message.setToUser(configStorage.getOpenid()); | |||
message.setContent( | |||
"欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>"); | |||
this.wxService.getKefuService().customMessageSend(message); | |||
this.wxService.getKefuService().sendKefuMessage(message); | |||
} | |||
public void testSendCustomMessageWithKfAccount() throws WxErrorException { | |||
WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService | |||
.getWxMpConfigStorage(); | |||
WxMpCustomMessage message = new WxMpCustomMessage(); | |||
WxMpKefuMessage message = new WxMpKefuMessage(); | |||
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.getKefuService().customMessageSend(message); | |||
this.wxService.getKefuService().sendKefuMessage(message); | |||
} | |||
public void testKfList() throws WxErrorException { | |||
@@ -6,10 +6,10 @@ import org.testng.annotations.Test; | |||
/** | |||
* Created by ben on 2015/12/29. | |||
*/ | |||
public class WxMpXmlOutTransferCustomerServiceMessageTest { | |||
public class WxMpXmlOutTransferKefuMessageTest { | |||
@Test | |||
public void test() { | |||
WxMpXmlOutTransferCustomerServiceMessage m = new WxMpXmlOutTransferCustomerServiceMessage(); | |||
WxMpXmlOutTransferKefuMessage m = new WxMpXmlOutTransferKefuMessage(); | |||
m.setCreateTime(1399197672L); | |||
m.setFromUserName("fromuser"); | |||
m.setToUserName("touser"); | |||
@@ -32,7 +32,7 @@ public class WxMpXmlOutTransferCustomerServiceMessageTest { | |||
"<KfAccount><![CDATA[test1@test]]></KfAccount>" + | |||
"</TransInfo>" + | |||
"</xml>"; | |||
WxMpXmlOutTransferCustomerServiceMessage.TransInfo transInfo = new WxMpXmlOutTransferCustomerServiceMessage.TransInfo(); | |||
WxMpXmlOutTransferKefuMessage.TransInfo transInfo = new WxMpXmlOutTransferKefuMessage.TransInfo(); | |||
transInfo.setKfAccount("test1@test"); | |||
m.setTransInfo(transInfo); | |||
System.out.println(m.toXml()); | |||
@@ -41,7 +41,7 @@ public class WxMpXmlOutTransferCustomerServiceMessageTest { | |||
@Test | |||
public void testBuild() { | |||
WxMpXmlOutTransferCustomerServiceMessage m = WxMpXmlOutMessage.TRANSFER_CUSTOMER_SERVICE().fromUser("fromuser").toUser("touser").build(); | |||
WxMpXmlOutTransferKefuMessage m = WxMpXmlOutMessage.TRANSFER_CUSTOMER_SERVICE().fromUser("fromuser").toUser("touser").build(); | |||
m.setCreateTime(1399197672L); | |||
String expected = "<xml>" + | |||
"<ToUserName><![CDATA[touser]]></ToUserName>" + | |||
@@ -67,4 +67,4 @@ public class WxMpXmlOutTransferCustomerServiceMessageTest { | |||
System.out.println(m.toXml()); | |||
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); | |||
} | |||
} | |||
} |
@@ -1,54 +1,54 @@ | |||
package me.chanjar.weixin.mp.bean; | |||
package me.chanjar.weixin.mp.bean.kefu; | |||
import me.chanjar.weixin.common.api.WxConsts; | |||
import me.chanjar.weixin.mp.bean.WxMpCustomMessage.WxArticle; | |||
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage.WxArticle; | |||
import org.testng.Assert; | |||
import org.testng.annotations.Test; | |||
@Test | |||
public class WxMpCustomMessageTest { | |||
public class WxMpKefuMessageTest { | |||
public void testTextReply() { | |||
WxMpCustomMessage reply = new WxMpCustomMessage(); | |||
WxMpKefuMessage reply = new WxMpKefuMessage(); | |||
reply.setToUser("OPENID"); | |||
reply.setMsgType(WxConsts.CUSTOM_MSG_TEXT); | |||
reply.setContent("sfsfdsdf"); | |||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}"); | |||
} | |||
public void testTextBuild() { | |||
WxMpCustomMessage reply = WxMpCustomMessage.TEXT().toUser("OPENID").content("sfsfdsdf").build(); | |||
WxMpKefuMessage reply = WxMpKefuMessage.TEXT().toUser("OPENID").content("sfsfdsdf").build(); | |||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}"); | |||
} | |||
public void testImageReply() { | |||
WxMpCustomMessage reply = new WxMpCustomMessage(); | |||
WxMpKefuMessage reply = new WxMpKefuMessage(); | |||
reply.setToUser("OPENID"); | |||
reply.setMsgType(WxConsts.CUSTOM_MSG_IMAGE); | |||
reply.setMediaId("MEDIA_ID"); | |||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}"); | |||
} | |||
public void testImageBuild() { | |||
WxMpCustomMessage reply = WxMpCustomMessage.IMAGE().toUser("OPENID").mediaId("MEDIA_ID").build(); | |||
WxMpKefuMessage reply = WxMpKefuMessage.IMAGE().toUser("OPENID").mediaId("MEDIA_ID").build(); | |||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}"); | |||
} | |||
public void testVoiceReply() { | |||
WxMpCustomMessage reply = new WxMpCustomMessage(); | |||
WxMpKefuMessage reply = new WxMpKefuMessage(); | |||
reply.setToUser("OPENID"); | |||
reply.setMsgType(WxConsts.CUSTOM_MSG_VOICE); | |||
reply.setMediaId("MEDIA_ID"); | |||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"voice\",\"voice\":{\"media_id\":\"MEDIA_ID\"}}"); | |||
} | |||
public void testVoiceBuild() { | |||
WxMpCustomMessage reply = WxMpCustomMessage.VOICE().toUser("OPENID").mediaId("MEDIA_ID").build(); | |||
WxMpKefuMessage reply = WxMpKefuMessage.VOICE().toUser("OPENID").mediaId("MEDIA_ID").build(); | |||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"voice\",\"voice\":{\"media_id\":\"MEDIA_ID\"}}"); | |||
} | |||
public void testVideoReply() { | |||
WxMpCustomMessage reply = new WxMpCustomMessage(); | |||
WxMpKefuMessage reply = new WxMpKefuMessage(); | |||
reply.setToUser("OPENID"); | |||
reply.setMsgType(WxConsts.CUSTOM_MSG_VIDEO); | |||
reply.setMediaId("MEDIA_ID"); | |||
@@ -57,14 +57,14 @@ public class WxMpCustomMessageTest { | |||
reply.setDescription("DESCRIPTION"); | |||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"video\",\"video\":{\"media_id\":\"MEDIA_ID\",\"thumb_media_id\":\"MEDIA_ID\",\"title\":\"TITLE\",\"description\":\"DESCRIPTION\"}}"); | |||
} | |||
public void testVideoBuild() { | |||
WxMpCustomMessage reply = WxMpCustomMessage.VIDEO().toUser("OPENID").title("TITLE").mediaId("MEDIA_ID").thumbMediaId("MEDIA_ID").description("DESCRIPTION").build(); | |||
WxMpKefuMessage reply = WxMpKefuMessage.VIDEO().toUser("OPENID").title("TITLE").mediaId("MEDIA_ID").thumbMediaId("MEDIA_ID").description("DESCRIPTION").build(); | |||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"video\",\"video\":{\"media_id\":\"MEDIA_ID\",\"thumb_media_id\":\"MEDIA_ID\",\"title\":\"TITLE\",\"description\":\"DESCRIPTION\"}}"); | |||
} | |||
public void testMusicReply() { | |||
WxMpCustomMessage reply = new WxMpCustomMessage(); | |||
WxMpKefuMessage reply = new WxMpKefuMessage(); | |||
reply.setToUser("OPENID"); | |||
reply.setMsgType(WxConsts.CUSTOM_MSG_MUSIC); | |||
reply.setThumbMediaId("MEDIA_ID"); | |||
@@ -74,9 +74,9 @@ public class WxMpCustomMessageTest { | |||
reply.setHqMusicUrl("HQ_MUSIC_URL"); | |||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"music\",\"music\":{\"title\":\"TITLE\",\"description\":\"DESCRIPTION\",\"thumb_media_id\":\"MEDIA_ID\",\"musicurl\":\"MUSIC_URL\",\"hqmusicurl\":\"HQ_MUSIC_URL\"}}"); | |||
} | |||
public void testMusicBuild() { | |||
WxMpCustomMessage reply = WxMpCustomMessage.MUSIC() | |||
WxMpKefuMessage reply = WxMpKefuMessage.MUSIC() | |||
.toUser("OPENID") | |||
.title("TITLE") | |||
.thumbMediaId("MEDIA_ID") | |||
@@ -86,19 +86,19 @@ public class WxMpCustomMessageTest { | |||
.build(); | |||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"music\",\"music\":{\"title\":\"TITLE\",\"description\":\"DESCRIPTION\",\"thumb_media_id\":\"MEDIA_ID\",\"musicurl\":\"MUSIC_URL\",\"hqmusicurl\":\"HQ_MUSIC_URL\"}}"); | |||
} | |||
public void testNewsReply() { | |||
WxMpCustomMessage reply = new WxMpCustomMessage(); | |||
WxMpKefuMessage reply = new WxMpKefuMessage(); | |||
reply.setToUser("OPENID"); | |||
reply.setMsgType(WxConsts.CUSTOM_MSG_NEWS); | |||
WxArticle article1 = new WxArticle(); | |||
article1.setUrl("URL"); | |||
article1.setPicUrl("PIC_URL"); | |||
article1.setDescription("Is Really A Happy Day"); | |||
article1.setTitle("Happy Day"); | |||
reply.getArticles().add(article1); | |||
WxArticle article2 = new WxArticle(); | |||
article2.setUrl("URL"); | |||
article2.setPicUrl("PIC_URL"); | |||
@@ -106,26 +106,26 @@ public class WxMpCustomMessageTest { | |||
article2.setTitle("Happy Day"); | |||
reply.getArticles().add(article2); | |||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"news\",\"news\":{\"articles\":[{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"},{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"}]}}"); | |||
} | |||
public void testNewsBuild() { | |||
WxArticle article1 = new WxArticle(); | |||
article1.setUrl("URL"); | |||
article1.setPicUrl("PIC_URL"); | |||
article1.setDescription("Is Really A Happy Day"); | |||
article1.setTitle("Happy Day"); | |||
WxArticle article2 = new WxArticle(); | |||
article2.setUrl("URL"); | |||
article2.setPicUrl("PIC_URL"); | |||
article2.setDescription("Is Really A Happy Day"); | |||
article2.setTitle("Happy Day"); | |||
WxMpCustomMessage reply = WxMpCustomMessage.NEWS().toUser("OPENID").addArticle(article1).addArticle(article2).build(); | |||
WxMpKefuMessage reply = WxMpKefuMessage.NEWS().toUser("OPENID").addArticle(article1).addArticle(article2).build(); | |||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"news\",\"news\":{\"articles\":[{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"},{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"}]}}"); | |||
} | |||
} |
@@ -10,7 +10,7 @@ import me.chanjar.weixin.common.session.WxSessionManager; | |||
import me.chanjar.weixin.mp.api.WxMpMessageHandler; | |||
import me.chanjar.weixin.mp.api.WxMpMessageMatcher; | |||
import me.chanjar.weixin.mp.api.WxMpService; | |||
import me.chanjar.weixin.mp.bean.WxMpCustomMessage; | |||
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; | |||
import me.chanjar.weixin.mp.bean.WxMpXmlMessage; | |||
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage; | |||
@@ -52,19 +52,19 @@ public class DemoGuessNumberHandler implements WxMpMessageHandler, WxMpMessageMa | |||
protected void letsGo(WxMpXmlMessage wxMessage, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException { | |||
WxSession session = sessionManager.getSession(wxMessage.getFromUser()); | |||
if (session.getAttribute("guessing") == null) { | |||
WxMpCustomMessage m = WxMpCustomMessage | |||
WxMpKefuMessage m = WxMpKefuMessage | |||
.TEXT() | |||
.toUser(wxMessage.getFromUser()) | |||
.content("请猜一个100以内的数字") | |||
.build(); | |||
wxMpService.getKefuService().customMessageSend(m); | |||
wxMpService.getKefuService().sendKefuMessage(m); | |||
} else { | |||
WxMpCustomMessage m = WxMpCustomMessage | |||
WxMpKefuMessage m = WxMpKefuMessage | |||
.TEXT() | |||
.toUser(wxMessage.getFromUser()) | |||
.content("放弃了吗?那请重新猜一个100以内的数字") | |||
.build(); | |||
wxMpService.getKefuService().customMessageSend(m); | |||
wxMpService.getKefuService().sendKefuMessage(m); | |||
} | |||
session.setAttribute("guessing", Boolean.TRUE); | |||
@@ -87,28 +87,28 @@ public class DemoGuessNumberHandler implements WxMpMessageHandler, WxMpMessageMa | |||
int answer = (Integer) session.getAttribute("number"); | |||
int guessNumber = Integer.valueOf(wxMessage.getContent()); | |||
if (guessNumber < answer) { | |||
WxMpCustomMessage m = WxMpCustomMessage | |||
WxMpKefuMessage m = WxMpKefuMessage | |||
.TEXT() | |||
.toUser(wxMessage.getFromUser()) | |||
.content("小了") | |||
.build(); | |||
wxMpService.getKefuService().customMessageSend(m); | |||
wxMpService.getKefuService().sendKefuMessage(m); | |||
} else if (guessNumber > answer) { | |||
WxMpCustomMessage m = WxMpCustomMessage | |||
WxMpKefuMessage m = WxMpKefuMessage | |||
.TEXT() | |||
.toUser(wxMessage.getFromUser()) | |||
.content("大了") | |||
.build(); | |||
wxMpService.getKefuService().customMessageSend(m); | |||
wxMpService.getKefuService().sendKefuMessage(m); | |||
} else { | |||
WxMpCustomMessage m = WxMpCustomMessage | |||
WxMpKefuMessage m = WxMpKefuMessage | |||
.TEXT() | |||
.toUser(wxMessage.getFromUser()) | |||
.content("Bingo!") | |||
.build(); | |||
session.removeAttribute("guessing"); | |||
wxMpService.getKefuService().customMessageSend(m); | |||
wxMpService.getKefuService().sendKefuMessage(m); | |||
} | |||
} | |||
@@ -17,7 +17,7 @@ | |||
<test name="Bean_Test"> | |||
<classes> | |||
<class name="me.chanjar.weixin.mp.bean.WxMpCustomMessageTest" /> | |||
<class name="me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessageTest" /> | |||
<class name="me.chanjar.weixin.mp.bean.WxMpXmlMessageTest" /> | |||
<class name="me.chanjar.weixin.mp.bean.WxMpXmlOutImageMessageTest" /> | |||
<class name="me.chanjar.weixin.mp.bean.WxXmlOutMusicMessageTest" /> | |||