批量格式化代码

This commit is contained in:
Binary Wang
2017-05-11 17:07:08 +08:00
parent 5f887739a3
commit 8982cf8471
223 changed files with 2425 additions and 2793 deletions

View File

@@ -39,13 +39,13 @@ public class WxCpJedisConfigStorage implements WxCpConfigStorage {
this.jedisPool = new JedisPool(host, port);
}
public WxCpJedisConfigStorage(JedisPoolConfig poolConfig, String host, int port) {
this.jedisPool = new JedisPool(poolConfig, host, port);
this.jedisPool = new JedisPool(poolConfig, host, port);
}
public WxCpJedisConfigStorage(JedisPoolConfig poolConfig, String host, int port, int timeout, final String password) {
this.jedisPool = new JedisPool(poolConfig, host, port, timeout, password);
this.jedisPool = new JedisPool(poolConfig, host, port, timeout, password);
}
/**

View File

@@ -481,13 +481,6 @@ public interface WxCpService {
*/
<T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException;
/**
* 注入 {@link WxCpConfigStorage} 的实现
*
* @param wxConfigProvider 配置对象
*/
void setWxCpConfigStorage(WxCpConfigStorage wxConfigProvider);
/**
* <pre>
* 设置当微信系统响应系统繁忙时,要等待多少 retrySleepMillis(ms) * 2^(重试次数 - 1) 再发起重试
@@ -563,4 +556,11 @@ public interface WxCpService {
* @return WxMpConfigStorage
*/
WxCpConfigStorage getWxCpConfigStorage();
/**
* 注入 {@link WxCpConfigStorage} 的实现
*
* @param wxConfigProvider 配置对象
*/
void setWxCpConfigStorage(WxCpConfigStorage wxConfigProvider);
}

View File

@@ -1,7 +1,5 @@
package me.chanjar.weixin.cp.api.impl.okhttp;
import java.io.IOException;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
@@ -11,6 +9,8 @@ import me.chanjar.weixin.cp.api.WxCpConfigStorage;
import me.chanjar.weixin.cp.api.impl.AbstractWxCpServiceImpl;
import okhttp3.*;
import java.io.IOException;
public class WxCpServiceImpl extends AbstractWxCpServiceImpl<ConnectionPool, OkhttpProxyInfo> {
protected ConnectionPool httpClient;
protected OkhttpProxyInfo httpProxy;

View File

@@ -1,9 +1,9 @@
package me.chanjar.weixin.cp.bean;
import java.io.Serializable;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import java.io.Serializable;
/**
* 微信部门
*
@@ -60,10 +60,10 @@ public class WxCpDepart implements Serializable {
@Override
public String toString() {
return "WxCpDepart{" +
"id=" + this.id +
", name='" + this.name + '\'' +
", parentId=" + this.parentId +
", order=" + this.order +
'}';
"id=" + this.id +
", name='" + this.name + '\'' +
", parentId=" + this.parentId +
", order=" + this.order +
'}';
}
}

View File

@@ -33,14 +33,6 @@ public class WxCpMessage implements Serializable {
private List<NewArticle> articles = new ArrayList<>();
private List<MpnewsArticle> mpnewsArticles = new ArrayList<>();
public List<MpnewsArticle> getMpnewsArticles() {
return mpnewsArticles;
}
public void setMpnewsArticles(List<MpnewsArticle> mpnewsArticles) {
this.mpnewsArticles = mpnewsArticles;
}
/**
* 获得文本消息builder
*/
@@ -90,6 +82,14 @@ public class WxCpMessage implements Serializable {
return new FileBuilder();
}
public List<MpnewsArticle> getMpnewsArticles() {
return mpnewsArticles;
}
public void setMpnewsArticles(List<MpnewsArticle> mpnewsArticles) {
this.mpnewsArticles = mpnewsArticles;
}
public String getToUser() {
return this.toUser;
}

View File

@@ -1,9 +1,9 @@
package me.chanjar.weixin.cp.bean;
import java.io.Serializable;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import java.io.Serializable;
/**
* Created by Daniel Qian
*/

View File

@@ -1,11 +1,11 @@
package me.chanjar.weixin.cp.bean;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
/**
* 微信用户信息
*

View File

@@ -1,21 +1,19 @@
package me.chanjar.weixin.cp.bean;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
import me.chanjar.weixin.cp.api.WxCpConfigStorage;
import me.chanjar.weixin.cp.util.crypto.WxCpCryptUtil;
import me.chanjar.weixin.cp.util.xml.XStreamTransformer;
import org.apache.commons.io.IOUtils;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.IOUtils;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
import me.chanjar.weixin.cp.api.WxCpConfigStorage;
import me.chanjar.weixin.cp.util.crypto.WxCpCryptUtil;
import me.chanjar.weixin.cp.util.xml.XStreamTransformer;
/**
* <pre>
* 微信推送过来的消息也是同步回复给用户的消息xml格式
@@ -183,18 +181,18 @@ public class WxCpXmlMessage implements Serializable {
* @param msgSignature
*/
public static WxCpXmlMessage fromEncryptedXml(
String encryptedXml,
WxCpConfigStorage wxCpConfigStorage,
String timestamp, String nonce, String msgSignature) {
String encryptedXml,
WxCpConfigStorage wxCpConfigStorage,
String timestamp, String nonce, String msgSignature) {
WxCpCryptUtil cryptUtil = new WxCpCryptUtil(wxCpConfigStorage);
String plainText = cryptUtil.decrypt(msgSignature, timestamp, nonce, encryptedXml);
return fromXml(plainText);
}
public static WxCpXmlMessage fromEncryptedXml(
InputStream is,
WxCpConfigStorage wxCpConfigStorage,
String timestamp, String nonce, String msgSignature) {
InputStream is,
WxCpConfigStorage wxCpConfigStorage,
String timestamp, String nonce, String msgSignature) {
try {
return fromEncryptedXml(IOUtils.toString(is, "UTF-8"), wxCpConfigStorage, timestamp, nonce, msgSignature);
} catch (IOException e) {
@@ -493,40 +491,40 @@ public class WxCpXmlMessage implements Serializable {
@Override
public String toString() {
return "WxCpXmlMessage{" +
"agentId=" + this.agentId +
", toUserName='" + this.toUserName + '\'' +
", fromUserName='" + this.fromUserName + '\'' +
", createTime=" + this.createTime +
", msgType='" + this.msgType + '\'' +
", content='" + this.content + '\'' +
", msgId=" + this.msgId +
", picUrl='" + this.picUrl + '\'' +
", mediaId='" + this.mediaId + '\'' +
", format='" + this.format + '\'' +
", thumbMediaId='" + this.thumbMediaId + '\'' +
", locationX=" + this.locationX +
", locationY=" + this.locationY +
", scale=" + this.scale +
", label='" + this.label + '\'' +
", title='" + this.title + '\'' +
", description='" + this.description + '\'' +
", url='" + this.url + '\'' +
", event='" + this.event + '\'' +
", eventKey='" + this.eventKey + '\'' +
", ticket='" + this.ticket + '\'' +
", latitude=" + this.latitude +
", longitude=" + this.longitude +
", precision=" + this.precision +
", recognition='" + this.recognition + '\'' +
", status='" + this.status + '\'' +
", totalCount=" + this.totalCount +
", filterCount=" + this.filterCount +
", sentCount=" + this.sentCount +
", errorCount=" + this.errorCount +
", scanCodeInfo=" + this.scanCodeInfo +
", sendPicsInfo=" + this.sendPicsInfo +
", sendLocationInfo=" + this.sendLocationInfo +
'}';
"agentId=" + this.agentId +
", toUserName='" + this.toUserName + '\'' +
", fromUserName='" + this.fromUserName + '\'' +
", createTime=" + this.createTime +
", msgType='" + this.msgType + '\'' +
", content='" + this.content + '\'' +
", msgId=" + this.msgId +
", picUrl='" + this.picUrl + '\'' +
", mediaId='" + this.mediaId + '\'' +
", format='" + this.format + '\'' +
", thumbMediaId='" + this.thumbMediaId + '\'' +
", locationX=" + this.locationX +
", locationY=" + this.locationY +
", scale=" + this.scale +
", label='" + this.label + '\'' +
", title='" + this.title + '\'' +
", description='" + this.description + '\'' +
", url='" + this.url + '\'' +
", event='" + this.event + '\'' +
", eventKey='" + this.eventKey + '\'' +
", ticket='" + this.ticket + '\'' +
", latitude=" + this.latitude +
", longitude=" + this.longitude +
", precision=" + this.precision +
", recognition='" + this.recognition + '\'' +
", status='" + this.status + '\'' +
", totalCount=" + this.totalCount +
", filterCount=" + this.filterCount +
", sentCount=" + this.sentCount +
", errorCount=" + this.errorCount +
", scanCodeInfo=" + this.scanCodeInfo +
", sendPicsInfo=" + this.sendPicsInfo +
", sendLocationInfo=" + this.sendLocationInfo +
'}';
}
@XStreamAlias("ScanCodeInfo")

View File

@@ -2,7 +2,6 @@ package me.chanjar.weixin.cp.bean;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.util.xml.XStreamMediaIdConverter;

View File

@@ -1,14 +1,13 @@
package me.chanjar.weixin.cp.bean;
import java.util.ArrayList;
import java.util.List;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
import java.util.ArrayList;
import java.util.List;
@XStreamAlias("xml")
public class WxCpXmlOutNewsMessage extends WxCpXmlOutMessage {
private static final long serialVersionUID = -5796178637883178826L;

View File

@@ -2,7 +2,6 @@ package me.chanjar.weixin.cp.bean;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;

View File

@@ -2,7 +2,6 @@ package me.chanjar.weixin.cp.bean;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;

View File

@@ -2,7 +2,6 @@ package me.chanjar.weixin.cp.bean;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.util.xml.XStreamMediaIdConverter;

View File

@@ -4,6 +4,7 @@ package me.chanjar.weixin.cp.bean.article;
* <pre>
* Created by BinaryWang on 2017/3/27.
* </pre>
*
* @author Binary Wang
*/
public class MpnewsArticle {

View File

@@ -44,7 +44,7 @@ public class BaseBuilder<T> {
m.setToParty(this.toParty);
m.setToTag(this.toTag);
m.setSafe(
(this.safe == null || "".equals(this.safe)) ? WxConsts.CUSTOM_MSG_SAFE_NO : this.safe);
(this.safe == null || "".equals(this.safe)) ? WxConsts.CUSTOM_MSG_SAFE_NO : this.safe);
return m;
}

View File

@@ -1,47 +1,51 @@
/**
* 对公众平台发送给公众账号的消息加解密示例代码.
*
* @copyright Copyright (c) 1998-2014 Tencent Inc.
* <p>
* 针对org.apache.commons.codec.binary.Base64
* 需要导入架包commons-codec-1.9或commons-codec-1.8等其他版本)
* 官方下载地址http://commons.apache.org/proper/commons-codec/download_codec.cgi
*/
// ------------------------------------------------------------------------
/**
* 针对org.apache.commons.codec.binary.Base64
* 需要导入架包commons-codec-1.9或commons-codec-1.8等其他版本)
* 官方下载地址http://commons.apache.org/proper/commons-codec/download_codec.cgi
*/
package me.chanjar.weixin.cp.util.crypto;
import me.chanjar.weixin.common.util.crypto.WxCryptUtil;
import me.chanjar.weixin.cp.api.WxCpConfigStorage;
import org.apache.commons.codec.binary.Base64;
public class WxCpCryptUtil extends WxCryptUtil {
/**
* 构造函数
*
* @param wxCpConfigStorage
*/
public WxCpCryptUtil(WxCpConfigStorage wxCpConfigStorage) {
/*
* @param token 公众平台上开发者设置的token
* @param encodingAesKey 公众平台上开发者设置的EncodingAESKey
* @param appidOrCorpid 公众平台appid
*/
String encodingAesKey = wxCpConfigStorage.getAesKey();
String token = wxCpConfigStorage.getToken();
String corpId = wxCpConfigStorage.getCorpId();
this.token = token;
this.appidOrCorpid = corpId;
this.aesKey = Base64.decodeBase64(encodingAesKey + "=");
}
}
/**
* 对公众平台发送给公众账号的消息加解密示例代码.
*
* @copyright Copyright (c) 1998-2014 Tencent Inc.
* <p>
* 针对org.apache.commons.codec.binary.Base64
* 需要导入架包commons-codec-1.9或commons-codec-1.8等其他版本)
* 官方下载地址http://commons.apache.org/proper/commons-codec/download_codec.cgi
* <p>
* 针对org.apache.commons.codec.binary.Base64
* 需要导入架包commons-codec-1.9或commons-codec-1.8等其他版本)
* 官方下载地址http://commons.apache.org/proper/commons-codec/download_codec.cgi
*/
// ------------------------------------------------------------------------
/**
* 针对org.apache.commons.codec.binary.Base64
* 需要导入架包commons-codec-1.9或commons-codec-1.8等其他版本)
* 官方下载地址http://commons.apache.org/proper/commons-codec/download_codec.cgi
*/
package me.chanjar.weixin.cp.util.crypto;
import me.chanjar.weixin.common.util.crypto.WxCryptUtil;
import me.chanjar.weixin.cp.api.WxCpConfigStorage;
import org.apache.commons.codec.binary.Base64;
public class WxCpCryptUtil extends WxCryptUtil {
/**
* 构造函数
*
* @param wxCpConfigStorage
*/
public WxCpCryptUtil(WxCpConfigStorage wxCpConfigStorage) {
/*
* @param token 公众平台上开发者设置的token
* @param encodingAesKey 公众平台上开发者设置的EncodingAESKey
* @param appidOrCorpid 公众平台appid
*/
String encodingAesKey = wxCpConfigStorage.getAesKey();
String token = wxCpConfigStorage.getToken();
String corpId = wxCpConfigStorage.getCorpId();
this.token = token;
this.appidOrCorpid = corpId;
this.aesKey = Base64.decodeBase64(encodingAesKey + "=");
}
}

View File

@@ -39,7 +39,7 @@ public class WxCpDepartGsonAdapter implements JsonSerializer<WxCpDepart>, JsonDe
@Override
public WxCpDepart deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
throws JsonParseException {
WxCpDepart depart = new WxCpDepart();
JsonObject departJson = json.getAsJsonObject();
if (departJson.get("id") != null && !departJson.get("id").isJsonNull()) {

View File

@@ -93,7 +93,7 @@ public class WxCpMessageGsonAdapter implements JsonSerializer<WxCpMessage> {
JsonObject newsJsonObject = new JsonObject();
if (message.getMediaId() != null) {
newsJsonObject.addProperty("media_id", message.getMediaId());
}else {
} else {
JsonArray articleJsonArray = new JsonArray();
for (MpnewsArticle article : message.getMpnewsArticles()) {
JsonObject articleJson = new JsonObject();

View File

@@ -29,7 +29,7 @@ public class WxCpTagGsonAdapter implements JsonSerializer<WxCpTag>, JsonDeserial
@Override
public WxCpTag deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
throws JsonParseException {
JsonObject jsonObject = json.getAsJsonObject();
return new WxCpTag(GsonHelper.getString(jsonObject, "tagid"), GsonHelper.getString(jsonObject, "tagname"));
}

View File

@@ -21,7 +21,7 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri
@Override
public WxCpUser deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
throws JsonParseException {
JsonObject o = json.getAsJsonObject();
WxCpUser user = new WxCpUser();
user.setUserId(GsonHelper.getString(o, "userid"));
@@ -50,8 +50,8 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri
JsonArray attrJsonElements = o.get("extattr").getAsJsonObject().get("attrs").getAsJsonArray();
for (JsonElement attrJsonElement : attrJsonElements) {
WxCpUser.Attr attr = new WxCpUser.Attr(
GsonHelper.getString(attrJsonElement.getAsJsonObject(), "name"),
GsonHelper.getString(attrJsonElement.getAsJsonObject(), "value")
GsonHelper.getString(attrJsonElement.getAsJsonObject(), "name"),
GsonHelper.getString(attrJsonElement.getAsJsonObject(), "value")
);
user.getExtAttrs().add(attr);
}

View File

@@ -1,16 +1,15 @@
package me.chanjar.weixin.cp.api;
import java.io.IOException;
import java.io.InputStream;
import com.google.inject.Binder;
import com.google.inject.Module;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
import me.chanjar.weixin.cp.api.impl.apache.WxCpServiceImpl;
import java.io.IOException;
import java.io.InputStream;
public class ApiTestModule implements Module {
public static <T> T fromXml(Class<T> clazz, InputStream is) {
@@ -23,9 +22,9 @@ public class ApiTestModule implements Module {
@Override
public void configure(Binder binder) {
try (InputStream is1 = ClassLoader
.getSystemResourceAsStream("test-config.xml")) {
.getSystemResourceAsStream("test-config.xml")) {
WxXmlCpInMemoryConfigStorage config = fromXml(
WxXmlCpInMemoryConfigStorage.class, is1);
WxXmlCpInMemoryConfigStorage.class, is1);
WxCpServiceImpl wxService = new WxCpServiceImpl();
wxService.setWxCpConfigStorage(config);
@@ -72,10 +71,10 @@ public class ApiTestModule implements Module {
@Override
public String toString() {
return super.toString() + " > WxXmlCpConfigStorage{" +
"userId='" + this.userId + '\'' +
", departmentId='" + this.departmentId + '\'' +
", tagId='" + this.tagId + '\'' +
'}';
"userId='" + this.userId + '\'' +
", departmentId='" + this.departmentId + '\'' +
", tagId='" + this.tagId + '\'' +
'}';
}
}

View File

@@ -1,16 +1,13 @@
package me.chanjar.weixin.cp.api;
import java.util.List;
import me.chanjar.weixin.cp.api.impl.apache.WxCpServiceImpl;
import org.testng.Assert;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.cp.api.impl.apache.WxCpServiceImpl;
import me.chanjar.weixin.cp.bean.WxCpDepart;
import org.testng.*;
import org.testng.annotations.*;
import java.util.List;
/**
* 测试部门接口

View File

@@ -1,22 +1,18 @@
package me.chanjar.weixin.cp.api;
import com.google.inject.Inject;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.cp.api.impl.apache.WxCpServiceImpl;
import org.testng.*;
import org.testng.annotations.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import me.chanjar.weixin.cp.api.impl.apache.WxCpServiceImpl;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import com.google.inject.Inject;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.exception.WxErrorException;
/**
* 测试多媒体文件上传下载
*
@@ -35,13 +31,13 @@ public class WxCpMediaAPITest {
@Test(dataProvider = "uploadMedia")
public void testUploadMedia(String mediaType, String fileType, String fileName) throws WxErrorException, IOException {
try (InputStream inputStream = ClassLoader
.getSystemResourceAsStream(fileName);) {
.getSystemResourceAsStream(fileName);) {
WxMediaUploadResult res = this.wxService.mediaUpload(mediaType, fileType,
inputStream);
inputStream);
Assert.assertNotNull(res.getType());
Assert.assertNotNull(res.getCreatedAt());
Assert.assertTrue(
res.getMediaId() != null || res.getThumbMediaId() != null);
res.getMediaId() != null || res.getThumbMediaId() != null);
if (res.getMediaId() != null) {
this.media_ids.add(res.getMediaId());
@@ -55,10 +51,10 @@ public class WxCpMediaAPITest {
@DataProvider
public Object[][] uploadMedia() {
return new Object[][]{
new Object[]{WxConsts.MEDIA_IMAGE, TestConstants.FILE_JPG, "mm.jpeg"},
new Object[]{WxConsts.MEDIA_VOICE, TestConstants.FILE_MP3, "mm.mp3"},
new Object[]{WxConsts.MEDIA_VIDEO, TestConstants.FILE_MP4, "mm.mp4"},
new Object[]{WxConsts.MEDIA_FILE, TestConstants.FILE_JPG, "mm.jpeg"}
new Object[]{WxConsts.MEDIA_IMAGE, TestConstants.FILE_JPG, "mm.jpeg"},
new Object[]{WxConsts.MEDIA_VOICE, TestConstants.FILE_MP3, "mm.mp3"},
new Object[]{WxConsts.MEDIA_VIDEO, TestConstants.FILE_MP4, "mm.mp4"},
new Object[]{WxConsts.MEDIA_FILE, TestConstants.FILE_JPG, "mm.jpeg"}
};
}

View File

@@ -5,9 +5,8 @@ import me.chanjar.weixin.common.session.StandardSessionManager;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.testng.*;
import org.testng.annotations.*;
import java.util.Map;
@@ -22,33 +21,33 @@ public class WxCpMessageRouterTest {
@Test(enabled = false)
public void prepare(boolean async, StringBuffer sb, WxCpMessageRouter router) {
router
.rule()
.async(async)
.msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1").content("CONTENT_1")
.handler(new WxEchoCpMessageHandler(sb, "COMBINE_4"))
.end()
.rule()
.async(async)
.msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1")
.handler(new WxEchoCpMessageHandler(sb, "COMBINE_3"))
.end()
.rule()
.async(async)
.msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK)
.handler(new WxEchoCpMessageHandler(sb, "COMBINE_2"))
.end()
.rule().async(async).msgType(WxConsts.XML_MSG_TEXT).handler(new WxEchoCpMessageHandler(sb, WxConsts.XML_MSG_TEXT)).end()
.rule().async(async).event(WxConsts.EVT_CLICK).handler(new WxEchoCpMessageHandler(sb, WxConsts.EVT_CLICK)).end()
.rule().async(async).eventKey("KEY_1").handler(new WxEchoCpMessageHandler(sb, "KEY_1")).end()
.rule().async(async).content("CONTENT_1").handler(new WxEchoCpMessageHandler(sb, "CONTENT_1")).end()
.rule().async(async).rContent(".*bc.*").handler(new WxEchoCpMessageHandler(sb, "abcd")).end()
.rule().async(async).matcher(new WxCpMessageMatcher() {
.rule()
.async(async)
.msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1").content("CONTENT_1")
.handler(new WxEchoCpMessageHandler(sb, "COMBINE_4"))
.end()
.rule()
.async(async)
.msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1")
.handler(new WxEchoCpMessageHandler(sb, "COMBINE_3"))
.end()
.rule()
.async(async)
.msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK)
.handler(new WxEchoCpMessageHandler(sb, "COMBINE_2"))
.end()
.rule().async(async).msgType(WxConsts.XML_MSG_TEXT).handler(new WxEchoCpMessageHandler(sb, WxConsts.XML_MSG_TEXT)).end()
.rule().async(async).event(WxConsts.EVT_CLICK).handler(new WxEchoCpMessageHandler(sb, WxConsts.EVT_CLICK)).end()
.rule().async(async).eventKey("KEY_1").handler(new WxEchoCpMessageHandler(sb, "KEY_1")).end()
.rule().async(async).content("CONTENT_1").handler(new WxEchoCpMessageHandler(sb, "CONTENT_1")).end()
.rule().async(async).rContent(".*bc.*").handler(new WxEchoCpMessageHandler(sb, "abcd")).end()
.rule().async(async).matcher(new WxCpMessageMatcher() {
@Override
public boolean match(WxCpXmlMessage message) {
return "strangeformat".equals(message.getFormat());
}
}).handler(new WxEchoCpMessageHandler(sb, "matcher")).end()
.rule().async(async).handler(new WxEchoCpMessageHandler(sb, "ALL")).end();
.rule().async(async).handler(new WxEchoCpMessageHandler(sb, "ALL")).end();
}
@Test(dataProvider = "messages-1")
@@ -138,16 +137,16 @@ public class WxCpMessageRouterTest {
return new Object[][]{
new Object[]{message1, WxConsts.XML_MSG_TEXT + ","},
new Object[]{message2, WxConsts.EVT_CLICK + ","},
new Object[]{message3, "KEY_1,"},
new Object[]{message4, "CONTENT_1,"},
new Object[]{message5, "ALL,"},
new Object[]{message6, "abcd,"},
new Object[]{message7, "matcher,"},
new Object[]{c2, "COMBINE_2,"},
new Object[]{c3, "COMBINE_3,"},
new Object[]{c4, "COMBINE_4,"}
new Object[]{message1, WxConsts.XML_MSG_TEXT + ","},
new Object[]{message2, WxConsts.EVT_CLICK + ","},
new Object[]{message3, "KEY_1,"},
new Object[]{message4, "CONTENT_1,"},
new Object[]{message5, "ALL,"},
new Object[]{message6, "abcd,"},
new Object[]{message7, "matcher,"},
new Object[]{c2, "COMBINE_2,"},
new Object[]{c3, "COMBINE_3,"},
new Object[]{c4, "COMBINE_4,"}
};
}
@@ -162,7 +161,7 @@ public class WxCpMessageRouterTest {
ism.setBackgroundProcessorDelay(1);
return new Object[][]{
new Object[]{ism}
new Object[]{ism}
};
}
@@ -174,8 +173,8 @@ public class WxCpMessageRouterTest {
final WxCpMessageRouter router = new WxCpMessageRouter(null);
router.setSessionManager(ism);
router
.rule().async(false).handler(new WxSessionMessageHandler()).next()
.rule().async(false).handler(new WxSessionMessageHandler()).end();
.rule().async(false).handler(new WxSessionMessageHandler()).next()
.rule().async(false).handler(new WxSessionMessageHandler()).end();
WxCpXmlMessage msg = new WxCpXmlMessage();
msg.setFromUserName("abc");
@@ -194,8 +193,8 @@ public class WxCpMessageRouterTest {
final WxCpMessageRouter router = new WxCpMessageRouter(null);
router.setSessionManager(ism);
router
.rule().async(false).handler(new WxSessionMessageHandler()).next()
.rule().async(true).handler(new WxSessionMessageHandler()).end();
.rule().async(false).handler(new WxSessionMessageHandler()).next()
.rule().async(true).handler(new WxSessionMessageHandler()).end();
WxCpXmlMessage msg = new WxCpXmlMessage();
msg.setFromUserName("abc");
@@ -208,8 +207,8 @@ public class WxCpMessageRouterTest {
final WxCpMessageRouter router = new WxCpMessageRouter(null);
router.setSessionManager(ism);
router
.rule().async(true).handler(new WxSessionMessageHandler()).next()
.rule().async(false).handler(new WxSessionMessageHandler()).end();
.rule().async(true).handler(new WxSessionMessageHandler()).next()
.rule().async(false).handler(new WxSessionMessageHandler()).end();
WxCpXmlMessage msg = new WxCpXmlMessage();
msg.setFromUserName("abc");
@@ -228,8 +227,8 @@ public class WxCpMessageRouterTest {
final WxCpMessageRouter router = new WxCpMessageRouter(null);
router.setSessionManager(ism);
router
.rule().async(true).handler(new WxSessionMessageHandler()).next()
.rule().async(true).handler(new WxSessionMessageHandler()).end();
.rule().async(true).handler(new WxSessionMessageHandler()).next()
.rule().async(true).handler(new WxSessionMessageHandler()).end();
WxCpXmlMessage msg = new WxCpXmlMessage();
msg.setFromUserName("abc");
@@ -248,7 +247,7 @@ public class WxCpMessageRouterTest {
final WxCpMessageRouter router = new WxCpMessageRouter(null);
router.setSessionManager(ism);
router
.rule().async(false).handler(new WxSessionMessageHandler()).end();
.rule().async(false).handler(new WxSessionMessageHandler()).end();
WxCpXmlMessage msg = new WxCpXmlMessage();
msg.setFromUserName("abc");
@@ -262,7 +261,7 @@ public class WxCpMessageRouterTest {
final WxCpMessageRouter router = new WxCpMessageRouter(null);
router.setSessionManager(ism);
router
.rule().async(true).handler(new WxSessionMessageHandler()).end();
.rule().async(true).handler(new WxSessionMessageHandler()).end();
WxCpXmlMessage msg = new WxCpXmlMessage();
msg.setFromUserName("abc");

View File

@@ -4,9 +4,8 @@ import com.google.inject.Inject;
import me.chanjar.weixin.cp.api.impl.apache.WxCpServiceImpl;
import me.chanjar.weixin.cp.bean.WxCpTag;
import me.chanjar.weixin.cp.bean.WxCpUser;
import org.testng.Assert;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import org.testng.*;
import org.testng.annotations.*;
import java.util.ArrayList;
import java.util.List;

View File

@@ -5,9 +5,8 @@ import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.cp.api.impl.apache.WxCpServiceImpl;
import me.chanjar.weixin.cp.bean.WxCpDepart;
import me.chanjar.weixin.cp.bean.WxCpUser;
import org.testng.Assert;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import org.testng.*;
import org.testng.annotations.*;
import java.util.List;

View File

@@ -6,10 +6,8 @@ import me.chanjar.weixin.common.bean.menu.WxMenu;
import me.chanjar.weixin.common.bean.menu.WxMenuButton;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.cp.api.impl.apache.WxCpServiceImpl;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import org.testng.*;
import org.testng.annotations.*;
/**
* 测试菜单
@@ -78,9 +76,9 @@ public class WxMenuAPITest {
button3.getSubButtons().add(button33);
return new Object[][]{
new Object[]{
menu
}
new Object[]{
menu
}
};
}

View File

@@ -5,9 +5,8 @@ import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.cp.api.ApiTestModule;
import me.chanjar.weixin.cp.api.WxCpConfigStorage;
import org.apache.commons.lang3.StringUtils;
import org.testng.Assert;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import org.testng.*;
import org.testng.annotations.*;
/**
* 基础API测试

View File

@@ -4,8 +4,7 @@ import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.cp.api.WxCpService;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.testng.annotations.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
@@ -22,7 +21,7 @@ public class WxCpBusyRetryTest {
@Override
public synchronized <T, E> T executeInternal(
RequestExecutor<T, E> executor, String uri, E data)
throws WxErrorException {
throws WxErrorException {
this.log.info("Executed");
WxError error = new WxError();
error.setErrorCode(-1);
@@ -33,7 +32,7 @@ public class WxCpBusyRetryTest {
service.setMaxRetryTimes(3);
service.setRetrySleepMillis(500);
return new Object[][]{
new Object[]{service}
new Object[]{service}
};
}

View File

@@ -5,8 +5,7 @@ import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.cp.api.ApiTestModule;
import me.chanjar.weixin.cp.bean.WxCpMessage;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import org.testng.annotations.*;
/***
* 测试发送消息
@@ -30,11 +29,11 @@ public class WxCpMessageAPITest {
this.wxService.messageSend(message1);
WxCpMessage message2 = WxCpMessage
.TEXT()
.agentId(configStorage.getAgentId())
.toUser(configStorage.getUserId())
.content("欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>")
.build();
.TEXT()
.agentId(configStorage.getAgentId())
.toUser(configStorage.getUserId())
.content("欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>")
.build();
this.wxService.messageSend(message2);
}

View File

@@ -1,12 +1,11 @@
package me.chanjar.weixin.cp.bean;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.cp.bean.article.NewArticle;
import me.chanjar.weixin.cp.bean.article.MpnewsArticle;
import org.testng.Assert;
import org.testng.annotations.Test;
import me.chanjar.weixin.cp.bean.article.NewArticle;
import org.testng.annotations.*;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.*;
@Test
public class WxCpMessageTest {

View File

@@ -1,8 +1,8 @@
package me.chanjar.weixin.cp.bean;
import me.chanjar.weixin.common.api.WxConsts;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.testng.*;
import org.testng.annotations.*;
@Test
public class WxCpXmlMessageTest {
@@ -10,49 +10,49 @@ public class WxCpXmlMessageTest {
public void testFromXml() {
String xml = "<xml>"
+ "<ToUserName><![CDATA[toUser]]></ToUserName>"
+ "<FromUserName><![CDATA[fromUser]]></FromUserName> "
+ "<CreateTime>1348831860</CreateTime>"
+ "<MsgType><![CDATA[text]]></MsgType>"
+ "<Content><![CDATA[this is a test]]></Content>"
+ "<MsgId>1234567890123456</MsgId>"
+ "<PicUrl><![CDATA[this is a url]]></PicUrl>"
+ "<MediaId><![CDATA[media_id]]></MediaId>"
+ "<Format><![CDATA[Format]]></Format>"
+ "<ThumbMediaId><![CDATA[thumb_media_id]]></ThumbMediaId>"
+ "<Location_X>23.134521</Location_X>"
+ "<Location_Y>113.358803</Location_Y>"
+ "<Scale>20</Scale>"
+ "<Label><![CDATA[位置信息]]></Label>"
+ "<Description><![CDATA[公众平台官网链接]]></Description>"
+ "<Url><![CDATA[url]]></Url>"
+ "<Title><![CDATA[公众平台官网链接]]></Title>"
+ "<Event><![CDATA[subscribe]]></Event>"
+ "<EventKey><![CDATA[qrscene_123123]]></EventKey>"
+ "<Ticket><![CDATA[TICKET]]></Ticket>"
+ "<Latitude>23.137466</Latitude>"
+ "<Longitude>113.352425</Longitude>"
+ "<Precision>119.385040</Precision>"
+ "<ScanCodeInfo>"
+ " <ScanType><![CDATA[qrcode]]></ScanType>"
+ " <ScanResult><![CDATA[1]]></ScanResult>"
+ "</ScanCodeInfo>"
+ "<SendPicsInfo>"
+ " <Count>1</Count>\n"
+ " <PicList>"
+ " <item>"
+ " <PicMd5Sum><![CDATA[1b5f7c23b5bf75682a53e7b6d163e185]]></PicMd5Sum>"
+ " </item>"
+ " </PicList>"
+ "</SendPicsInfo>"
+ "<SendLocationInfo>"
+ " <Location_X><![CDATA[23]]></Location_X>\n"
+ " <Location_Y><![CDATA[113]]></Location_Y>\n"
+ " <Scale><![CDATA[15]]></Scale>\n"
+ " <Label><![CDATA[ 广州市海珠区客村艺苑路 106号]]></Label>\n"
+ " <Poiname><![CDATA[wo de poi]]></Poiname>\n"
+ "</SendLocationInfo>"
+ "</xml>";
+ "<ToUserName><![CDATA[toUser]]></ToUserName>"
+ "<FromUserName><![CDATA[fromUser]]></FromUserName> "
+ "<CreateTime>1348831860</CreateTime>"
+ "<MsgType><![CDATA[text]]></MsgType>"
+ "<Content><![CDATA[this is a test]]></Content>"
+ "<MsgId>1234567890123456</MsgId>"
+ "<PicUrl><![CDATA[this is a url]]></PicUrl>"
+ "<MediaId><![CDATA[media_id]]></MediaId>"
+ "<Format><![CDATA[Format]]></Format>"
+ "<ThumbMediaId><![CDATA[thumb_media_id]]></ThumbMediaId>"
+ "<Location_X>23.134521</Location_X>"
+ "<Location_Y>113.358803</Location_Y>"
+ "<Scale>20</Scale>"
+ "<Label><![CDATA[位置信息]]></Label>"
+ "<Description><![CDATA[公众平台官网链接]]></Description>"
+ "<Url><![CDATA[url]]></Url>"
+ "<Title><![CDATA[公众平台官网链接]]></Title>"
+ "<Event><![CDATA[subscribe]]></Event>"
+ "<EventKey><![CDATA[qrscene_123123]]></EventKey>"
+ "<Ticket><![CDATA[TICKET]]></Ticket>"
+ "<Latitude>23.137466</Latitude>"
+ "<Longitude>113.352425</Longitude>"
+ "<Precision>119.385040</Precision>"
+ "<ScanCodeInfo>"
+ " <ScanType><![CDATA[qrcode]]></ScanType>"
+ " <ScanResult><![CDATA[1]]></ScanResult>"
+ "</ScanCodeInfo>"
+ "<SendPicsInfo>"
+ " <Count>1</Count>\n"
+ " <PicList>"
+ " <item>"
+ " <PicMd5Sum><![CDATA[1b5f7c23b5bf75682a53e7b6d163e185]]></PicMd5Sum>"
+ " </item>"
+ " </PicList>"
+ "</SendPicsInfo>"
+ "<SendLocationInfo>"
+ " <Location_X><![CDATA[23]]></Location_X>\n"
+ " <Location_Y><![CDATA[113]]></Location_Y>\n"
+ " <Scale><![CDATA[15]]></Scale>\n"
+ " <Label><![CDATA[ 广州市海珠区客村艺苑路 106号]]></Label>\n"
+ " <Poiname><![CDATA[wo de poi]]></Poiname>\n"
+ "</SendLocationInfo>"
+ "</xml>";
WxCpXmlMessage wxMessage = WxCpXmlMessage.fromXml(xml);
Assert.assertEquals(wxMessage.getToUserName(), "toUser");
Assert.assertEquals(wxMessage.getFromUserName(), "fromUser");

View File

@@ -1,7 +1,7 @@
package me.chanjar.weixin.cp.bean;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.testng.*;
import org.testng.annotations.*;
@Test
public class WxCpXmlOutImageMessageTest {
@@ -14,12 +14,12 @@ public class WxCpXmlOutImageMessageTest {
m.setToUserName("to");
String expected = "<xml>"
+ "<ToUserName><![CDATA[to]]></ToUserName>"
+ "<FromUserName><![CDATA[from]]></FromUserName>"
+ "<CreateTime>1122</CreateTime>"
+ "<MsgType><![CDATA[image]]></MsgType>"
+ "<Image><MediaId><![CDATA[ddfefesfsdfef]]></MediaId></Image>"
+ "</xml>";
+ "<ToUserName><![CDATA[to]]></ToUserName>"
+ "<FromUserName><![CDATA[from]]></FromUserName>"
+ "<CreateTime>1122</CreateTime>"
+ "<MsgType><![CDATA[image]]></MsgType>"
+ "<Image><MediaId><![CDATA[ddfefesfsdfef]]></MediaId></Image>"
+ "</xml>";
System.out.println(m.toXml());
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", ""));
}
@@ -27,21 +27,21 @@ public class WxCpXmlOutImageMessageTest {
public void testBuild() {
WxCpXmlOutImageMessage m = WxCpXmlOutMessage.IMAGE().mediaId("ddfefesfsdfef").fromUser("from").toUser("to").build();
String expected = "<xml>"
+ "<ToUserName><![CDATA[to]]></ToUserName>"
+ "<FromUserName><![CDATA[from]]></FromUserName>"
+ "<CreateTime>1122</CreateTime>"
+ "<MsgType><![CDATA[image]]></MsgType>"
+ "<Image><MediaId><![CDATA[ddfefesfsdfef]]></MediaId></Image>"
+ "</xml>";
+ "<ToUserName><![CDATA[to]]></ToUserName>"
+ "<FromUserName><![CDATA[from]]></FromUserName>"
+ "<CreateTime>1122</CreateTime>"
+ "<MsgType><![CDATA[image]]></MsgType>"
+ "<Image><MediaId><![CDATA[ddfefesfsdfef]]></MediaId></Image>"
+ "</xml>";
System.out.println(m.toXml());
Assert.assertEquals(
m
.toXml()
.replaceAll("\\s", "")
.replaceAll("<CreateTime>.*?</CreateTime>", ""),
expected
.replaceAll("\\s", "")
.replaceAll("<CreateTime>.*?</CreateTime>", "")
m
.toXml()
.replaceAll("\\s", "")
.replaceAll("<CreateTime>.*?</CreateTime>", ""),
expected
.replaceAll("\\s", "")
.replaceAll("<CreateTime>.*?</CreateTime>", "")
);
}

View File

@@ -1,7 +1,7 @@
package me.chanjar.weixin.cp.bean;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.testng.*;
import org.testng.annotations.*;
@Test
public class WxCpXmlOutNewsMessageTest {
@@ -21,26 +21,26 @@ public class WxCpXmlOutNewsMessageTest {
m.addArticle(item);
String expected = "<xml>"
+ "<ToUserName><![CDATA[toUser]]></ToUserName>"
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>"
+ "<CreateTime>1122</CreateTime>"
+ "<MsgType><![CDATA[news]]></MsgType>"
+ " <Articles>"
+ " <item>"
+ " <Title><![CDATA[title]]></Title>"
+ " <Description><![CDATA[description]]></Description>"
+ " <PicUrl><![CDATA[picUrl]]></PicUrl>"
+ " <Url><![CDATA[url]]></Url>"
+ " </item>"
+ " <item>"
+ " <Title><![CDATA[title]]></Title>"
+ " <Description><![CDATA[description]]></Description>"
+ " <PicUrl><![CDATA[picUrl]]></PicUrl>"
+ " <Url><![CDATA[url]]></Url>"
+ " </item>"
+ " </Articles>"
+ " <ArticleCount>2</ArticleCount>"
+ "</xml>";
+ "<ToUserName><![CDATA[toUser]]></ToUserName>"
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>"
+ "<CreateTime>1122</CreateTime>"
+ "<MsgType><![CDATA[news]]></MsgType>"
+ " <Articles>"
+ " <item>"
+ " <Title><![CDATA[title]]></Title>"
+ " <Description><![CDATA[description]]></Description>"
+ " <PicUrl><![CDATA[picUrl]]></PicUrl>"
+ " <Url><![CDATA[url]]></Url>"
+ " </item>"
+ " <item>"
+ " <Title><![CDATA[title]]></Title>"
+ " <Description><![CDATA[description]]></Description>"
+ " <PicUrl><![CDATA[picUrl]]></PicUrl>"
+ " <Url><![CDATA[url]]></Url>"
+ " </item>"
+ " </Articles>"
+ " <ArticleCount>2</ArticleCount>"
+ "</xml>";
System.out.println(m.toXml());
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", ""));
}
@@ -53,41 +53,41 @@ public class WxCpXmlOutNewsMessageTest {
item.setUrl("url");
WxCpXmlOutNewsMessage m = WxCpXmlOutMessage.NEWS()
.fromUser("fromUser")
.toUser("toUser")
.addArticle(item)
.addArticle(item)
.build();
.fromUser("fromUser")
.toUser("toUser")
.addArticle(item)
.addArticle(item)
.build();
String expected = "<xml>"
+ "<ToUserName><![CDATA[toUser]]></ToUserName>"
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>"
+ "<CreateTime>1122</CreateTime>"
+ "<MsgType><![CDATA[news]]></MsgType>"
+ " <Articles>"
+ " <item>"
+ " <Title><![CDATA[title]]></Title>"
+ " <Description><![CDATA[description]]></Description>"
+ " <PicUrl><![CDATA[picUrl]]></PicUrl>"
+ " <Url><![CDATA[url]]></Url>"
+ " </item>"
+ " <item>"
+ " <Title><![CDATA[title]]></Title>"
+ " <Description><![CDATA[description]]></Description>"
+ " <PicUrl><![CDATA[picUrl]]></PicUrl>"
+ " <Url><![CDATA[url]]></Url>"
+ " </item>"
+ " </Articles>"
+ " <ArticleCount>2</ArticleCount>"
+ "</xml>";
+ "<ToUserName><![CDATA[toUser]]></ToUserName>"
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>"
+ "<CreateTime>1122</CreateTime>"
+ "<MsgType><![CDATA[news]]></MsgType>"
+ " <Articles>"
+ " <item>"
+ " <Title><![CDATA[title]]></Title>"
+ " <Description><![CDATA[description]]></Description>"
+ " <PicUrl><![CDATA[picUrl]]></PicUrl>"
+ " <Url><![CDATA[url]]></Url>"
+ " </item>"
+ " <item>"
+ " <Title><![CDATA[title]]></Title>"
+ " <Description><![CDATA[description]]></Description>"
+ " <PicUrl><![CDATA[picUrl]]></PicUrl>"
+ " <Url><![CDATA[url]]></Url>"
+ " </item>"
+ " </Articles>"
+ " <ArticleCount>2</ArticleCount>"
+ "</xml>";
System.out.println(m.toXml());
Assert.assertEquals(
m
.toXml()
.replaceAll("\\s", "")
.replaceAll("<CreateTime>.*?</CreateTime>", ""),
expected
.replaceAll("\\s", "")
.replaceAll("<CreateTime>.*?</CreateTime>", "")
m
.toXml()
.replaceAll("\\s", "")
.replaceAll("<CreateTime>.*?</CreateTime>", ""),
expected
.replaceAll("\\s", "")
.replaceAll("<CreateTime>.*?</CreateTime>", "")
);
}

View File

@@ -1,7 +1,7 @@
package me.chanjar.weixin.cp.bean;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.testng.*;
import org.testng.annotations.*;
@Test
public class WxCpXmlOutTextMessageTest {
@@ -14,12 +14,12 @@ public class WxCpXmlOutTextMessageTest {
m.setToUserName("to");
String expected = "<xml>"
+ "<ToUserName><![CDATA[to]]></ToUserName>"
+ "<FromUserName><![CDATA[from]]></FromUserName>"
+ "<CreateTime>1122</CreateTime>"
+ "<MsgType><![CDATA[text]]></MsgType>"
+ "<Content><![CDATA[content]]></Content>"
+ "</xml>";
+ "<ToUserName><![CDATA[to]]></ToUserName>"
+ "<FromUserName><![CDATA[from]]></FromUserName>"
+ "<CreateTime>1122</CreateTime>"
+ "<MsgType><![CDATA[text]]></MsgType>"
+ "<Content><![CDATA[content]]></Content>"
+ "</xml>";
System.out.println(m.toXml());
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", ""));
}
@@ -27,21 +27,21 @@ public class WxCpXmlOutTextMessageTest {
public void testBuild() {
WxCpXmlOutTextMessage m = WxCpXmlOutMessage.TEXT().content("content").fromUser("from").toUser("to").build();
String expected = "<xml>"
+ "<ToUserName><![CDATA[to]]></ToUserName>"
+ "<FromUserName><![CDATA[from]]></FromUserName>"
+ "<CreateTime>1122</CreateTime>"
+ "<MsgType><![CDATA[text]]></MsgType>"
+ "<Content><![CDATA[content]]></Content>"
+ "</xml>";
+ "<ToUserName><![CDATA[to]]></ToUserName>"
+ "<FromUserName><![CDATA[from]]></FromUserName>"
+ "<CreateTime>1122</CreateTime>"
+ "<MsgType><![CDATA[text]]></MsgType>"
+ "<Content><![CDATA[content]]></Content>"
+ "</xml>";
System.out.println(m.toXml());
Assert.assertEquals(
m
.toXml()
.replaceAll("\\s", "")
.replaceAll("<CreateTime>.*?</CreateTime>", ""),
expected
.replaceAll("\\s", "")
.replaceAll("<CreateTime>.*?</CreateTime>", "")
m
.toXml()
.replaceAll("\\s", "")
.replaceAll("<CreateTime>.*?</CreateTime>", ""),
expected
.replaceAll("\\s", "")
.replaceAll("<CreateTime>.*?</CreateTime>", "")
);
}

View File

@@ -1,7 +1,7 @@
package me.chanjar.weixin.cp.bean;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.testng.*;
import org.testng.annotations.*;
@Test
public class WxCpXmlOutVideoMessageTest {
@@ -16,48 +16,48 @@ public class WxCpXmlOutVideoMessageTest {
m.setToUserName("toUser");
String expected = "<xml>"
+ "<ToUserName><![CDATA[toUser]]></ToUserName>"
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>"
+ "<CreateTime>1122</CreateTime>"
+ "<MsgType><![CDATA[video]]></MsgType>"
+ "<Video>"
+ "<MediaId><![CDATA[media_id]]></MediaId>"
+ "<Title><![CDATA[title]]></Title>"
+ "<Description><![CDATA[ddfff]]></Description>"
+ "</Video> "
+ "</xml>";
+ "<ToUserName><![CDATA[toUser]]></ToUserName>"
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>"
+ "<CreateTime>1122</CreateTime>"
+ "<MsgType><![CDATA[video]]></MsgType>"
+ "<Video>"
+ "<MediaId><![CDATA[media_id]]></MediaId>"
+ "<Title><![CDATA[title]]></Title>"
+ "<Description><![CDATA[ddfff]]></Description>"
+ "</Video> "
+ "</xml>";
System.out.println(m.toXml());
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", ""));
}
public void testBuild() {
WxCpXmlOutVideoMessage m = WxCpXmlOutMessage.VIDEO()
.mediaId("media_id")
.fromUser("fromUser")
.toUser("toUser")
.title("title")
.description("ddfff")
.build();
.mediaId("media_id")
.fromUser("fromUser")
.toUser("toUser")
.title("title")
.description("ddfff")
.build();
String expected = "<xml>"
+ "<ToUserName><![CDATA[toUser]]></ToUserName>"
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>"
+ "<CreateTime>1122</CreateTime>"
+ "<MsgType><![CDATA[video]]></MsgType>"
+ "<Video>"
+ "<MediaId><![CDATA[media_id]]></MediaId>"
+ "<Title><![CDATA[title]]></Title>"
+ "<Description><![CDATA[ddfff]]></Description>"
+ "</Video> "
+ "</xml>";
+ "<ToUserName><![CDATA[toUser]]></ToUserName>"
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>"
+ "<CreateTime>1122</CreateTime>"
+ "<MsgType><![CDATA[video]]></MsgType>"
+ "<Video>"
+ "<MediaId><![CDATA[media_id]]></MediaId>"
+ "<Title><![CDATA[title]]></Title>"
+ "<Description><![CDATA[ddfff]]></Description>"
+ "</Video> "
+ "</xml>";
System.out.println(m.toXml());
Assert.assertEquals(
m
.toXml()
.replaceAll("\\s", "")
.replaceAll("<CreateTime>.*?</CreateTime>", ""),
expected
.replaceAll("\\s", "")
.replaceAll("<CreateTime>.*?</CreateTime>", "")
m
.toXml()
.replaceAll("\\s", "")
.replaceAll("<CreateTime>.*?</CreateTime>", ""),
expected
.replaceAll("\\s", "")
.replaceAll("<CreateTime>.*?</CreateTime>", "")
);
}

View File

@@ -1,7 +1,7 @@
package me.chanjar.weixin.cp.bean;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.testng.*;
import org.testng.annotations.*;
@Test
public class WxCpXmlOutVoiceMessageTest {
@@ -14,12 +14,12 @@ public class WxCpXmlOutVoiceMessageTest {
m.setToUserName("to");
String expected = "<xml>"
+ "<ToUserName><![CDATA[to]]></ToUserName>"
+ "<FromUserName><![CDATA[from]]></FromUserName>"
+ "<CreateTime>1122</CreateTime>"
+ "<MsgType><![CDATA[voice]]></MsgType>"
+ "<Voice><MediaId><![CDATA[ddfefesfsdfef]]></MediaId></Voice>"
+ "</xml>";
+ "<ToUserName><![CDATA[to]]></ToUserName>"
+ "<FromUserName><![CDATA[from]]></FromUserName>"
+ "<CreateTime>1122</CreateTime>"
+ "<MsgType><![CDATA[voice]]></MsgType>"
+ "<Voice><MediaId><![CDATA[ddfefesfsdfef]]></MediaId></Voice>"
+ "</xml>";
System.out.println(m.toXml());
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", ""));
}
@@ -27,21 +27,21 @@ public class WxCpXmlOutVoiceMessageTest {
public void testBuild() {
WxCpXmlOutVoiceMessage m = WxCpXmlOutMessage.VOICE().mediaId("ddfefesfsdfef").fromUser("from").toUser("to").build();
String expected = "<xml>"
+ "<ToUserName><![CDATA[to]]></ToUserName>"
+ "<FromUserName><![CDATA[from]]></FromUserName>"
+ "<CreateTime>1122</CreateTime>"
+ "<MsgType><![CDATA[voice]]></MsgType>"
+ "<Voice><MediaId><![CDATA[ddfefesfsdfef]]></MediaId></Voice>"
+ "</xml>";
+ "<ToUserName><![CDATA[to]]></ToUserName>"
+ "<FromUserName><![CDATA[from]]></FromUserName>"
+ "<CreateTime>1122</CreateTime>"
+ "<MsgType><![CDATA[voice]]></MsgType>"
+ "<Voice><MediaId><![CDATA[ddfefesfsdfef]]></MediaId></Voice>"
+ "</xml>";
System.out.println(m.toXml());
Assert.assertEquals(
m
.toXml()
.replaceAll("\\s", "")
.replaceAll("<CreateTime>.*?</CreateTime>", ""),
expected
.replaceAll("\\s", "")
.replaceAll("<CreateTime>.*?</CreateTime>", "")
m
.toXml()
.replaceAll("\\s", "")
.replaceAll("<CreateTime>.*?</CreateTime>", ""),
expected
.replaceAll("\\s", "")
.replaceAll("<CreateTime>.*?</CreateTime>", "")
);
}

View File

@@ -22,7 +22,7 @@ class WxCpDemoInMemoryConfigStorage extends WxCpInMemoryConfigStorage {
@Override
public String toString() {
return "SimpleWxConfigProvider [appidOrCorpid=" + this.corpId + ", corpSecret=" + this.corpSecret + ", accessToken=" + this.accessToken
+ ", expiresTime=" + this.expiresTime + ", token=" + this.token + ", aesKey=" + this.aesKey + "]";
+ ", expiresTime=" + this.expiresTime + ", token=" + this.token + ", aesKey=" + this.aesKey + "]";
}
}

View File

@@ -1,13 +1,5 @@
package me.chanjar.weixin.cp.demo;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.cp.api.WxCpConfigStorage;
import me.chanjar.weixin.cp.api.WxCpMessageHandler;
@@ -17,6 +9,13 @@ import me.chanjar.weixin.cp.api.impl.apache.WxCpServiceImpl;
import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlOutTextMessage;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
public class WxCpDemoServer {
@@ -44,9 +43,9 @@ public class WxCpDemoServer {
private static void initWeixin() throws IOException {
try (InputStream is1 = ClassLoader
.getSystemResourceAsStream("test-config.xml")) {
.getSystemResourceAsStream("test-config.xml")) {
WxCpDemoInMemoryConfigStorage config = WxCpDemoInMemoryConfigStorage
.fromXml(is1);
.fromXml(is1);
wxCpConfigStorage = config;
wxCpService = new WxCpServiceImpl();
@@ -55,11 +54,11 @@ public class WxCpDemoServer {
WxCpMessageHandler handler = new WxCpMessageHandler() {
@Override
public WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage,
Map<String, Object> context, WxCpService wxService,
WxSessionManager sessionManager) {
Map<String, Object> context, WxCpService wxService,
WxSessionManager sessionManager) {
WxCpXmlOutTextMessage m = WxCpXmlOutMessage.TEXT().content("测试加密消息")
.fromUser(wxMessage.getToUserName())
.toUser(wxMessage.getFromUserName()).build();
.fromUser(wxMessage.getToUserName())
.toUser(wxMessage.getFromUserName()).build();
return m;
}
};
@@ -67,22 +66,22 @@ public class WxCpDemoServer {
WxCpMessageHandler oauth2handler = new WxCpMessageHandler() {
@Override
public WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage,
Map<String, Object> context, WxCpService wxService,
WxSessionManager sessionManager) {
Map<String, Object> context, WxCpService wxService,
WxSessionManager sessionManager) {
String href = "<a href=\""
+ wxService.oauth2buildAuthorizationUrl(
wxCpConfigStorage.getOauth2redirectUri(), null)
+ "\">测试oauth2</a>";
+ wxService.oauth2buildAuthorizationUrl(
wxCpConfigStorage.getOauth2redirectUri(), null)
+ "\">测试oauth2</a>";
return WxCpXmlOutMessage.TEXT().content(href)
.fromUser(wxMessage.getToUserName())
.toUser(wxMessage.getFromUserName()).build();
.fromUser(wxMessage.getToUserName())
.toUser(wxMessage.getFromUserName()).build();
}
};
wxCpMessageRouter = new WxCpMessageRouter(wxCpService);
wxCpMessageRouter.rule().async(false).content("哈哈") // 拦截内容为“哈哈”的消息
.handler(handler).end().rule().async(false).content("oauth")
.handler(oauth2handler).end();
.handler(handler).end().rule().async(false).content("oauth")
.handler(oauth2handler).end();
}
}

View File

@@ -31,7 +31,7 @@ public class WxCpEndpointServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws IOException {
throws IOException {
response.setContentType("text/html;charset=utf-8");
response.setStatus(HttpServletResponse.SC_OK);
@@ -55,7 +55,7 @@ public class WxCpEndpointServlet extends HttpServlet {
}
WxCpXmlMessage inMessage = WxCpXmlMessage
.fromEncryptedXml(request.getInputStream(), this.wxCpConfigStorage, timestamp, nonce, msgSignature);
.fromEncryptedXml(request.getInputStream(), this.wxCpConfigStorage, timestamp, nonce, msgSignature);
WxCpXmlOutMessage outMessage = this.wxCpMessageRouter.route(inMessage);
if (outMessage != null) {
response.getWriter().write(outMessage.toEncryptedXml(this.wxCpConfigStorage));

View File

@@ -1,14 +1,13 @@
package me.chanjar.weixin.cp.demo;
import java.io.IOException;
import java.util.Arrays;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpService;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpService;
import java.io.IOException;
import java.util.Arrays;
public class WxCpOAuth2Servlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@@ -21,7 +20,7 @@ public class WxCpOAuth2Servlet extends HttpServlet {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws IOException {
throws IOException {
response.setContentType("text/html;charset=utf-8");
response.setStatus(HttpServletResponse.SC_OK);

View File

@@ -9,8 +9,8 @@
</appender>
<root level="info">
<appender-ref ref="STDOUT" />
<appender-ref ref="STDOUT"/>
</root>
<logger name="me.chanjar.weixin.cp" level="debug" />
<logger name="me.chanjar.weixin.cp" level="debug"/>
</configuration>

View File

@@ -1,13 +1,13 @@
<xml>
<corpId>企业号corpid</corpId>
<corpSecret>企业号corpsecret</corpSecret>
<agentId>企业号应用id</agentId>
<token>企业号应用Token</token>
<aesKey>企业号应用EncodingAESKey</aesKey>
<accessToken>可以不填写</accessToken>
<expiresTime>可以不填写</expiresTime>
<userId>企业号通讯录里的某个userid</userId>
<departmentId>企业号通讯录的某个部门id</departmentId>
<tagId>企业号通讯录里的某个tagid</tagId>
<oauth2redirectUri>网页授权获取用户信息回调地址</oauth2redirectUri>
<corpId>企业号corpid</corpId>
<corpSecret>企业号corpsecret</corpSecret>
<agentId>企业号应用id</agentId>
<token>企业号应用Token</token>
<aesKey>企业号应用EncodingAESKey</aesKey>
<accessToken>可以不填写</accessToken>
<expiresTime>可以不填写</expiresTime>
<userId>企业号通讯录里的某个userid</userId>
<departmentId>企业号通讯录的某个部门id</departmentId>
<tagId>企业号通讯录里的某个tagid</tagId>
<oauth2redirectUri>网页授权获取用户信息回调地址</oauth2redirectUri>
</xml>