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