]";
+ }
+
+ return result.deleteCharAt(result.length() - 1).toString();
+ }
+}
diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/WxCryptUtil.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/WxCryptUtil.java
index fead486e..a809fe3b 100755
--- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/WxCryptUtil.java
+++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/WxCryptUtil.java
@@ -1,300 +1,300 @@
-/**
- * 对公众平台发送给公众账号的消息加解密示例代码.
- *
- * @copyright Copyright (c) 1998-2014 Tencent Inc.
- *
- * 针对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.common.util.crypto;
-
-import java.io.StringReader;
-import java.nio.charset.Charset;
-import java.util.Arrays;
-import java.util.Random;
-
-import javax.crypto.Cipher;
-import javax.crypto.spec.IvParameterSpec;
-import javax.crypto.spec.SecretKeySpec;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.apache.commons.codec.binary.Base64;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.xml.sax.InputSource;
-
-public class WxCryptUtil {
-
- private static final Base64 base64 = new Base64();
- private static final Charset CHARSET = Charset.forName("utf-8");
-
- private static final ThreadLocal builderLocal = new ThreadLocal() {
- @Override
- protected DocumentBuilder initialValue() {
- try {
- return DocumentBuilderFactory.newInstance().newDocumentBuilder();
- } catch (ParserConfigurationException exc) {
- throw new IllegalArgumentException(exc);
- }
- }
- };
-
- protected byte[] aesKey;
- protected String token;
- protected String appidOrCorpid;
-
- public WxCryptUtil() {
- super();
- }
-
- /**
- * 构造函数
- *
- * @param token 公众平台上,开发者设置的token
- * @param encodingAesKey 公众平台上,开发者设置的EncodingAESKey
- * @param appidOrCorpid 公众平台appid/corpid
- */
- public WxCryptUtil(String token, String encodingAesKey,
- String appidOrCorpid) {
- this.token = token;
- this.appidOrCorpid = appidOrCorpid;
- this.aesKey = Base64.decodeBase64(encodingAesKey + "=");
- }
-
- static String extractEncryptPart(String xml) {
- try {
- DocumentBuilder db = builderLocal.get();
- Document document = db.parse(new InputSource(new StringReader(xml)));
-
- Element root = document.getDocumentElement();
- return root.getElementsByTagName("Encrypt").item(0).getTextContent();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * 将公众平台回复用户的消息加密打包.
- *
- * - 对要发送的消息进行AES-CBC加密
- * - 生成安全签名
- * - 将消息密文和安全签名打包成xml格式
- *
- *
- * @param plainText 公众平台待回复用户的消息,xml格式的字符串
- * @return 加密后的可以直接回复用户的密文,包括msg_signature, timestamp, nonce, encrypt的xml格式的字符串
- */
- public String encrypt(String plainText) {
- // 加密
- String encryptedXml = encrypt(genRandomStr(), plainText);
-
- // 生成安全签名
- String timeStamp = Long.toString(System.currentTimeMillis() / 1000l);
- String nonce = genRandomStr();
-
- String signature = SHA1.gen(this.token, timeStamp, nonce, encryptedXml);
- String result = generateXml(encryptedXml, signature, timeStamp, nonce);
- return result;
- }
-
- /**
- * 对明文进行加密.
- *
- * @param plainText 需要加密的明文
- * @return 加密后base64编码的字符串
- */
- protected String encrypt(String randomStr, String plainText) {
- ByteGroup byteCollector = new ByteGroup();
- byte[] randomStringBytes = randomStr.getBytes(CHARSET);
- byte[] plainTextBytes = plainText.getBytes(CHARSET);
- byte[] bytesOfSizeInNetworkOrder = number2BytesInNetworkOrder(
- plainTextBytes.length);
- byte[] appIdBytes = this.appidOrCorpid.getBytes(CHARSET);
-
- // randomStr + networkBytesOrder + text + appid
- byteCollector.addBytes(randomStringBytes);
- byteCollector.addBytes(bytesOfSizeInNetworkOrder);
- byteCollector.addBytes(plainTextBytes);
- byteCollector.addBytes(appIdBytes);
-
- // ... + pad: 使用自定义的填充方式对明文进行补位填充
- byte[] padBytes = PKCS7Encoder.encode(byteCollector.size());
- byteCollector.addBytes(padBytes);
-
- // 获得最终的字节流, 未加密
- byte[] unencrypted = byteCollector.toBytes();
-
- try {
- // 设置加密模式为AES的CBC模式
- Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
- SecretKeySpec keySpec = new SecretKeySpec(this.aesKey, "AES");
- IvParameterSpec iv = new IvParameterSpec(this.aesKey, 0, 16);
- cipher.init(Cipher.ENCRYPT_MODE, keySpec, iv);
-
- // 加密
- byte[] encrypted = cipher.doFinal(unencrypted);
-
- // 使用BASE64对加密后的字符串进行编码
- String base64Encrypted = base64.encodeToString(encrypted);
-
- return base64Encrypted;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * 检验消息的真实性,并且获取解密后的明文.
- *
- * - 利用收到的密文生成安全签名,进行签名验证
- * - 若验证通过,则提取xml中的加密消息
- * - 对消息进行解密
- *
- *
- * @param msgSignature 签名串,对应URL参数的msg_signature
- * @param timeStamp 时间戳,对应URL参数的timestamp
- * @param nonce 随机串,对应URL参数的nonce
- * @param encryptedXml 密文,对应POST请求的数据
- * @return 解密后的原文
- */
- public String decrypt(String msgSignature, String timeStamp, String nonce,
- String encryptedXml) {
- // 密钥,公众账号的app corpSecret
- // 提取密文
- String cipherText = extractEncryptPart(encryptedXml);
-
- // 验证安全签名
- String signature = SHA1.gen(this.token, timeStamp, nonce, cipherText);
- if (!signature.equals(msgSignature)) {
- throw new RuntimeException("加密消息签名校验失败");
- }
-
- // 解密
- String result = decrypt(cipherText);
- return result;
- }
-
- /**
- * 对密文进行解密.
- *
- * @param cipherText 需要解密的密文
- * @return 解密得到的明文
- */
- public String decrypt(String cipherText) {
- byte[] original;
- try {
- // 设置解密模式为AES的CBC模式
- Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
- SecretKeySpec key_spec = new SecretKeySpec(this.aesKey, "AES");
- IvParameterSpec iv = new IvParameterSpec(
- Arrays.copyOfRange(this.aesKey, 0, 16));
- cipher.init(Cipher.DECRYPT_MODE, key_spec, iv);
-
- // 使用BASE64对密文进行解码
- byte[] encrypted = Base64.decodeBase64(cipherText);
-
- // 解密
- original = cipher.doFinal(encrypted);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
-
- String xmlContent, from_appid;
- try {
- // 去除补位字符
- byte[] bytes = PKCS7Encoder.decode(original);
-
- // 分离16位随机字符串,网络字节序和AppId
- byte[] networkOrder = Arrays.copyOfRange(bytes, 16, 20);
-
- int xmlLength = bytesNetworkOrder2Number(networkOrder);
-
- xmlContent = new String(Arrays.copyOfRange(bytes, 20, 20 + xmlLength),
- CHARSET);
- from_appid = new String(
- Arrays.copyOfRange(bytes, 20 + xmlLength, bytes.length), CHARSET);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
-
- // appid不相同的情况
- if (!from_appid.equals(this.appidOrCorpid)) {
- throw new RuntimeException("AppID不正确");
- }
-
- return xmlContent;
-
- }
-
- /**
- * 将一个数字转换成生成4个字节的网络字节序bytes数组
- *
- * @param number
- */
- private static byte[] number2BytesInNetworkOrder(int number) {
- byte[] orderBytes = new byte[4];
- orderBytes[3] = (byte) (number & 0xFF);
- orderBytes[2] = (byte) (number >> 8 & 0xFF);
- orderBytes[1] = (byte) (number >> 16 & 0xFF);
- orderBytes[0] = (byte) (number >> 24 & 0xFF);
- return orderBytes;
- }
-
- /**
- * 4个字节的网络字节序bytes数组还原成一个数字
- *
- * @param bytesInNetworkOrder
- */
- private static int bytesNetworkOrder2Number(byte[] bytesInNetworkOrder) {
- int sourceNumber = 0;
- for (int i = 0; i < 4; i++) {
- sourceNumber <<= 8;
- sourceNumber |= bytesInNetworkOrder[i] & 0xff;
- }
- return sourceNumber;
- }
-
- /**
- * 随机生成16位字符串
- */
- private static String genRandomStr() {
- String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
- Random random = new Random();
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < 16; i++) {
- int number = random.nextInt(base.length());
- sb.append(base.charAt(number));
- }
- return sb.toString();
- }
-
- /**
- * 生成xml消息
- *
- * @param encrypt 加密后的消息密文
- * @param signature 安全签名
- * @param timestamp 时间戳
- * @param nonce 随机字符串
- * @return 生成的xml字符串
- */
- private static String generateXml(String encrypt, String signature,
- String timestamp, String nonce) {
- String format = "\n" + "\n"
- + "\n"
- + "%3$s\n" + "\n"
- + "";
- return String.format(format, encrypt, signature, timestamp, nonce);
- }
-
-}
+/**
+ * 对公众平台发送给公众账号的消息加解密示例代码.
+ *
+ * @copyright Copyright (c) 1998-2014 Tencent Inc.
+ *
+ * 针对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.common.util.crypto;
+
+import java.io.StringReader;
+import java.nio.charset.Charset;
+import java.util.Arrays;
+import java.util.Random;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.commons.codec.binary.Base64;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.InputSource;
+
+public class WxCryptUtil {
+
+ private static final Base64 base64 = new Base64();
+ private static final Charset CHARSET = Charset.forName("utf-8");
+
+ private static final ThreadLocal builderLocal = new ThreadLocal() {
+ @Override
+ protected DocumentBuilder initialValue() {
+ try {
+ return DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ } catch (ParserConfigurationException exc) {
+ throw new IllegalArgumentException(exc);
+ }
+ }
+ };
+
+ protected byte[] aesKey;
+ protected String token;
+ protected String appidOrCorpid;
+
+ public WxCryptUtil() {
+ super();
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param token 公众平台上,开发者设置的token
+ * @param encodingAesKey 公众平台上,开发者设置的EncodingAESKey
+ * @param appidOrCorpid 公众平台appid/corpid
+ */
+ public WxCryptUtil(String token, String encodingAesKey,
+ String appidOrCorpid) {
+ this.token = token;
+ this.appidOrCorpid = appidOrCorpid;
+ this.aesKey = Base64.decodeBase64(encodingAesKey + "=");
+ }
+
+ static String extractEncryptPart(String xml) {
+ try {
+ DocumentBuilder db = builderLocal.get();
+ Document document = db.parse(new InputSource(new StringReader(xml)));
+
+ Element root = document.getDocumentElement();
+ return root.getElementsByTagName("Encrypt").item(0).getTextContent();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * 将公众平台回复用户的消息加密打包.
+ *
+ * - 对要发送的消息进行AES-CBC加密
+ * - 生成安全签名
+ * - 将消息密文和安全签名打包成xml格式
+ *
+ *
+ * @param plainText 公众平台待回复用户的消息,xml格式的字符串
+ * @return 加密后的可以直接回复用户的密文,包括msg_signature, timestamp, nonce, encrypt的xml格式的字符串
+ */
+ public String encrypt(String plainText) {
+ // 加密
+ String encryptedXml = encrypt(genRandomStr(), plainText);
+
+ // 生成安全签名
+ String timeStamp = Long.toString(System.currentTimeMillis() / 1000l);
+ String nonce = genRandomStr();
+
+ String signature = SHA1.gen(this.token, timeStamp, nonce, encryptedXml);
+ String result = generateXml(encryptedXml, signature, timeStamp, nonce);
+ return result;
+ }
+
+ /**
+ * 对明文进行加密.
+ *
+ * @param plainText 需要加密的明文
+ * @return 加密后base64编码的字符串
+ */
+ protected String encrypt(String randomStr, String plainText) {
+ ByteGroup byteCollector = new ByteGroup();
+ byte[] randomStringBytes = randomStr.getBytes(CHARSET);
+ byte[] plainTextBytes = plainText.getBytes(CHARSET);
+ byte[] bytesOfSizeInNetworkOrder = number2BytesInNetworkOrder(
+ plainTextBytes.length);
+ byte[] appIdBytes = this.appidOrCorpid.getBytes(CHARSET);
+
+ // randomStr + networkBytesOrder + text + appid
+ byteCollector.addBytes(randomStringBytes);
+ byteCollector.addBytes(bytesOfSizeInNetworkOrder);
+ byteCollector.addBytes(plainTextBytes);
+ byteCollector.addBytes(appIdBytes);
+
+ // ... + pad: 使用自定义的填充方式对明文进行补位填充
+ byte[] padBytes = PKCS7Encoder.encode(byteCollector.size());
+ byteCollector.addBytes(padBytes);
+
+ // 获得最终的字节流, 未加密
+ byte[] unencrypted = byteCollector.toBytes();
+
+ try {
+ // 设置加密模式为AES的CBC模式
+ Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
+ SecretKeySpec keySpec = new SecretKeySpec(this.aesKey, "AES");
+ IvParameterSpec iv = new IvParameterSpec(this.aesKey, 0, 16);
+ cipher.init(Cipher.ENCRYPT_MODE, keySpec, iv);
+
+ // 加密
+ byte[] encrypted = cipher.doFinal(unencrypted);
+
+ // 使用BASE64对加密后的字符串进行编码
+ String base64Encrypted = base64.encodeToString(encrypted);
+
+ return base64Encrypted;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * 检验消息的真实性,并且获取解密后的明文.
+ *
+ * - 利用收到的密文生成安全签名,进行签名验证
+ * - 若验证通过,则提取xml中的加密消息
+ * - 对消息进行解密
+ *
+ *
+ * @param msgSignature 签名串,对应URL参数的msg_signature
+ * @param timeStamp 时间戳,对应URL参数的timestamp
+ * @param nonce 随机串,对应URL参数的nonce
+ * @param encryptedXml 密文,对应POST请求的数据
+ * @return 解密后的原文
+ */
+ public String decrypt(String msgSignature, String timeStamp, String nonce,
+ String encryptedXml) {
+ // 密钥,公众账号的app corpSecret
+ // 提取密文
+ String cipherText = extractEncryptPart(encryptedXml);
+
+ // 验证安全签名
+ String signature = SHA1.gen(this.token, timeStamp, nonce, cipherText);
+ if (!signature.equals(msgSignature)) {
+ throw new RuntimeException("加密消息签名校验失败");
+ }
+
+ // 解密
+ String result = decrypt(cipherText);
+ return result;
+ }
+
+ /**
+ * 对密文进行解密.
+ *
+ * @param cipherText 需要解密的密文
+ * @return 解密得到的明文
+ */
+ public String decrypt(String cipherText) {
+ byte[] original;
+ try {
+ // 设置解密模式为AES的CBC模式
+ Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
+ SecretKeySpec key_spec = new SecretKeySpec(this.aesKey, "AES");
+ IvParameterSpec iv = new IvParameterSpec(
+ Arrays.copyOfRange(this.aesKey, 0, 16));
+ cipher.init(Cipher.DECRYPT_MODE, key_spec, iv);
+
+ // 使用BASE64对密文进行解码
+ byte[] encrypted = Base64.decodeBase64(cipherText);
+
+ // 解密
+ original = cipher.doFinal(encrypted);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ String xmlContent, from_appid;
+ try {
+ // 去除补位字符
+ byte[] bytes = PKCS7Encoder.decode(original);
+
+ // 分离16位随机字符串,网络字节序和AppId
+ byte[] networkOrder = Arrays.copyOfRange(bytes, 16, 20);
+
+ int xmlLength = bytesNetworkOrder2Number(networkOrder);
+
+ xmlContent = new String(Arrays.copyOfRange(bytes, 20, 20 + xmlLength),
+ CHARSET);
+ from_appid = new String(
+ Arrays.copyOfRange(bytes, 20 + xmlLength, bytes.length), CHARSET);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ // appid不相同的情况
+ if (!from_appid.equals(this.appidOrCorpid)) {
+ throw new RuntimeException("AppID不正确");
+ }
+
+ return xmlContent;
+
+ }
+
+ /**
+ * 将一个数字转换成生成4个字节的网络字节序bytes数组
+ *
+ * @param number
+ */
+ private static byte[] number2BytesInNetworkOrder(int number) {
+ byte[] orderBytes = new byte[4];
+ orderBytes[3] = (byte) (number & 0xFF);
+ orderBytes[2] = (byte) (number >> 8 & 0xFF);
+ orderBytes[1] = (byte) (number >> 16 & 0xFF);
+ orderBytes[0] = (byte) (number >> 24 & 0xFF);
+ return orderBytes;
+ }
+
+ /**
+ * 4个字节的网络字节序bytes数组还原成一个数字
+ *
+ * @param bytesInNetworkOrder
+ */
+ private static int bytesNetworkOrder2Number(byte[] bytesInNetworkOrder) {
+ int sourceNumber = 0;
+ for (int i = 0; i < 4; i++) {
+ sourceNumber <<= 8;
+ sourceNumber |= bytesInNetworkOrder[i] & 0xff;
+ }
+ return sourceNumber;
+ }
+
+ /**
+ * 随机生成16位字符串
+ */
+ private static String genRandomStr() {
+ String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+ Random random = new Random();
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < 16; i++) {
+ int number = random.nextInt(base.length());
+ sb.append(base.charAt(number));
+ }
+ return sb.toString();
+ }
+
+ /**
+ * 生成xml消息
+ *
+ * @param encrypt 加密后的消息密文
+ * @param signature 安全签名
+ * @param timestamp 时间戳
+ * @param nonce 随机字符串
+ * @return 生成的xml字符串
+ */
+ private static String generateXml(String encrypt, String signature,
+ String timestamp, String nonce) {
+ String format = "\n" + "\n"
+ + "\n"
+ + "%3$s\n" + "\n"
+ + "";
+ return String.format(format, encrypt, signature, timestamp, nonce);
+ }
+
+}
diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/ApacheHttpClientBuilder.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/ApacheHttpClientBuilder.java
index 8bd900ca..c932445d 100644
--- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/ApacheHttpClientBuilder.java
+++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/ApacheHttpClientBuilder.java
@@ -5,6 +5,7 @@ import org.apache.http.impl.client.CloseableHttpClient;
/**
* httpclient build interface
+ * @author kakotor
*/
public interface ApacheHttpClientBuilder {
diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/DefaultApacheHttpClientBuilder.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/DefaultApacheHttpClientBuilder.java
index f69dcc6c..030fe98f 100644
--- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/DefaultApacheHttpClientBuilder.java
+++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/DefaultApacheHttpClientBuilder.java
@@ -1,6 +1,6 @@
package me.chanjar.weixin.common.util.http;
-import me.chanjar.weixin.common.util.StringUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
@@ -20,15 +20,22 @@ import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.protocol.HttpContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
/**
* httpclient 连接管理器
+ *
+ * @author kakotor
*/
@NotThreadSafe
public class DefaultApacheHttpClientBuilder implements ApacheHttpClientBuilder {
+ protected final Logger log = LoggerFactory.getLogger(DefaultApacheHttpClientBuilder.class);
+ private final AtomicBoolean prepared = new AtomicBoolean(false);
private int connectionRequestTimeout = 3000;
private int connectionTimeout = 5000;
private int soTimeout = 5000;
@@ -45,21 +52,16 @@ public class DefaultApacheHttpClientBuilder implements ApacheHttpClientBuilder {
};
private SSLConnectionSocketFactory sslConnectionSocketFactory = SSLConnectionSocketFactory.getSocketFactory();
private PlainConnectionSocketFactory plainConnectionSocketFactory = PlainConnectionSocketFactory.getSocketFactory();
-
private String httpProxyHost;
private int httpProxyPort;
private String httpProxyUsername;
private String httpProxyPassword;
-
/**
* 闲置连接监控线程
*/
private IdleConnectionMonitorThread idleConnectionMonitorThread;
-
private HttpClientBuilder httpClientBuilder;
- private boolean prepared = false;
-
private DefaultApacheHttpClientBuilder() {
}
@@ -97,11 +99,98 @@ public class DefaultApacheHttpClientBuilder implements ApacheHttpClientBuilder {
return this;
}
+ /**
+ * 获取链接的超时时间设置,默认3000ms
+ *
+ * 设置为零时不超时,一直等待.
+ * 设置为负数是使用系统默认设置(非上述的3000ms的默认值,而是httpclient的默认设置).
+ *
+ *
+ * @param connectionRequestTimeout 获取链接的超时时间设置(单位毫秒),默认3000ms
+ */
+ public void setConnectionRequestTimeout(int connectionRequestTimeout) {
+ this.connectionRequestTimeout = connectionRequestTimeout;
+ }
+
+ /**
+ * 建立链接的超时时间,默认为5000ms.由于是在链接池获取链接,此设置应该并不起什么作用
+ *
+ * 设置为零时不超时,一直等待.
+ * 设置为负数是使用系统默认设置(非上述的5000ms的默认值,而是httpclient的默认设置).
+ *
+ *
+ * @param connectionTimeout 建立链接的超时时间设置(单位毫秒),默认5000ms
+ */
+ public void setConnectionTimeout(int connectionTimeout) {
+ this.connectionTimeout = connectionTimeout;
+ }
+
+ /**
+ * 默认NIO的socket超时设置,默认5000ms.
+ *
+ * @param soTimeout 默认NIO的socket超时设置,默认5000ms.
+ * @see java.net.SocketOptions#SO_TIMEOUT
+ */
+ public void setSoTimeout(int soTimeout) {
+ this.soTimeout = soTimeout;
+ }
+
+ /**
+ * 空闲链接的超时时间,默认60000ms.
+ *
+ * 超时的链接将在下一次空闲链接检查是被销毁
+ *
+ *
+ * @param idleConnTimeout 空闲链接的超时时间,默认60000ms.
+ */
+ public void setIdleConnTimeout(int idleConnTimeout) {
+ this.idleConnTimeout = idleConnTimeout;
+ }
+
+ /**
+ * 检查空间链接的间隔周期,默认60000ms.
+ *
+ * @param checkWaitTime 检查空间链接的间隔周期,默认60000ms.
+ */
+ public void setCheckWaitTime(int checkWaitTime) {
+ this.checkWaitTime = checkWaitTime;
+ }
+
+ /**
+ * 每路的最大链接数,默认10
+ *
+ * @param maxConnPerHost 每路的最大链接数,默认10
+ */
+ public void setMaxConnPerHost(int maxConnPerHost) {
+ this.maxConnPerHost = maxConnPerHost;
+ }
+
+ /**
+ * 最大总连接数,默认50
+ *
+ * @param maxTotalConn 最大总连接数,默认50
+ */
+ public void setMaxTotalConn(int maxTotalConn) {
+ this.maxTotalConn = maxTotalConn;
+ }
+
+ /**
+ * 自定义httpclient的User Agent
+ *
+ * @param userAgent User Agent
+ */
+ public void setUserAgent(String userAgent) {
+ this.userAgent = userAgent;
+ }
+
public IdleConnectionMonitorThread getIdleConnectionMonitorThread() {
return this.idleConnectionMonitorThread;
}
- private void prepare() {
+ private synchronized void prepare() {
+ if(prepared.get()){
+ return;
+ }
Registry registry = RegistryBuilder.create()
.register("http", this.plainConnectionSocketFactory)
.register("https", this.sslConnectionSocketFactory)
@@ -148,16 +237,14 @@ public class DefaultApacheHttpClientBuilder implements ApacheHttpClientBuilder {
if (StringUtils.isNotBlank(this.userAgent)) {
this.httpClientBuilder.setUserAgent(this.userAgent);
}
-
+ prepared.set(true);
}
@Override
public CloseableHttpClient build() {
- if (!this.prepared) {
+ if(!prepared.get()){
prepare();
- this.prepared = true;
}
-
return this.httpClientBuilder.build();
}
diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/JoddGetRequestExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/JoddGetRequestExecutor.java
deleted file mode 100644
index 34f20779..00000000
--- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/JoddGetRequestExecutor.java
+++ /dev/null
@@ -1,55 +0,0 @@
-package me.chanjar.weixin.common.util.http;
-
-import org.apache.http.HttpHost;
-import org.apache.http.impl.client.CloseableHttpClient;
-
-import jodd.http.HttpRequest;
-import jodd.http.HttpResponse;
-import jodd.http.ProxyInfo;
-import jodd.http.net.SocketHttpConnectionProvider;
-import me.chanjar.weixin.common.bean.result.WxError;
-import me.chanjar.weixin.common.exception.WxErrorException;
-
-/**
- * 简单的GET请求执行器,请求的参数是String, 返回的结果也是String
- *
- * @author Daniel Qian
- */
-public class JoddGetRequestExecutor implements RequestExecutor {
-
- @Override
- public String execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri,
- String queryParam) throws WxErrorException {
- if (queryParam != null) {
- if (uri.indexOf('?') == -1) {
- uri += '?';
- }
- uri += uri.endsWith("?") ? queryParam : '&' + queryParam;
- }
-
- SocketHttpConnectionProvider provider = new SocketHttpConnectionProvider();
-
- if (httpProxy != null) {
- ProxyInfo proxyInfoObj = new ProxyInfo(
- ProxyInfo.ProxyType.HTTP,
- httpProxy.getHostName(),
- httpProxy.getPort(), "", "");
- provider.useProxy(proxyInfoObj);
- }
-
- HttpRequest request = HttpRequest.get(uri);
- request.method("GET");
- request.charset("UTF-8");
-
- HttpResponse response = request.open(provider).send();
- response.charset("UTF-8");
- String result = response.bodyText();
-
- WxError error = WxError.fromJson(result);
- if (error.getErrorCode() != 0) {
- throw new WxErrorException(error);
- }
- return result;
- }
-
-}
diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/JoddPostRequestExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/JoddPostRequestExecutor.java
deleted file mode 100644
index 757db665..00000000
--- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/JoddPostRequestExecutor.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package me.chanjar.weixin.common.util.http;
-
-import org.apache.http.HttpHost;
-import org.apache.http.impl.client.CloseableHttpClient;
-
-import jodd.http.HttpRequest;
-import jodd.http.HttpResponse;
-import jodd.http.ProxyInfo;
-import jodd.http.net.SocketHttpConnectionProvider;
-import me.chanjar.weixin.common.bean.result.WxError;
-import me.chanjar.weixin.common.exception.WxErrorException;
-
-/**
- * 简单的POST请求执行器,请求的参数是String, 返回的结果也是String
- *
- * @author Edison Guo
- */
-public class JoddPostRequestExecutor implements RequestExecutor {
-
- @Override
- public String execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri,
- String postEntity) throws WxErrorException {
- SocketHttpConnectionProvider provider = new SocketHttpConnectionProvider();
-
- if (httpProxy != null) {
- ProxyInfo proxyInfoObj = new ProxyInfo(
- ProxyInfo.ProxyType.HTTP,
- httpProxy.getAddress().getHostAddress(),
- httpProxy.getPort(), "", "");
- provider.useProxy(proxyInfoObj);
- }
-
- HttpRequest request = HttpRequest.get(uri);
- request.method("POST");
- request.charset("UTF-8");
- request.bodyText(postEntity);
-
- HttpResponse response = request.open(provider).send();
- response.charset("UTF-8");
- String result = response.bodyText();
-
- WxError error = WxError.fromJson(result);
- if (error.getErrorCode() != 0) {
- throw new WxErrorException(error);
- }
- return result;
- }
-
-}
diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MediaDownloadRequestExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MediaDownloadRequestExecutor.java
index c81658e2..57024f50 100644
--- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MediaDownloadRequestExecutor.java
+++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MediaDownloadRequestExecutor.java
@@ -2,8 +2,8 @@ package me.chanjar.weixin.common.util.http;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
-import me.chanjar.weixin.common.util.StringUtils;
import me.chanjar.weixin.common.util.fs.FileUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.http.Header;
import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig;
diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/URIUtil.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/URIUtil.java
index 9448f2d1..7e42aba7 100644
--- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/URIUtil.java
+++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/URIUtil.java
@@ -1,6 +1,7 @@
package me.chanjar.weixin.common.util.http;
-import me.chanjar.weixin.common.util.StringUtils;
+
+import org.apache.commons.lang3.StringUtils;
import java.io.UnsupportedEncodingException;
diff --git a/weixin-java-common/src/test/java/me/chanjar/weixin/common/util/crypto/WxCryptUtilTest.java b/weixin-java-common/src/test/java/me/chanjar/weixin/common/util/crypto/WxCryptUtilTest.java
index e7692165..91095a20 100755
--- a/weixin-java-common/src/test/java/me/chanjar/weixin/common/util/crypto/WxCryptUtilTest.java
+++ b/weixin-java-common/src/test/java/me/chanjar/weixin/common/util/crypto/WxCryptUtilTest.java
@@ -1,103 +1,103 @@
-package me.chanjar.weixin.common.util.crypto;
-
-import org.testng.annotations.Test;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import java.io.IOException;
-import java.io.StringReader;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.fail;
-
-@Test
-public class WxCryptUtilTest {
- String encodingAesKey = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFG";
- String token = "pamtest";
- String timestamp = "1409304348";
- String nonce = "xxxxxx";
- String appId = "wxb11529c136998cb6";
- String randomStr = "aaaabbbbccccdddd";
-
- String xmlFormat = "";
- String replyMsg = "我是中文abcd123";
-
- String afterAesEncrypt = "jn1L23DB+6ELqJ+6bruv21Y6MD7KeIfP82D6gU39rmkgczbWwt5+3bnyg5K55bgVtVzd832WzZGMhkP72vVOfg==";
-
- String replyMsg2 = "1407743423";
- String afterAesEncrypt2 = "jn1L23DB+6ELqJ+6bruv23M2GmYfkv0xBh2h+XTBOKVKcgDFHle6gqcZ1cZrk3e1qjPQ1F4RsLWzQRG9udbKWesxlkupqcEcW7ZQweImX9+wLMa0GaUzpkycA8+IamDBxn5loLgZpnS7fVAbExOkK5DYHBmv5tptA9tklE/fTIILHR8HLXa5nQvFb3tYPKAlHF3rtTeayNf0QuM+UW/wM9enGIDIJHF7CLHiDNAYxr+r+OrJCmPQyTy8cVWlu9iSvOHPT/77bZqJucQHQ04sq7KZI27OcqpQNSto2OdHCoTccjggX5Z9Mma0nMJBU+jLKJ38YB1fBIz+vBzsYjrTmFQ44YfeEuZ+xRTQwr92vhA9OxchWVINGC50qE/6lmkwWTwGX9wtQpsJKhP+oS7rvTY8+VdzETdfakjkwQ5/Xka042OlUb1/slTwo4RscuQ+RdxSGvDahxAJ6+EAjLt9d8igHngxIbf6YyqqROxuxqIeIch3CssH/LqRs+iAcILvApYZckqmA7FNERspKA5f8GoJ9sv8xmGvZ9Yrf57cExWtnX8aCMMaBropU/1k+hKP5LVdzbWCG0hGwx/dQudYR/eXp3P0XxjlFiy+9DMlaFExWUZQDajPkdPrEeOwofJb";
-
- public void testNormal() throws ParserConfigurationException, SAXException, IOException {
- WxCryptUtil pc = new WxCryptUtil(this.token, this.encodingAesKey, this.appId);
- String encryptedXml = pc.encrypt(this.replyMsg);
-
- System.out.println(encryptedXml);
-
- DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
- Document document = documentBuilder.parse(new InputSource(new StringReader(encryptedXml)));
-
- Element root = document.getDocumentElement();
- String cipherText = root.getElementsByTagName("Encrypt").item(0).getTextContent();
- System.out.println(cipherText);
-
- String msgSignature = root.getElementsByTagName("MsgSignature").item(0).getTextContent();
- System.out.println(msgSignature);
-
- String timestamp = root.getElementsByTagName("TimeStamp").item(0).getTextContent();
- System.out.println(timestamp);
-
- String nonce = root.getElementsByTagName("Nonce").item(0).getTextContent();
- System.out.println(nonce);
-
- String messageText = String.format(this.xmlFormat, cipherText);
- System.out.println(messageText);
-
- // 第三方收到企业号平台发送的消息
- String plainMessage = pc.decrypt(cipherText);
- System.out.println(plainMessage);
-
- assertEquals(plainMessage, this.replyMsg);
- }
-
- public void testAesEncrypt() {
- WxCryptUtil pc = new WxCryptUtil(this.token, this.encodingAesKey, this.appId);
- assertEquals(pc.encrypt(this.randomStr, this.replyMsg), this.afterAesEncrypt);
- }
-
- public void testAesEncrypt2() {
- WxCryptUtil pc = new WxCryptUtil(this.token, this.encodingAesKey, this.appId);
- assertEquals(pc.encrypt(this.randomStr, this.replyMsg2), this.afterAesEncrypt2);
- }
-
- public void testValidateSignatureError() throws ParserConfigurationException, SAXException,
- IOException {
- try {
- WxCryptUtil pc = new WxCryptUtil(this.token, this.encodingAesKey, this.appId);
- String afterEncrpt = pc.encrypt(this.replyMsg);
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- DocumentBuilder db = dbf.newDocumentBuilder();
- StringReader sr = new StringReader(afterEncrpt);
- InputSource is = new InputSource(sr);
- Document document = db.parse(is);
-
- Element root = document.getDocumentElement();
- NodeList nodelist1 = root.getElementsByTagName("Encrypt");
-
- String encrypt = nodelist1.item(0).getTextContent();
- String fromXML = String.format(this.xmlFormat, encrypt);
- pc.decrypt("12345", this.timestamp, this.nonce, fromXML); // 这里签名错误
- } catch (RuntimeException e) {
- assertEquals(e.getMessage(), "加密消息签名校验失败");
- return;
- }
- fail("错误流程不抛出异常???");
- }
-
-}
+package me.chanjar.weixin.common.util.crypto;
+
+import org.testng.annotations.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.IOException;
+import java.io.StringReader;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.fail;
+
+@Test
+public class WxCryptUtilTest {
+ String encodingAesKey = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFG";
+ String token = "pamtest";
+ String timestamp = "1409304348";
+ String nonce = "xxxxxx";
+ String appId = "wxb11529c136998cb6";
+ String randomStr = "aaaabbbbccccdddd";
+
+ String xmlFormat = "";
+ String replyMsg = "我是中文abcd123";
+
+ String afterAesEncrypt = "jn1L23DB+6ELqJ+6bruv21Y6MD7KeIfP82D6gU39rmkgczbWwt5+3bnyg5K55bgVtVzd832WzZGMhkP72vVOfg==";
+
+ String replyMsg2 = "1407743423";
+ String afterAesEncrypt2 = "jn1L23DB+6ELqJ+6bruv23M2GmYfkv0xBh2h+XTBOKVKcgDFHle6gqcZ1cZrk3e1qjPQ1F4RsLWzQRG9udbKWesxlkupqcEcW7ZQweImX9+wLMa0GaUzpkycA8+IamDBxn5loLgZpnS7fVAbExOkK5DYHBmv5tptA9tklE/fTIILHR8HLXa5nQvFb3tYPKAlHF3rtTeayNf0QuM+UW/wM9enGIDIJHF7CLHiDNAYxr+r+OrJCmPQyTy8cVWlu9iSvOHPT/77bZqJucQHQ04sq7KZI27OcqpQNSto2OdHCoTccjggX5Z9Mma0nMJBU+jLKJ38YB1fBIz+vBzsYjrTmFQ44YfeEuZ+xRTQwr92vhA9OxchWVINGC50qE/6lmkwWTwGX9wtQpsJKhP+oS7rvTY8+VdzETdfakjkwQ5/Xka042OlUb1/slTwo4RscuQ+RdxSGvDahxAJ6+EAjLt9d8igHngxIbf6YyqqROxuxqIeIch3CssH/LqRs+iAcILvApYZckqmA7FNERspKA5f8GoJ9sv8xmGvZ9Yrf57cExWtnX8aCMMaBropU/1k+hKP5LVdzbWCG0hGwx/dQudYR/eXp3P0XxjlFiy+9DMlaFExWUZQDajPkdPrEeOwofJb";
+
+ public void testNormal() throws ParserConfigurationException, SAXException, IOException {
+ WxCryptUtil pc = new WxCryptUtil(this.token, this.encodingAesKey, this.appId);
+ String encryptedXml = pc.encrypt(this.replyMsg);
+
+ System.out.println(encryptedXml);
+
+ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
+ Document document = documentBuilder.parse(new InputSource(new StringReader(encryptedXml)));
+
+ Element root = document.getDocumentElement();
+ String cipherText = root.getElementsByTagName("Encrypt").item(0).getTextContent();
+ System.out.println(cipherText);
+
+ String msgSignature = root.getElementsByTagName("MsgSignature").item(0).getTextContent();
+ System.out.println(msgSignature);
+
+ String timestamp = root.getElementsByTagName("TimeStamp").item(0).getTextContent();
+ System.out.println(timestamp);
+
+ String nonce = root.getElementsByTagName("Nonce").item(0).getTextContent();
+ System.out.println(nonce);
+
+ String messageText = String.format(this.xmlFormat, cipherText);
+ System.out.println(messageText);
+
+ // 第三方收到企业号平台发送的消息
+ String plainMessage = pc.decrypt(cipherText);
+ System.out.println(plainMessage);
+
+ assertEquals(plainMessage, this.replyMsg);
+ }
+
+ public void testAesEncrypt() {
+ WxCryptUtil pc = new WxCryptUtil(this.token, this.encodingAesKey, this.appId);
+ assertEquals(pc.encrypt(this.randomStr, this.replyMsg), this.afterAesEncrypt);
+ }
+
+ public void testAesEncrypt2() {
+ WxCryptUtil pc = new WxCryptUtil(this.token, this.encodingAesKey, this.appId);
+ assertEquals(pc.encrypt(this.randomStr, this.replyMsg2), this.afterAesEncrypt2);
+ }
+
+ public void testValidateSignatureError() throws ParserConfigurationException, SAXException,
+ IOException {
+ try {
+ WxCryptUtil pc = new WxCryptUtil(this.token, this.encodingAesKey, this.appId);
+ String afterEncrpt = pc.encrypt(this.replyMsg);
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ StringReader sr = new StringReader(afterEncrpt);
+ InputSource is = new InputSource(sr);
+ Document document = db.parse(is);
+
+ Element root = document.getDocumentElement();
+ NodeList nodelist1 = root.getElementsByTagName("Encrypt");
+
+ String encrypt = nodelist1.item(0).getTextContent();
+ String fromXML = String.format(this.xmlFormat, encrypt);
+ pc.decrypt("12345", this.timestamp, this.nonce, fromXML); // 这里签名错误
+ } catch (RuntimeException e) {
+ assertEquals(e.getMessage(), "加密消息签名校验失败");
+ return;
+ }
+ fail("错误流程不抛出异常???");
+ }
+
+}
diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml
index e87e2ea1..e7fbd255 100644
--- a/weixin-java-cp/pom.xml
+++ b/weixin-java-cp/pom.xml
@@ -6,7 +6,7 @@
com.github.binarywang
weixin-java-parent
- 2.2.0
+ 2.3.0
weixin-java-cp
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpInMemoryConfigStorage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpInMemoryConfigStorage.java
index 17fda4ca..fb7bacff 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpInMemoryConfigStorage.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpInMemoryConfigStorage.java
@@ -1,13 +1,11 @@
package me.chanjar.weixin.cp.api;
-import java.io.File;
-
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-
import me.chanjar.weixin.common.bean.WxAccessToken;
+import me.chanjar.weixin.common.util.ToStringUtils;
import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder;
+import java.io.File;
+
/**
* 基于内存的微信配置provider,在实际生产环境中应该将这些配置持久化
*
@@ -203,7 +201,7 @@ public class WxCpInMemoryConfigStorage implements WxCpConfigStorage {
@Override
public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
+ return ToStringUtils.toSimpleString(this);
}
@Override
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java
index e3723a71..b044b468 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java
@@ -1,28 +1,7 @@
package me.chanjar.weixin.cp.api;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.List;
-import java.util.UUID;
-
-import org.apache.http.HttpHost;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.config.RequestConfig;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.impl.client.BasicResponseHandler;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.gson.JsonArray;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import com.google.gson.JsonPrimitive;
+import com.google.gson.*;
import com.google.gson.reflect.TypeToken;
-
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.bean.menu.WxMenu;
@@ -33,23 +12,31 @@ import me.chanjar.weixin.common.session.StandardSessionManager;
import me.chanjar.weixin.common.session.WxSession;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.common.util.RandomUtils;
-import me.chanjar.weixin.common.util.StringUtils;
import me.chanjar.weixin.common.util.crypto.SHA1;
import me.chanjar.weixin.common.util.fs.FileUtils;
-import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder;
-import me.chanjar.weixin.common.util.http.DefaultApacheHttpClientBuilder;
-import me.chanjar.weixin.common.util.http.MediaDownloadRequestExecutor;
-import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
-import me.chanjar.weixin.common.util.http.RequestExecutor;
-import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
-import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
-import me.chanjar.weixin.common.util.http.URIUtil;
+import me.chanjar.weixin.common.util.http.*;
import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.cp.bean.WxCpDepart;
import me.chanjar.weixin.cp.bean.WxCpMessage;
import me.chanjar.weixin.cp.bean.WxCpTag;
import me.chanjar.weixin.cp.bean.WxCpUser;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.http.HttpHost;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.BasicResponseHandler;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.UUID;
public class WxCpServiceImpl implements WxCpService {
@@ -185,10 +172,10 @@ public class WxCpServiceImpl implements WxCpService {
jsapiSignature.setNoncestr(noncestr);
jsapiSignature.setUrl(url);
jsapiSignature.setSignature(signature);
-
+
// Fixed bug
jsapiSignature.setAppid(this.configStorage.getCorpId());
-
+
return jsapiSignature;
}
@@ -503,7 +490,7 @@ this.configStorage.getOauth2redirectUri(),
public String[] oauth2getUserInfo(String agentId, String code) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?"
+ "code=" + code
- + "&agendid=" + agentId;
+ + "&agentid=" + agentId;
String responseText = get(url, null);
JsonElement je = new JsonParser().parse(responseText);
JsonObject jo = je.getAsJsonObject();
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpDepart.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpDepart.java
index c8735086..a679dffe 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpDepart.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpDepart.java
@@ -1,9 +1,9 @@
package me.chanjar.weixin.cp.bean;
-import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
-
import java.io.Serializable;
+import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
+
/**
* 微信部门
*
@@ -11,9 +11,6 @@ import java.io.Serializable;
*/
public class WxCpDepart implements Serializable {
- /**
- *
- */
private static final long serialVersionUID = -5028321625140879571L;
private Integer id;
private String name;
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMessage.java
index 6dba9091..e2422e3b 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMessage.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMessage.java
@@ -1,12 +1,17 @@
package me.chanjar.weixin.cp.bean;
-import me.chanjar.weixin.cp.bean.messagebuilder.*;
-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.bean.messagebuilder.FileBuilder;
+import me.chanjar.weixin.cp.bean.messagebuilder.ImageBuilder;
+import me.chanjar.weixin.cp.bean.messagebuilder.NewsBuilder;
+import me.chanjar.weixin.cp.bean.messagebuilder.TextBuilder;
+import me.chanjar.weixin.cp.bean.messagebuilder.VideoBuilder;
+import me.chanjar.weixin.cp.bean.messagebuilder.VoiceBuilder;
+import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
+
/**
* 消息
*
@@ -14,9 +19,6 @@ import java.util.List;
*/
public class WxCpMessage implements Serializable {
- /**
- *
- */
private static final long serialVersionUID = -2082278303476631708L;
private String toUser;
private String toParty;
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTag.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTag.java
index ca11cb1f..4e1c034f 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTag.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTag.java
@@ -1,17 +1,14 @@
package me.chanjar.weixin.cp.bean;
-import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
-
import java.io.Serializable;
+import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
+
/**
* Created by Daniel Qian
*/
public class WxCpTag implements Serializable {
- /**
- *
- */
private static final long serialVersionUID = -7243320279646928402L;
private String id;
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java
index d1737d5d..93c3e5fe 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java
@@ -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;
+
/**
* 微信用户信息
*
@@ -13,9 +13,6 @@ import java.util.List;
*/
public class WxCpUser implements Serializable {
- /**
- *
- */
private static final long serialVersionUID = -5696099236344075582L;
private final List extAttrs = new ArrayList<>();
private String userId;
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlMessage.java
index 352fa2e6..93ca45c3 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlMessage.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlMessage.java
@@ -1,18 +1,20 @@
package me.chanjar.weixin.cp.bean;
+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;
-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;
/**
*
@@ -27,16 +29,12 @@ import java.util.List;
*/
@XStreamAlias("xml")
public class WxCpXmlMessage implements Serializable {
+ private static final long serialVersionUID = -1042994982179476410L;
///////////////////////
// 以下都是微信推送过来的消息的xml的element所对应的属性
///////////////////////
- /**
- *
- */
- private static final long serialVersionUID = -1042994982179476410L;
-
@XStreamAlias("AgentID")
private Integer agentId;
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutImageMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutImageMessage.java
index 44de8811..35cbe754 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutImageMessage.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutImageMessage.java
@@ -2,11 +2,13 @@ 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;
@XStreamAlias("xml")
public class WxCpXmlOutImageMessage extends WxCpXmlOutMessage {
+ private static final long serialVersionUID = -1099446240667237313L;
@XStreamAlias("Image")
@XStreamConverter(value = XStreamMediaIdConverter.class)
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutMessage.java
index 332b5e24..0d90a012 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutMessage.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutMessage.java
@@ -8,8 +8,12 @@ import me.chanjar.weixin.cp.bean.outxmlbuilder.*;
import me.chanjar.weixin.cp.util.crypto.WxCpCryptUtil;
import me.chanjar.weixin.cp.util.xml.XStreamTransformer;
+import java.io.Serializable;
+
@XStreamAlias("xml")
-public abstract class WxCpXmlOutMessage {
+public abstract class WxCpXmlOutMessage implements Serializable {
+
+ private static final long serialVersionUID = 1418629839964153110L;
@XStreamAlias("ToUserName")
@XStreamConverter(value = XStreamCDataConverter.class)
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutNewsMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutNewsMessage.java
index 5906a324..8910f03f 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutNewsMessage.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutNewsMessage.java
@@ -1,15 +1,17 @@
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;
@XStreamAlias("Articles")
protected final List- articles = new ArrayList<>();
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutTextMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutTextMessage.java
index 3c59edf9..532e06c3 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutTextMessage.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutTextMessage.java
@@ -2,11 +2,13 @@ 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;
@XStreamAlias("xml")
public class WxCpXmlOutTextMessage extends WxCpXmlOutMessage {
+ private static final long serialVersionUID = 2569239617185930232L;
@XStreamAlias("Content")
@XStreamConverter(value = XStreamCDataConverter.class)
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVideoMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVideoMessage.java
index 6e2f268f..73c56d4c 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVideoMessage.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVideoMessage.java
@@ -2,11 +2,13 @@ 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;
@XStreamAlias("xml")
public class WxCpXmlOutVideoMessage extends WxCpXmlOutMessage {
+ private static final long serialVersionUID = -8672761162722733622L;
@XStreamAlias("Video")
protected final Video video = new Video();
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVoiceMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVoiceMessage.java
index 1fd6d4ce..bba95cfd 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVoiceMessage.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVoiceMessage.java
@@ -2,11 +2,13 @@ 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;
@XStreamAlias("xml")
public class WxCpXmlOutVoiceMessage extends WxCpXmlOutMessage {
+ private static final long serialVersionUID = -7947384031546099340L;
@XStreamAlias("Voice")
@XStreamConverter(value = XStreamMediaIdConverter.class)
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpMessageGsonAdapter.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpMessageGsonAdapter.java
index 322658c2..7bf09c71 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpMessageGsonAdapter.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpMessageGsonAdapter.java
@@ -10,8 +10,8 @@ package me.chanjar.weixin.cp.util.json;
import com.google.gson.*;
import me.chanjar.weixin.common.api.WxConsts;
-import me.chanjar.weixin.common.util.StringUtils;
import me.chanjar.weixin.cp.bean.WxCpMessage;
+import org.apache.commons.lang3.StringUtils;
import java.lang.reflect.Type;
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBaseAPITest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBaseAPITest.java
index d2eb2ec6..894bb3b6 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBaseAPITest.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBaseAPITest.java
@@ -1,14 +1,12 @@
package me.chanjar.weixin.cp.api;
+import com.google.inject.Inject;
+import me.chanjar.weixin.common.exception.WxErrorException;
+import org.apache.commons.lang3.StringUtils;
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.common.util.StringUtils;
-
/**
* 基础API测试
*
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlOutNewsMessageTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlOutNewsMessageTest.java
index bd66743c..872c0ac3 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlOutNewsMessageTest.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlOutNewsMessageTest.java
@@ -19,12 +19,12 @@ public class WxCpXmlOutNewsMessageTest {
item.setUrl("url");
m.addArticle(item);
m.addArticle(item);
+
String expected = ""
+ ""
+ ""
+ "1122"
+ ""
- + " 2"
+ " "
+ "
- "
+ " "
@@ -39,6 +39,7 @@ public class WxCpXmlOutNewsMessageTest {
+ " "
+ "
"
+ " "
+ + " 2"
+ "";
System.out.println(m.toXml());
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", ""));
@@ -62,7 +63,6 @@ public class WxCpXmlOutNewsMessageTest {
+ ""
+ "1122"
+ ""
- + " 2"
+ " "
+ " - "
+ " "
@@ -77,6 +77,7 @@ public class WxCpXmlOutNewsMessageTest {
+ " "
+ "
"
+ " "
+ + " 2"
+ "";
System.out.println(m.toXml());
Assert.assertEquals(
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpEndpointServlet.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpEndpointServlet.java
index d59eb3f3..43bf1799 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpEndpointServlet.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpEndpointServlet.java
@@ -1,18 +1,17 @@
package me.chanjar.weixin.cp.demo;
-import java.io.IOException;
-
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import me.chanjar.weixin.common.util.StringUtils;
import me.chanjar.weixin.cp.api.WxCpConfigStorage;
import me.chanjar.weixin.cp.api.WxCpMessageRouter;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage;
import me.chanjar.weixin.cp.util.crypto.WxCpCryptUtil;
+import org.apache.commons.lang3.StringUtils;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
/**
* @author Daniel Qian
diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml
index 6fc42ee6..c1b6a136 100644
--- a/weixin-java-mp/pom.xml
+++ b/weixin-java-mp/pom.xml
@@ -6,7 +6,7 @@
com.github.binarywang
weixin-java-parent
- 2.2.0
+ 2.3.0
weixin-java-mp
WeiXin Java Tools - MP
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java
index 765f6d53..e75b78da 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java
@@ -1,13 +1,10 @@
package me.chanjar.weixin.mp.api;
import me.chanjar.weixin.common.bean.WxAccessToken;
+import me.chanjar.weixin.common.util.ToStringUtils;
import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder;
import javax.net.ssl.SSLContext;
-
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-
import java.io.File;
/**
@@ -43,7 +40,7 @@ public class WxMpInMemoryConfigStorage implements WxMpConfigStorage {
* 临时文件目录
*/
protected volatile File tmpDirFile;
-
+
protected volatile SSLContext sslContext;
protected volatile ApacheHttpClientBuilder apacheHttpClientBuilder;
@@ -62,7 +59,7 @@ public class WxMpInMemoryConfigStorage implements WxMpConfigStorage {
public synchronized void updateAccessToken(WxAccessToken accessToken) {
updateAccessToken(accessToken.getAccessToken(), accessToken.getExpiresIn());
}
-
+
@Override
public synchronized void updateAccessToken(String accessToken, int expiresInSeconds) {
this.accessToken = accessToken;
@@ -229,7 +226,7 @@ public class WxMpInMemoryConfigStorage implements WxMpConfigStorage {
@Override
public String toString() {
- return ToStringBuilder.reflectionToString(this,ToStringStyle.JSON_STYLE);
+ return ToStringUtils.toSimpleString(this);
}
@Override
@@ -263,7 +260,7 @@ public class WxMpInMemoryConfigStorage implements WxMpConfigStorage {
public SSLContext getSSLContext() {
return this.sslContext;
}
-
+
public void setSSLContext(SSLContext context) {
this.sslContext = context;
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpKefuService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpKefuService.java
index fc678b42..f57c9630 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpKefuService.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpKefuService.java
@@ -1,17 +1,12 @@
package me.chanjar.weixin.mp.api;
-import java.io.File;
-import java.util.Date;
-
import me.chanjar.weixin.common.exception.WxErrorException;
-import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
+import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest;
-import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfList;
-import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfMsgList;
-import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfOnlineList;
-import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfSessionGetResult;
-import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfSessionList;
-import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfSessionWaitCaseList;
+import me.chanjar.weixin.mp.bean.kefu.result.*;
+
+import java.io.File;
+import java.util.Date;
/**
* 客服接口 ,
@@ -27,9 +22,10 @@ public interface WxMpKefuService {
*
* 发送客服消息
* 详情请见: 发送客服消息
+ * 接口url格式:https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN
*
*/
- boolean customMessageSend(WxMpCustomMessage message) throws WxErrorException;
+ boolean sendKefuMessage(WxMpKefuMessage message) throws WxErrorException;
//*******************客服管理接口***********************//
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMaterialService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMaterialService.java
index 48a6f610..8c867c5f 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMaterialService.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMaterialService.java
@@ -2,11 +2,12 @@ package me.chanjar.weixin.mp.api;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.exception.WxErrorException;
-import me.chanjar.weixin.mp.bean.*;
-import me.chanjar.weixin.mp.bean.result.*;
+import me.chanjar.weixin.mp.bean.material.WxMpMaterial;
+import me.chanjar.weixin.mp.bean.material.WxMpMaterialArticleUpdate;
+import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews;
+import me.chanjar.weixin.mp.bean.material.*;
import java.io.File;
-import java.io.IOException;
import java.io.InputStream;
/**
@@ -20,21 +21,58 @@ import java.io.InputStream;
public interface WxMpMaterialService {
/**
+ *
* 新增临时素材
- *
- * @param mediaType
- * @param file
+ * 公众号经常有需要用到一些临时性的多媒体素材的场景,例如在使用接口特别是发送消息时,对多媒体文件、多媒体消息的获取和调用等操作,是通过media_id来进行的。
+ * 素材管理接口对所有认证的订阅号和服务号开放。通过本接口,公众号可以新增临时素材(即上传临时多媒体文件)。
+ * 请注意:
+ * 1、对于临时素材,每个素材(media_id)会在开发者上传或粉丝发送到微信服务器3天后自动删除(所以用户发送给开发者的素材,若开发者需要,应尽快下载到本地),以节省服务器资源。
+ * 2、media_id是可复用的。
+ * 3、素材的格式大小等要求与公众平台官网一致。具体是,图片大小不超过2M,支持png/jpeg/jpg/gif格式,语音大小不超过5M,长度不超过60秒,支持mp3/amr格式
+ * 4、需使用https调用本接口。
+ * 本接口即为原“上传多媒体文件”接口。
+ * 注意事项:
+ * 上传的临时多媒体文件有格式和大小限制,如下:
+ * 图片(image): 2M,支持PNG\JPEG\JPG\GIF格式
+ * 语音(voice):2M,播放长度不超过60s,支持AMR\MP3格式
+ * 视频(video):10MB,支持MP4格式
+ * 缩略图(thumb):64KB,支持JPG格式
+ *媒体文件在后台保存时间为3天,即3天后media_id失效。
+ * 详情请见: 新增临时素材
+ * 接口url格式:https://api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE
+ *
+ * @param mediaType 媒体类型, 请看{@link me.chanjar.weixin.common.api.WxConsts}
+ * @param file 文件对象
* @throws WxErrorException
* @see #mediaUpload(String, String, InputStream)
*/
WxMediaUploadResult mediaUpload(String mediaType, File file) throws WxErrorException;
+ /**
+ *
+ * 新增临时素材
+ * 本接口即为原“上传多媒体文件”接口。
+ *
+ * 详情请见: 新增临时素材
+ * 接口url格式:https://api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE
+ *
+ *
+ * @param mediaType 媒体类型, 请看{@link me.chanjar.weixin.common.api.WxConsts}
+ * @param fileType 文件类型,请看{@link me.chanjar.weixin.common.api.WxConsts}
+ * @param inputStream 输入流
+ * @throws WxErrorException
+ * @see #mediaUpload(java.lang.String, java.io.File)
+ */
+ WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream inputStream) throws WxErrorException;
+
/**
*
* 获取临时素材
+ * 公众号可以使用本接口获取临时素材(即下载临时的多媒体文件)。请注意,视频文件不支持https下载,调用该接口需http协议。
* 本接口即为原“下载多媒体文件”接口。
* 根据微信文档,视频文件下载不了,会返回null
- * 详情请见: 获取临时素材
+ * 详情请见: 获取临时素材
+ * 接口url格式:https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID
*
*
* @param media_id
@@ -46,10 +84,12 @@ public interface WxMpMaterialService {
/**
*
* 上传图文消息内的图片获取URL
- * 详情请见:http://mp.weixin.qq.com/wiki/15/40b6865b893947b764e2de8e4a1fb55f.html#.E4.B8.8A.E4.BC.A0.E5.9B.BE.E6.96.87.E6.B6.88.E6.81.AF.E5.86.85.E7.9A.84.E5.9B.BE.E7.89.87.E8.8E.B7.E5.8F.96URL.E3.80.90.E8.AE.A2.E9.98.85.E5.8F.B7.E4.B8.8E.E6.9C.8D.E5.8A.A1.E5.8F.B7.E8.AE.A4.E8.AF.81.E5.90.8E.E5.9D.87.E5.8F.AF.E7.94.A8.E3.80.91
+ * 请注意,本接口所上传的图片不占用公众号的素材库中图片数量的5000个的限制。图片仅支持jpg/png格式,大小必须在1MB以下。
+ * 详情请见: 新增永久素材
+ * 接口url格式:https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token=ACCESS_TOKEN
*
*
- * @param file
+ * @param file 上传的文件对象
* @return WxMediaImgUploadResult 返回图片url
* @throws WxErrorException
*/
@@ -57,114 +97,123 @@ public interface WxMpMaterialService {
/**
*
- * 新增临时素材
- * 本接口即为原“上传多媒体文件”接口。
- *
- * 上传的多媒体文件有格式和大小限制,如下:
- * 图片(image): 1M,支持JPG格式
- * 语音(voice):2M,播放长度不超过60s,支持AMR\MP3格式
- * 视频(video):10MB,支持MP4格式
- * 缩略图(thumb):64KB,支持JPG格式
- *
- * 详情请见: 新增临时素材
- *
- *
- * @param mediaType 媒体类型, 请看{@link me.chanjar.weixin.common.api.WxConsts}
- * @param fileType 文件类型,请看{@link me.chanjar.weixin.common.api.WxConsts}
- * @param inputStream 输入流
- * @throws WxErrorException
- */
- WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream inputStream) throws WxErrorException, IOException;
-
- /**
- *
- * 上传非图文永久素材
- *
- * 上传的多媒体文件有格式和大小限制,如下:
- * 图片(image): 图片大小不超过2M,支持bmp/png/jpeg/jpg/gif格式
- * 语音(voice):语音大小不超过5M,长度不超过60秒,支持mp3/wma/wav/amr格式
- * 视频(video):在上传视频素材时需要POST另一个表单,id为description,包含素材的描述信息,内容格式为JSON
- * 缩略图(thumb):文档未说明
- *
- * 详情请见: http://mp.weixin.qq.com/wiki/14/7e6c03263063f4813141c3e17dd4350a.html
+ * 新增非图文永久素材
+ * 通过POST表单来调用接口,表单id为media,包含需要上传的素材内容,有filename、filelength、content-type等信息。请注意:图片素材将进入公众平台官网素材管理模块中的默认分组。
+ * 新增永久视频素材需特别注意:
+ * 在上传视频素材时需要POST另一个表单,id为description,包含素材的描述信息,内容格式为JSON,格式如下:
+ * { "title":VIDEO_TITLE, "introduction":INTRODUCTION }
+ * 详情请见: 新增永久素材
+ * 接口url格式:https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=ACCESS_TOKEN&type=TYPE
+ *
+ * 除了3天就会失效的临时素材外,开发者有时需要永久保存一些素材,届时就可以通过本接口新增永久素材。
+ 永久图片素材新增后,将带有URL返回给开发者,开发者可以在腾讯系域名内使用(腾讯系域名外使用,图片将被屏蔽)。
+ 请注意:
+ 1、新增的永久素材也可以在公众平台官网素材管理模块中看到
+ 2、永久素材的数量是有上限的,请谨慎新增。图文消息素材和图片素材的上限为5000,其他类型为1000
+ 3、素材的格式大小等要求与公众平台官网一致。具体是,图片大小不超过2M,支持bmp/png/jpeg/jpg/gif格式,语音大小不超过5M,长度不超过60秒,支持mp3/wma/wav/amr格式
+ 4、调用该接口需https协议
*
*
* @param mediaType 媒体类型, 请看{@link me.chanjar.weixin.common.api.WxConsts}
- * @param material 上传的素材, 请看{@link me.chanjar.weixin.mp.bean.WxMpMaterial}
+ * @param material 上传的素材, 请看{@link WxMpMaterial}
*/
WxMpMaterialUploadResult materialFileUpload(String mediaType, WxMpMaterial material) throws WxErrorException;
/**
*
- * 上传永久图文素材
- *
- * 详情请见: http://mp.weixin.qq.com/wiki/14/7e6c03263063f4813141c3e17dd4350a.html
+ * 新增永久图文素材
+ *
+ * 详情请见: 新增永久素材
+ * 接口url格式:https://api.weixin.qq.com/cgi-bin/material/add_news?access_token=ACCESS_TOKEN
+ *
+ * 除了3天就会失效的临时素材外,开发者有时需要永久保存一些素材,届时就可以通过本接口新增永久素材。
+ 永久图片素材新增后,将带有URL返回给开发者,开发者可以在腾讯系域名内使用(腾讯系域名外使用,图片将被屏蔽)。
+ 请注意:
+ 1、新增的永久素材也可以在公众平台官网素材管理模块中看到
+ 2、永久素材的数量是有上限的,请谨慎新增。图文消息素材和图片素材的上限为5000,其他类型为1000
+ 3、素材的格式大小等要求与公众平台官网一致。具体是,图片大小不超过2M,支持bmp/png/jpeg/jpg/gif格式,语音大小不超过5M,长度不超过60秒,支持mp3/wma/wav/amr格式
+ 4、调用该接口需https协议
*
*
- * @param news 上传的图文消息, 请看{@link me.chanjar.weixin.mp.bean.WxMpMaterialNews}
+ * @param news 上传的图文消息, 请看{@link WxMpMaterialNews}
*/
WxMpMaterialUploadResult materialNewsUpload(WxMpMaterialNews news) throws WxErrorException;
/**
*
- * 下载声音或者图片永久素材
+ * 获取声音或者图片永久素材
*
- * 详情请见: http://mp.weixin.qq.com/wiki/4/b3546879f07623cb30df9ca0e420a5d0.html
+ * 详情请见: 获取永久素材
+ * 接口url格式:https://api.weixin.qq.com/cgi-bin/material/get_material?access_token=ACCESS_TOKEN
*
*
- * @param media_id 永久素材的id
+ * @param mediaId 永久素材的id
*/
- InputStream materialImageOrVoiceDownload(String media_id) throws WxErrorException;
+ InputStream materialImageOrVoiceDownload(String mediaId) throws WxErrorException;
/**
*
* 获取视频永久素材的信息和下载地址
*
- * 详情请见: http://mp.weixin.qq.com/wiki/4/b3546879f07623cb30df9ca0e420a5d0.html
+ * 详情请见: 获取永久素材
+ * 接口url格式:https://api.weixin.qq.com/cgi-bin/material/get_material?access_token=ACCESS_TOKEN
*
*
- * @param media_id 永久素材的id
+ * @param mediaId 永久素材的id
*/
- WxMpMaterialVideoInfoResult materialVideoInfo(String media_id) throws WxErrorException;
+ WxMpMaterialVideoInfoResult materialVideoInfo(String mediaId) throws WxErrorException;
/**
*
* 获取图文永久素材的信息
*
- * 详情请见: http://mp.weixin.qq.com/wiki/4/b3546879f07623cb30df9ca0e420a5d0.html
+ * 详情请见: 获取永久素材
+ * 接口url格式:https://api.weixin.qq.com/cgi-bin/material/get_material?access_token=ACCESS_TOKEN
*
*
- * @param media_id 永久素材的id
+ * @param mediaId 永久素材的id
*/
- WxMpMaterialNews materialNewsInfo(String media_id) throws WxErrorException;
+ WxMpMaterialNews materialNewsInfo(String mediaId) throws WxErrorException;
/**
*
- * 更新图文永久素材
+ * 修改永久图文素材
*
- * 详情请见: http://mp.weixin.qq.com/wiki/4/19a59cba020d506e767360ca1be29450.html
+ * 详情请见: 修改永久图文素材
+ * 接口url格式:https://api.weixin.qq.com/cgi-bin/material/update_news?access_token=ACCESS_TOKEN
*
*
- * @param wxMpMaterialArticleUpdate 用来更新图文素材的bean, 请看{@link me.chanjar.weixin.mp.bean.WxMpMaterialArticleUpdate}
+ * @param wxMpMaterialArticleUpdate 用来更新图文素材的bean, 请看{@link WxMpMaterialArticleUpdate}
*/
boolean materialNewsUpdate(WxMpMaterialArticleUpdate wxMpMaterialArticleUpdate) throws WxErrorException;
/**
*
* 删除永久素材
- *
- * 详情请见: http://mp.weixin.qq.com/wiki/5/e66f61c303db51a6c0f90f46b15af5f5.html
+ * 在新增了永久素材后,开发者可以根据本接口来删除不再需要的永久素材,节省空间。
+ * 请注意:
+ * 1、请谨慎操作本接口,因为它可以删除公众号在公众平台官网素材管理模块中新建的图文消息、语音、视频等素材(但需要先通过获取素材列表来获知素材的media_id)
+ * 2、临时素材无法通过本接口删除
+ * 3、调用该接口需https协议
+ * 详情请见: 删除永久素材
+ * 接口url格式:https://api.weixin.qq.com/cgi-bin/material/del_material?access_token=ACCESS_TOKEN
*
*
- * @param media_id 永久素材的id
+ * @param mediaId 永久素材的id
*/
- boolean materialDelete(String media_id) throws WxErrorException;
+ boolean materialDelete(String mediaId) throws WxErrorException;
/**
*
* 获取各类素材总数
- *
- * 详情请见: http://mp.weixin.qq.com/wiki/16/8cc64f8c189674b421bee3ed403993b8.html
+ * 开发者可以根据本接口来获取永久素材的列表,需要时也可保存到本地。
+ * 请注意:
+ * 1.永久素材的总数,也会计算公众平台官网素材管理中的素材
+ * 2.图片和图文消息素材(包括单图文和多图文)的总数上限为5000,其他素材的总数上限为1000
+ * 3.调用该接口需https协议
+ *
+ * 详情请见: 获取素材总数
+ * 接口url格式:https://api.weixin.qq.com/cgi-bin/material/get_materialcount?access_token=ACCESS_TOKEN
*
*/
WxMpMaterialCountResult materialCount() throws WxErrorException;
@@ -173,7 +222,8 @@ public interface WxMpMaterialService {
*
* 分页获取图文素材列表
*
- * 详情请见: http://mp.weixin.qq.com/wiki/12/2108cd7aafff7f388f41f37efa710204.html
+ * 详情请见: 获取素材列表
+ * 接口url格式:https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token=ACCESS_TOKEN
*
*
* @param offset 从全部素材的该偏移位置开始返回,0表示从第一个素材 返回
@@ -185,7 +235,8 @@ public interface WxMpMaterialService {
*
* 分页获取其他媒体素材列表
*
- * 详情请见: http://mp.weixin.qq.com/wiki/12/2108cd7aafff7f388f41f37efa710204.html
+ * 详情请见: 获取素材列表
+ * 接口url格式:https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token=ACCESS_TOKEN
*
*
* @param type 媒体类型, 请看{@link me.chanjar.weixin.common.api.WxConsts}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageHandler.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageHandler.java
index dae2a238..5a336bc8 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageHandler.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageHandler.java
@@ -2,8 +2,8 @@ package me.chanjar.weixin.mp.api;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
-import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
-import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
+import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
+import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import java.util.Map;
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageInterceptor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageInterceptor.java
index 3fcd6d95..15223895 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageInterceptor.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageInterceptor.java
@@ -2,7 +2,7 @@ package me.chanjar.weixin.mp.api;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
-import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
+import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import java.util.Map;
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageMatcher.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageMatcher.java
index 68798ae2..812992c9 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageMatcher.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageMatcher.java
@@ -1,6 +1,6 @@
package me.chanjar.weixin.mp.api;
-import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
+import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
/**
* 消息匹配器,用在消息路由的时候
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouter.java
index 7db50e79..24dc4451 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouter.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouter.java
@@ -1,230 +1,230 @@
-package me.chanjar.weixin.mp.api;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import me.chanjar.weixin.common.api.WxErrorExceptionHandler;
-import me.chanjar.weixin.common.api.WxMessageDuplicateChecker;
-import me.chanjar.weixin.common.api.WxMessageInMemoryDuplicateChecker;
-import me.chanjar.weixin.common.session.InternalSession;
-import me.chanjar.weixin.common.session.InternalSessionManager;
-import me.chanjar.weixin.common.session.StandardSessionManager;
-import me.chanjar.weixin.common.session.WxSessionManager;
-import me.chanjar.weixin.common.util.LogExceptionHandler;
-import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
-import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
-
-/**
- *
- * 微信消息路由器,通过代码化的配置,把来自微信的消息交给handler处理
- *
- * 说明:
- * 1. 配置路由规则时要按照从细到粗的原则,否则可能消息可能会被提前处理
- * 2. 默认情况下消息只会被处理一次,除非使用 {@link WxMpMessageRouterRule#next()}
- * 3. 规则的结束必须用{@link WxMpMessageRouterRule#end()}或者{@link WxMpMessageRouterRule#next()},否则不会生效
- *
- * 使用方法:
- * WxMpMessageRouter router = new WxMpMessageRouter();
- * router
- * .rule()
- * .msgType("MSG_TYPE").event("EVENT").eventKey("EVENT_KEY").content("CONTENT")
- * .interceptor(interceptor, ...).handler(handler, ...)
- * .end()
- * .rule()
- * // 另外一个匹配规则
- * .end()
- * ;
- *
- * // 将WxXmlMessage交给消息路由器
- * router.route(message);
- *
- *
- * @author Daniel Qian
- *
- */
-public class WxMpMessageRouter {
-
- protected final Logger log = LoggerFactory.getLogger(WxMpMessageRouter.class);
-
- private static final int DEFAULT_THREAD_POOL_SIZE = 100;
-
- private final List rules = new ArrayList<>();
-
- private final WxMpService wxMpService;
-
- private ExecutorService executorService;
-
- private WxMessageDuplicateChecker messageDuplicateChecker;
-
- private WxSessionManager sessionManager;
-
- private WxErrorExceptionHandler exceptionHandler;
-
- public WxMpMessageRouter(WxMpService wxMpService) {
- this.wxMpService = wxMpService;
- this.executorService = Executors.newFixedThreadPool(DEFAULT_THREAD_POOL_SIZE);
- this.messageDuplicateChecker = new WxMessageInMemoryDuplicateChecker();
- this.sessionManager = new StandardSessionManager();
- this.exceptionHandler = new LogExceptionHandler();
- }
-
- /**
- *
- * 设置自定义的 {@link ExecutorService}
- * 如果不调用该方法,默认使用 Executors.newFixedThreadPool(100)
- *
- * @param executorService
- */
- public void setExecutorService(ExecutorService executorService) {
- this.executorService = executorService;
- }
-
- /**
- *
- * 设置自定义的 {@link me.chanjar.weixin.common.api.WxMessageDuplicateChecker}
- * 如果不调用该方法,默认使用 {@link me.chanjar.weixin.common.api.WxMessageInMemoryDuplicateChecker}
- *
- * @param messageDuplicateChecker
- */
- public void setMessageDuplicateChecker(WxMessageDuplicateChecker messageDuplicateChecker) {
- this.messageDuplicateChecker = messageDuplicateChecker;
- }
-
- /**
- *
- * 设置自定义的{@link me.chanjar.weixin.common.session.WxSessionManager}
- * 如果不调用该方法,默认使用 {@link me.chanjar.weixin.common.session.StandardSessionManager}
- *
- * @param sessionManager
- */
- public void setSessionManager(WxSessionManager sessionManager) {
- this.sessionManager = sessionManager;
- }
-
- /**
- *
- * 设置自定义的{@link me.chanjar.weixin.common.api.WxErrorExceptionHandler}
- * 如果不调用该方法,默认使用 {@link me.chanjar.weixin.common.util.LogExceptionHandler}
- *
- * @param exceptionHandler
- */
- public void setExceptionHandler(WxErrorExceptionHandler exceptionHandler) {
- this.exceptionHandler = exceptionHandler;
- }
-
- List getRules() {
- return this.rules;
- }
-
- /**
- * 开始一个新的Route规则
- */
- public WxMpMessageRouterRule rule() {
- return new WxMpMessageRouterRule(this);
- }
-
- /**
- * 处理微信消息
- * @param wxMessage
- */
- public WxMpXmlOutMessage route(final WxMpXmlMessage wxMessage) {
- if (isDuplicateMessage(wxMessage)) {
- // 如果是重复消息,那么就不做处理
- return null;
- }
-
- final List matchRules = new ArrayList<>();
- // 收集匹配的规则
- for (final WxMpMessageRouterRule rule : this.rules) {
- if (rule.test(wxMessage)) {
- matchRules.add(rule);
- if(!rule.isReEnter()) {
- break;
- }
- }
- }
-
- if (matchRules.size() == 0) {
- return null;
- }
-
- WxMpXmlOutMessage res = null;
- final List> futures = new ArrayList<>();
- for (final WxMpMessageRouterRule rule : matchRules) {
- // 返回最后一个非异步的rule的执行结果
- if(rule.isAsync()) {
- futures.add(
- this.executorService.submit(new Runnable() {
- @Override
- public void run() {
- rule.service(wxMessage, WxMpMessageRouter.this.wxMpService, WxMpMessageRouter.this.sessionManager, WxMpMessageRouter.this.exceptionHandler);
- }
- })
- );
- } else {
- res = rule.service(wxMessage, this.wxMpService, this.sessionManager, this.exceptionHandler);
- // 在同步操作结束,session访问结束
- this.log.debug("End session access: async=false, sessionId={}", wxMessage.getFromUser());
- sessionEndAccess(wxMessage);
- }
- }
-
- if (futures.size() > 0) {
- this.executorService.submit(new Runnable() {
- @Override
- public void run() {
- for (Future> future : futures) {
- try {
- future.get();
- WxMpMessageRouter.this.log.debug("End session access: async=true, sessionId={}", wxMessage.getFromUser());
- // 异步操作结束,session访问结束
- sessionEndAccess(wxMessage);
- } catch (InterruptedException e) {
- WxMpMessageRouter.this.log.error("Error happened when wait task finish", e);
- } catch (ExecutionException e) {
- WxMpMessageRouter.this.log.error("Error happened when wait task finish", e);
- }
- }
- }
- });
- }
- return res;
- }
-
- protected boolean isDuplicateMessage(WxMpXmlMessage wxMessage) {
-
- StringBuffer messageId = new StringBuffer();
- if (wxMessage.getMsgId() == null) {
- messageId.append(wxMessage.getCreateTime())
- .append("-").append(wxMessage.getFromUser())
- .append("-").append(wxMessage.getEventKey() == null ? "" : wxMessage.getEventKey())
- .append("-").append(wxMessage.getEvent() == null ? "" : wxMessage.getEvent())
- ;
- } else {
- messageId.append(wxMessage.getMsgId());
- }
-
- return this.messageDuplicateChecker.isDuplicate(messageId.toString());
-
- }
-
- /**
- * 对session的访问结束
- * @param wxMessage
- */
- protected void sessionEndAccess(WxMpXmlMessage wxMessage) {
-
- InternalSession session = ((InternalSessionManager)this.sessionManager).findSession(wxMessage.getFromUser());
- if (session != null) {
- session.endAccess();
- }
-
- }
-}
+package me.chanjar.weixin.mp.api;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import me.chanjar.weixin.common.api.WxErrorExceptionHandler;
+import me.chanjar.weixin.common.api.WxMessageDuplicateChecker;
+import me.chanjar.weixin.common.api.WxMessageInMemoryDuplicateChecker;
+import me.chanjar.weixin.common.session.InternalSession;
+import me.chanjar.weixin.common.session.InternalSessionManager;
+import me.chanjar.weixin.common.session.StandardSessionManager;
+import me.chanjar.weixin.common.session.WxSessionManager;
+import me.chanjar.weixin.common.util.LogExceptionHandler;
+import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
+import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
+
+/**
+ *
+ * 微信消息路由器,通过代码化的配置,把来自微信的消息交给handler处理
+ *
+ * 说明:
+ * 1. 配置路由规则时要按照从细到粗的原则,否则可能消息可能会被提前处理
+ * 2. 默认情况下消息只会被处理一次,除非使用 {@link WxMpMessageRouterRule#next()}
+ * 3. 规则的结束必须用{@link WxMpMessageRouterRule#end()}或者{@link WxMpMessageRouterRule#next()},否则不会生效
+ *
+ * 使用方法:
+ * WxMpMessageRouter router = new WxMpMessageRouter();
+ * router
+ * .rule()
+ * .msgType("MSG_TYPE").event("EVENT").eventKey("EVENT_KEY").content("CONTENT")
+ * .interceptor(interceptor, ...).handler(handler, ...)
+ * .end()
+ * .rule()
+ * // 另外一个匹配规则
+ * .end()
+ * ;
+ *
+ * // 将WxXmlMessage交给消息路由器
+ * router.route(message);
+ *
+ *
+ * @author Daniel Qian
+ *
+ */
+public class WxMpMessageRouter {
+
+ protected final Logger log = LoggerFactory.getLogger(WxMpMessageRouter.class);
+
+ private static final int DEFAULT_THREAD_POOL_SIZE = 100;
+
+ private final List rules = new ArrayList<>();
+
+ private final WxMpService wxMpService;
+
+ private ExecutorService executorService;
+
+ private WxMessageDuplicateChecker messageDuplicateChecker;
+
+ private WxSessionManager sessionManager;
+
+ private WxErrorExceptionHandler exceptionHandler;
+
+ public WxMpMessageRouter(WxMpService wxMpService) {
+ this.wxMpService = wxMpService;
+ this.executorService = Executors.newFixedThreadPool(DEFAULT_THREAD_POOL_SIZE);
+ this.messageDuplicateChecker = new WxMessageInMemoryDuplicateChecker();
+ this.sessionManager = new StandardSessionManager();
+ this.exceptionHandler = new LogExceptionHandler();
+ }
+
+ /**
+ *
+ * 设置自定义的 {@link ExecutorService}
+ * 如果不调用该方法,默认使用 Executors.newFixedThreadPool(100)
+ *
+ * @param executorService
+ */
+ public void setExecutorService(ExecutorService executorService) {
+ this.executorService = executorService;
+ }
+
+ /**
+ *
+ * 设置自定义的 {@link me.chanjar.weixin.common.api.WxMessageDuplicateChecker}
+ * 如果不调用该方法,默认使用 {@link me.chanjar.weixin.common.api.WxMessageInMemoryDuplicateChecker}
+ *
+ * @param messageDuplicateChecker
+ */
+ public void setMessageDuplicateChecker(WxMessageDuplicateChecker messageDuplicateChecker) {
+ this.messageDuplicateChecker = messageDuplicateChecker;
+ }
+
+ /**
+ *
+ * 设置自定义的{@link me.chanjar.weixin.common.session.WxSessionManager}
+ * 如果不调用该方法,默认使用 {@link me.chanjar.weixin.common.session.StandardSessionManager}
+ *
+ * @param sessionManager
+ */
+ public void setSessionManager(WxSessionManager sessionManager) {
+ this.sessionManager = sessionManager;
+ }
+
+ /**
+ *
+ * 设置自定义的{@link me.chanjar.weixin.common.api.WxErrorExceptionHandler}
+ * 如果不调用该方法,默认使用 {@link me.chanjar.weixin.common.util.LogExceptionHandler}
+ *
+ * @param exceptionHandler
+ */
+ public void setExceptionHandler(WxErrorExceptionHandler exceptionHandler) {
+ this.exceptionHandler = exceptionHandler;
+ }
+
+ List getRules() {
+ return this.rules;
+ }
+
+ /**
+ * 开始一个新的Route规则
+ */
+ public WxMpMessageRouterRule rule() {
+ return new WxMpMessageRouterRule(this);
+ }
+
+ /**
+ * 处理微信消息
+ * @param wxMessage
+ */
+ public WxMpXmlOutMessage route(final WxMpXmlMessage wxMessage) {
+ if (isDuplicateMessage(wxMessage)) {
+ // 如果是重复消息,那么就不做处理
+ return null;
+ }
+
+ final List matchRules = new ArrayList<>();
+ // 收集匹配的规则
+ for (final WxMpMessageRouterRule rule : this.rules) {
+ if (rule.test(wxMessage)) {
+ matchRules.add(rule);
+ if(!rule.isReEnter()) {
+ break;
+ }
+ }
+ }
+
+ if (matchRules.size() == 0) {
+ return null;
+ }
+
+ WxMpXmlOutMessage res = null;
+ final List> futures = new ArrayList<>();
+ for (final WxMpMessageRouterRule rule : matchRules) {
+ // 返回最后一个非异步的rule的执行结果
+ if(rule.isAsync()) {
+ futures.add(
+ this.executorService.submit(new Runnable() {
+ @Override
+ public void run() {
+ rule.service(wxMessage, WxMpMessageRouter.this.wxMpService, WxMpMessageRouter.this.sessionManager, WxMpMessageRouter.this.exceptionHandler);
+ }
+ })
+ );
+ } else {
+ res = rule.service(wxMessage, this.wxMpService, this.sessionManager, this.exceptionHandler);
+ // 在同步操作结束,session访问结束
+ this.log.debug("End session access: async=false, sessionId={}", wxMessage.getFromUser());
+ sessionEndAccess(wxMessage);
+ }
+ }
+
+ if (futures.size() > 0) {
+ this.executorService.submit(new Runnable() {
+ @Override
+ public void run() {
+ for (Future> future : futures) {
+ try {
+ future.get();
+ WxMpMessageRouter.this.log.debug("End session access: async=true, sessionId={}", wxMessage.getFromUser());
+ // 异步操作结束,session访问结束
+ sessionEndAccess(wxMessage);
+ } catch (InterruptedException e) {
+ WxMpMessageRouter.this.log.error("Error happened when wait task finish", e);
+ } catch (ExecutionException e) {
+ WxMpMessageRouter.this.log.error("Error happened when wait task finish", e);
+ }
+ }
+ }
+ });
+ }
+ return res;
+ }
+
+ protected boolean isDuplicateMessage(WxMpXmlMessage wxMessage) {
+
+ StringBuffer messageId = new StringBuffer();
+ if (wxMessage.getMsgId() == null) {
+ messageId.append(wxMessage.getCreateTime())
+ .append("-").append(wxMessage.getFromUser())
+ .append("-").append(wxMessage.getEventKey() == null ? "" : wxMessage.getEventKey())
+ .append("-").append(wxMessage.getEvent() == null ? "" : wxMessage.getEvent())
+ ;
+ } else {
+ messageId.append(wxMessage.getMsgId());
+ }
+
+ return this.messageDuplicateChecker.isDuplicate(messageId.toString());
+
+ }
+
+ /**
+ * 对session的访问结束
+ * @param wxMessage
+ */
+ protected void sessionEndAccess(WxMpXmlMessage wxMessage) {
+
+ InternalSession session = ((InternalSessionManager)this.sessionManager).findSession(wxMessage.getFromUser());
+ if (session != null) {
+ session.endAccess();
+ }
+
+ }
+}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouterRule.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouterRule.java
index 317303b8..6859b7d7 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouterRule.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouterRule.java
@@ -3,8 +3,8 @@ package me.chanjar.weixin.mp.api;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.common.api.WxErrorExceptionHandler;
-import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
-import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
+import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
+import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import java.util.ArrayList;
import java.util.HashMap;
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java
index 72eabd08..2fcd4cb9 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java
@@ -1,16 +1,16 @@
package me.chanjar.weixin.mp.api;
-import java.util.Map;
-
import me.chanjar.weixin.common.exception.WxErrorException;
-import me.chanjar.weixin.mp.bean.pay.WxMpPayCallback;
-import me.chanjar.weixin.mp.bean.pay.WxMpPayRefundResult;
-import me.chanjar.weixin.mp.bean.pay.WxMpPayResult;
-import me.chanjar.weixin.mp.bean.pay.WxMpPrepayIdResult;
-import me.chanjar.weixin.mp.bean.pay.WxRedpackResult;
-import me.chanjar.weixin.mp.bean.pay.WxSendRedpackRequest;
-import me.chanjar.weixin.mp.bean.pay.WxUnifiedOrderRequest;
-import me.chanjar.weixin.mp.bean.pay.WxUnifiedOrderResult;
+import me.chanjar.weixin.mp.bean.pay.WxPayJsSDKCallback;
+import me.chanjar.weixin.mp.bean.pay.result.WxPayOrderCloseResult;
+import me.chanjar.weixin.mp.bean.pay.request.WxEntPayRequest;
+import me.chanjar.weixin.mp.bean.pay.request.WxPayRefundRequest;
+import me.chanjar.weixin.mp.bean.pay.request.WxPaySendRedpackRequest;
+import me.chanjar.weixin.mp.bean.pay.request.WxPayUnifiedOrderRequest;
+import me.chanjar.weixin.mp.bean.pay.result.*;
+
+import java.io.File;
+import java.util.Map;
/**
* 微信支付相关接口
@@ -19,53 +19,74 @@ import me.chanjar.weixin.mp.bean.pay.WxUnifiedOrderResult;
*/
public interface WxMpPayService {
+ /**
+ *
+ * 查询订单(详见https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2)
+ * 该接口提供所有微信支付订单的查询,商户可以通过查询订单接口主动查询订单状态,完成下一步的业务逻辑。
+ * 需要调用查询接口的情况:
+ ◆ 当商户后台、网络、服务器等出现异常,商户系统最终未接收到支付通知;
+ ◆ 调用支付接口后,返回系统错误或未知交易状态情况;
+ ◆ 调用被扫支付API,返回USERPAYING的状态;
+ ◆ 调用关单或撤销接口API之前,需确认支付状态;
+ * 接口地址:https://api.mch.weixin.qq.com/pay/orderquery
+ *
+ * @param transactionId 微信支付分配的商户号
+ * @param outTradeNo 商户系统内部的订单号,当没提供transaction_id时需要传这个。
+ * @throws WxErrorException
+ */
+ WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) throws WxErrorException;
+
+ /**
+ *
+ * 关闭订单
+ * 应用场景
+ * 以下情况需要调用关单接口:
+ * 1. 商户订单支付失败需要生成新单号重新发起支付,要对原订单号调用关单,避免重复支付;
+ * 2. 系统下单后,用户支付超时,系统退出不再受理,避免用户继续,请调用关单接口。
+ * 注意:订单生成后不能马上调用关单接口,最短调用时间间隔为5分钟。
+ * 接口地址:https://api.mch.weixin.qq.com/pay/closeorder
+ * 是否需要证书: 不需要。
+ *
+ * @param outTradeNo 商户系统内部的订单号,当没提供transaction_id时需要传这个。
+ * @throws WxErrorException
+ */
+ WxPayOrderCloseResult closeOrder(String outTradeNo) throws WxErrorException;
+
/**
* 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1)
* 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识"
* 接口地址:https://api.mch.weixin.qq.com/pay/unifiedorder
- * @throws WxErrorException
+ * @throws WxErrorException
+ * @param request 请求对象
*
*/
- WxUnifiedOrderResult unifiedOrder(WxUnifiedOrderRequest request)
- throws WxErrorException;
+ WxPayUnifiedOrderResult unifiedOrder(WxPayUnifiedOrderRequest request) throws WxErrorException;
/**
* 该接口调用“统一下单”接口,并拼装发起支付请求需要的参数
* 详见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN
- *
+ * @param request 请求对象
*/
- Map getPayInfo(WxUnifiedOrderRequest request) throws WxErrorException;
-
+ Map getPayInfo(WxPayUnifiedOrderRequest request) throws WxErrorException;
/**
- * 该接口提供所有微信支付订单的查询,当支付通知处理异常戒丢失的情冴,商户可以通过该接口查询订单支付状态。
- * 详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2
- * @throws WxErrorException
- *
+ *
+ * 微信支付-申请退款
+ * 详见 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4
+ * 接口链接:https://api.mch.weixin.qq.com/secapi/pay/refund
+ *
+ * @param request 请求对象
+ * @param keyFile 证书文件对象
+ * @return 退款操作结果
*/
- WxMpPayResult getJSSDKPayResult(String transactionId, String outTradeNo)
- throws WxErrorException;
+ WxPayRefundResult refund(WxPayRefundRequest request, File keyFile) throws WxErrorException;
/**
* 读取支付结果通知
* 详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7
*
*/
- WxMpPayCallback getJSSDKCallbackData(String xmlData);
-
- /**
- * 微信支付-申请退款
- * 详见 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4
- *
- * @param parameters 需要传入的退款参数的Map。以下几项为参数的必须项:
- * transaction_id
- * out_trade_no (仅在上述transaction_id为空时是必须项)
- * out_refund_no
- * total_fee
- * refund_fee
- * @return 退款操作结果
- */
- WxMpPayRefundResult refundPay(Map parameters) throws WxErrorException;
+ WxPayJsSDKCallback getJSSDKCallbackData(String xmlData) throws WxErrorException;
/**
*
@@ -78,12 +99,40 @@ public interface WxMpPayService {
/**
* 发送微信红包给个人用户
- *
+ *
* 文档详见:
* 发送普通红包 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_4&index=3
* 发送裂变红包 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_5&index=4
*
+ * @param request 请求对象
+ * @param keyFile 证书文件对象
+ */
+ WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request, File keyFile) throws WxErrorException;
+
+ /**
+ *
+ * 企业付款业务是基于微信支付商户平台的资金管理能力,为了协助商户方便地实现企业向个人付款,针对部分有开发能力的商户,提供通过API完成企业付款的功能。
+ * 比如目前的保险行业向客户退保、给付、理赔。
+ * 企业付款将使用商户的可用余额,需确保可用余额充足。查看可用余额、充值、提现请登录商户平台“资金管理”https://pay.weixin.qq.com/进行操作。
+ * 注意:与商户微信支付收款资金并非同一账户,需要单独充值。
+ * 文档详见:https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_2
+ * 接口链接:https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers
+ *
+ * @param request 请求对象
+ * @param keyFile 证书文件对象
+ */
+ WxEntPayResult entPay(WxEntPayRequest request, File keyFile) throws WxErrorException;
+
+ /**
+ *
+ * 查询企业付款API
+ * 用于商户的企业付款操作进行结果查询,返回付款操作详细结果。
+ * 文档详见:https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_3
+ * 接口链接:https://api.mch.weixin.qq.com/mmpaymkttransfers/gettransferinfo
+ *
+ * @param partnerTradeNo 商户订单号
+ * @param keyFile 证书文件对象
*/
- WxRedpackResult sendRedpack(WxSendRedpackRequest request) throws WxErrorException;
+ WxEntPayQueryResult queryEntPay(String partnerTradeNo, File keyFile) throws WxErrorException;
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java
index 292c5645..a74e718d 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java
@@ -3,19 +3,9 @@ package me.chanjar.weixin.mp.api;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestExecutor;
-import me.chanjar.weixin.mp.bean.WxMpIndustry;
-import me.chanjar.weixin.mp.bean.WxMpMassTagMessage;
-import me.chanjar.weixin.mp.bean.WxMpMassNews;
-import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage;
-import me.chanjar.weixin.mp.bean.WxMpMassPreviewMessage;
-import me.chanjar.weixin.mp.bean.WxMpMassVideo;
-import me.chanjar.weixin.mp.bean.WxMpSemanticQuery;
-import me.chanjar.weixin.mp.bean.WxMpTemplateMessage;
-import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult;
-import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult;
-import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
-import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult;
-import me.chanjar.weixin.mp.bean.result.WxMpUser;
+import me.chanjar.weixin.mp.bean.*;
+import me.chanjar.weixin.mp.bean.result.*;
+import org.apache.http.HttpHost;
/**
* 微信API的Service
@@ -126,22 +116,26 @@ public interface WxMpService {
/**
*
- * 长链接转短链接接口
- * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=长链接转短链接接口
+ * 群发消息预览接口
+ * 开发者可通过该接口发送消息给指定用户,在手机端查看消息的样式和排版。为了满足第三方平台开发者的需求,在保留对openID预览能力的同时,增加了对指定微信号发送预览的能力,但该能力每日调用次数有限制(100次),请勿滥用。
+ * 接口调用请求说明
+ * http请求方式: POST
+ * https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token=ACCESS_TOKEN
+ * 详情请见:http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140549&token=&lang=zh_CN
*
*
+ * @return wxMpMassSendResult
*/
- String shortUrl(String long_url) throws WxErrorException;
+ WxMpMassSendResult massMessagePreview(WxMpMassPreviewMessage wxMpMassPreviewMessage) throws Exception;
/**
*
- * 发送模板消息
- * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=模板消息接口
+ * 长链接转短链接接口
+ * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=长链接转短链接接口
*
*
- * @return msgid
*/
- String templateSend(WxMpTemplateMessage templateMessage) throws WxErrorException;
+ String shortUrl(String long_url) throws WxErrorException;
/**
*
@@ -235,6 +229,11 @@ public interface WxMpService {
*/
T execute(RequestExecutor executor, String uri, E data) throws WxErrorException;
+ /**
+ * 获取代理对象
+ */
+ HttpHost getHttpProxy();
+
/**
* 注入 {@link WxMpConfigStorage} 的实现
*/
@@ -256,37 +255,6 @@ public interface WxMpService {
*/
void setMaxRetryTimes(int maxRetryTimes);
- /**
- *
- * 预览接口
- * 详情请见:http://mp.weixin.qq.com/wiki/15/40b6865b893947b764e2de8e4a1fb55f.html#.E9.A2.84.E8.A7.88.E6.8E.A5.E5.8F.A3.E3.80.90.E8.AE.A2.E9.98.85.E5.8F.B7.E4.B8.8E.E6.9C.8D.E5.8A.A1.E5.8F.B7.E8.AE.A4.E8.AF.81.E5.90.8E.E5.9D.87.E5.8F.AF.E7.94.A8.E3.80.91
- *
- *
- * @return wxMpMassSendResult
- */
- WxMpMassSendResult massMessagePreview(WxMpMassPreviewMessage wxMpMassPreviewMessage) throws Exception;
-
- /**
- *
- * 设置所属行业
- * 官方文档中暂未告知响应内容
- * 详情请见:http://mp.weixin.qq.com/wiki/5/6dde9eaa909f83354e0094dc3ad99e05.html#.E8.AE.BE.E7.BD.AE.E6.89.80.E5.B1.9E.E8.A1.8C.E4.B8.9A
- *
- *
- * @return JsonObject
- */
- String setIndustry(WxMpIndustry wxMpIndustry) throws WxErrorException;
-
- /***
- *
- * 获取设置的行业信息
- * 详情请见:http://mp.weixin.qq.com/wiki/5/6dde9eaa909f83354e0094dc3ad99e05.html#.E8.AE.BE.E7.BD.AE.E6.89.80.E5.B1.9E.E8.A1.8C.E4.B8.9A
- *
- *
- * @return wxMpIndustry
- */
- WxMpIndustry getIndustry() throws WxErrorException;
-
/**
* 获取WxMpConfigStorage 对象
*
@@ -370,4 +338,11 @@ public interface WxMpService {
* @return WxMpStoreService
*/
WxMpStoreService getStoreService();
+
+ /**
+ * 返回模板消息相关接口方法的实现类对象,以方便调用其各种接口
+ *
+ * @return WxMpTemplateMsgService
+ */
+ WxMpTemplateMsgService getTemplateMsgService();
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpStoreService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpStoreService.java
index 0ce7cc03..c214c46d 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpStoreService.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpStoreService.java
@@ -9,7 +9,7 @@ import java.util.List;
/**
* 门店管理的相关接口代码
- * @author binarywang(https://github.com/binarywang)
+ * @author binarywang(Binary Wang)
* Created by Binary Wang on 2016-09-23.
*/
public interface WxMpStoreService {
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpTemplateMsgService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpTemplateMsgService.java
new file mode 100644
index 00000000..9b66f722
--- /dev/null
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpTemplateMsgService.java
@@ -0,0 +1,87 @@
+package me.chanjar.weixin.mp.api;
+
+import me.chanjar.weixin.common.exception.WxErrorException;
+import me.chanjar.weixin.mp.bean.template.WxMpTemplate;
+import me.chanjar.weixin.mp.bean.template.WxMpTemplateIndustry;
+import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
+
+import java.util.List;
+
+/**
+ *
+ * 模板消息接口
+ * http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277&token=&lang=zh_CN
+ * Created by Binary Wang on 2016-10-14.
+ * @author miller.lin
+ * @author binarywang(Binary Wang)
+ *
+ */
+public interface WxMpTemplateMsgService {
+
+ /**
+ *
+ * 设置所属行业
+ * 官方文档中暂未告知响应内容
+ * 详情请见:http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277&token=&lang=zh_CN
+ *
+ *
+ * @return 是否成功
+ */
+ boolean setIndustry(WxMpTemplateIndustry wxMpIndustry) throws WxErrorException;
+
+ /***
+ *
+ * 获取设置的行业信息
+ * 详情请见:http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277&token=&lang=zh_CN
+ *
+ *
+ * @return wxMpIndustry
+ */
+ WxMpTemplateIndustry getIndustry() throws WxErrorException;
+
+ /**
+ *
+ * 发送模板消息
+ * 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277&token=&lang=zh_CN
+ *
+ *
+ * @return 消息Id
+ */
+ String sendTemplateMsg(WxMpTemplateMessage templateMessage) throws WxErrorException;
+
+ /**
+ *
+ * 获得模板ID
+ * 从行业模板库选择模板到帐号后台,获得模板ID的过程可在MP中完成
+ * 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277&token=&lang=zh_CN
+ * 接口地址格式:https://api.weixin.qq.com/cgi-bin/template/api_add_template?access_token=ACCESS_TOKEN
+ *
+ * @param shortTemplateId 模板库中模板的编号,有“TM**”和“OPENTMTM**”等形式
+ * @return templateId 模板Id
+ */
+ String addTemplate(String shortTemplateId) throws WxErrorException;
+
+ /**
+ *
+ * 获取模板列表
+ * 获取已添加至帐号下所有模板列表,可在MP中查看模板列表信息,为方便第三方开发者,提供通过接口调用的方式来获取帐号下所有模板信息
+ * 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277&token=&lang=zh_CN
+ * 接口地址格式:https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token=ACCESS_TOKEN
+ *
+ *
+ * @return templateId 模板Id
+ */
+ List getAllPrivateTemplate() throws WxErrorException;
+
+ /**
+ *
+ * 删除模板
+ * 删除模板可在MP中完成,为方便第三方开发者,提供通过接口调用的方式来删除某帐号下的模板
+ * 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277&token=&lang=zh_CN
+ * 接口地址格式:https://api.weixin.qq.com/cgi-bin/template/del_private_template?access_token=ACCESS_TOKEN
+ *
+ *
+ * @param templateId 模板Id
+ */
+ boolean delPrivateTemplate(String templateId) throws WxErrorException;
+}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserService.java
index f46ca634..96499128 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserService.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserService.java
@@ -1,12 +1,12 @@
package me.chanjar.weixin.mp.api;
-import java.util.List;
-
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.bean.WxMpUserQuery;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import me.chanjar.weixin.mp.bean.result.WxMpUserList;
+import java.util.List;
+
/**
* 用户管理相关操作接口
*
@@ -16,8 +16,10 @@ public interface WxMpUserService {
/**
*
- * 设置用户备注名接口
- * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=设置用户备注名接口
+ * 设置用户备注名
+ * 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140838&token=&lang=zh_CN
+ * http请求方式: POST(请使用https协议)
+ * 接口地址:https://api.weixin.qq.com/cgi-bin/user/info/updateremark?access_token=ACCESS_TOKEN
*
*
* @param openid 用户openid
@@ -25,10 +27,24 @@ public interface WxMpUserService {
*/
void userUpdateRemark(String openid, String remark) throws WxErrorException;
+ /**
+ *
+ * 获取用户基本信息(语言为默认的zh_CN 简体)
+ * 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140839&token=&lang=zh_CN
+ * http请求方式: GET
+ * 接口地址:https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN
+ *
+ *
+ * @param openid 用户openid
+ */
+ WxMpUser userInfo(String openid) throws WxErrorException;
+
/**
*
* 获取用户基本信息
- * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=获取用户基本信息
+ * 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140839&token=&lang=zh_CN
+ * http请求方式: GET
+ * 接口地址:https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN
*
*
* @param openid 用户openid
@@ -39,7 +55,10 @@ public interface WxMpUserService {
/**
*
* 获取用户基本信息列表
- * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=批量获取用户基本信息
+ * 开发者可通过该接口来批量获取用户基本信息。最多支持一次拉取100条。
+ * 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140839&token=&lang=zh_CN
+ * http请求方式: POST
+ * 接口地址:https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=ACCESS_TOKEN
*
*
* @param openids 用户openid列表
@@ -49,7 +68,10 @@ public interface WxMpUserService {
/**
*
* 获取用户基本信息列表
- * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=批量获取用户基本信息
+ * 开发者可通过该接口来批量获取用户基本信息。最多支持一次拉取100条。
+ * 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140839&token=&lang=zh_CN
+ * http请求方式: POST
+ * 接口地址:https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=ACCESS_TOKEN
*
*
* @param userQuery 详细查询参数
@@ -58,8 +80,11 @@ public interface WxMpUserService {
/**
*
- * 获取关注者列表
- * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=获取关注者列表
+ * 获取用户列表
+ * 公众号可通过本接口来获取帐号的关注者列表,关注者列表由一串OpenID(加密后的微信号,每个用户对每个公众号的OpenID是唯一的)组成。一次拉取调用最多拉取10000个关注者的OpenID,可以通过多次拉取的方式来满足需求。
+ * 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140840&token=&lang=zh_CN
+ * http请求方式: GET(请使用https协议)
+ * 接口地址:https://api.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&next_openid=NEXT_OPENID
*
*
* @param nextOpenid 可选,第一个拉取的OPENID,null为从头开始拉取
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java
index 0fcfb40f..4c0ab7c8 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java
@@ -9,7 +9,7 @@ import me.chanjar.weixin.mp.bean.tag.WxUserTag;
/**
* 用户标签管理相关接口
* Created by Binary Wang on 2016/9/2.
- * @author binarywang(https://github.com/binarywang)
+ * @author binarywang(Binary Wang)
*
*/
public interface WxMpUserTagService {
@@ -94,8 +94,8 @@ public interface WxMpUserTagService {
* 详情请见:用户标签管理
* 接口url格式: https://api.weixin.qq.com/cgi-bin/tags/getidlist?access_token=ACCESS_TOKEN
*
- *
+ * @return 标签Id的列表
*/
- List userTagList(String openid) throws WxErrorException;
+ List userTagList(String openid) throws WxErrorException;
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImpl.java
index 99428348..09a68adf 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImpl.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImpl.java
@@ -1,21 +1,28 @@
package me.chanjar.weixin.mp.api.impl;
+import java.io.File;
+import java.util.Date;
+
+import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import com.google.gson.JsonObject;
+
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
import me.chanjar.weixin.mp.api.WxMpKefuService;
import me.chanjar.weixin.mp.api.WxMpService;
-import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest;
import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfSessionRequest;
-import me.chanjar.weixin.mp.bean.kefu.result.*;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.util.Date;
+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;
/**
*
@@ -34,11 +41,11 @@ public class WxMpKefuServiceImpl implements WxMpKefuService {
}
@Override
- public boolean customMessageSend(WxMpCustomMessage message)
+ public boolean sendKefuMessage(WxMpKefuMessage message)
throws WxErrorException {
String url = "https://api.weixin.qq.com/cgi-bin/message/custom/send";
String responseContent = this.wxMpService.post(url, message.toJson());
- return true;
+ return responseContent != null;
}
@Override
@@ -60,7 +67,7 @@ public class WxMpKefuServiceImpl implements WxMpKefuService {
throws WxErrorException {
String url = API_URL_PREFIX + "/kfaccount/add";
String responseContent = this.wxMpService.post(url, request.toJson());
- return true;
+ return responseContent != null;
}
@Override
@@ -68,14 +75,14 @@ public class WxMpKefuServiceImpl implements WxMpKefuService {
throws WxErrorException {
String url = API_URL_PREFIX + "/kfaccount/update";
String responseContent = this.wxMpService.post(url, request.toJson());
- return true;
+ return responseContent != null;
}
@Override
public boolean kfAccountInviteWorker(WxMpKfAccountRequest request) throws WxErrorException {
String url = API_URL_PREFIX + "/kfaccount/inviteworker";
String responseContent = this.wxMpService.post(url, request.toJson());
- return true;
+ return responseContent != null;
}
@Override
@@ -84,14 +91,14 @@ public class WxMpKefuServiceImpl implements WxMpKefuService {
String url = API_URL_PREFIX + "/kfaccount/uploadheadimg?kf_account=" + kfAccount;
WxMediaUploadResult responseContent = this.wxMpService
.execute(new MediaUploadRequestExecutor(), url, imgFile);
- return true;
+ return responseContent != null;
}
@Override
public boolean kfAccountDel(String kfAccount) throws WxErrorException {
String url = API_URL_PREFIX + "/kfaccount/del?kf_account=" + kfAccount;
String responseContent = this.wxMpService.get(url, null);
- return true;
+ return responseContent != null;
}
@Override
@@ -100,7 +107,7 @@ public class WxMpKefuServiceImpl implements WxMpKefuService {
WxMpKfSessionRequest request = new WxMpKfSessionRequest(kfAccount, openid);
String url = API_URL_PREFIX + "/kfsession/create";
String responseContent = this.wxMpService.post(url, request.toJson());
- return true;
+ return responseContent != null;
}
@Override
@@ -109,7 +116,7 @@ public class WxMpKefuServiceImpl implements WxMpKefuService {
WxMpKfSessionRequest request = new WxMpKfSessionRequest(kfAccount, openid);
String url = API_URL_PREFIX + "/kfsession/close";
String responseContent = this.wxMpService.post(url, request.toJson());
- return true;
+ return responseContent != null;
}
@Override
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImpl.java
index 310bbe78..af9fa54c 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImpl.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImpl.java
@@ -10,10 +10,10 @@ import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import me.chanjar.weixin.mp.api.WxMpMaterialService;
import me.chanjar.weixin.mp.api.WxMpService;
-import me.chanjar.weixin.mp.bean.WxMpMaterial;
-import me.chanjar.weixin.mp.bean.WxMpMaterialArticleUpdate;
-import me.chanjar.weixin.mp.bean.WxMpMaterialNews;
-import me.chanjar.weixin.mp.bean.result.*;
+import me.chanjar.weixin.mp.bean.material.WxMpMaterial;
+import me.chanjar.weixin.mp.bean.material.WxMpMaterialArticleUpdate;
+import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews;
+import me.chanjar.weixin.mp.bean.material.*;
import me.chanjar.weixin.mp.util.http.*;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
@@ -37,8 +37,13 @@ public class WxMpMaterialServiceImpl implements WxMpMaterialService {
}
@Override
- public WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream inputStream) throws WxErrorException, IOException {
- return this.mediaUpload(mediaType, FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), fileType));
+ public WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream inputStream) throws WxErrorException {
+ try {
+ return this.mediaUpload(mediaType, FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), fileType));
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new WxErrorException(WxError.newBuilder().setErrorMsg(e.getMessage()).build());
+ }
}
@Override
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java
index dcb1e89f..3273cd2b 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java
@@ -1,37 +1,39 @@
package me.chanjar.weixin.mp.api.impl;
-import java.lang.reflect.Field;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.SortedMap;
-import java.util.TreeMap;
-
-import org.apache.commons.codec.digest.DigestUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.joor.Reflect;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
import com.thoughtworks.xstream.XStream;
-import com.thoughtworks.xstream.annotations.XStreamAlias;
-
-import me.chanjar.weixin.common.annotation.Required;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
+import me.chanjar.weixin.common.util.BeanUtils;
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
import me.chanjar.weixin.mp.api.WxMpPayService;
import me.chanjar.weixin.mp.api.WxMpService;
-import me.chanjar.weixin.mp.bean.pay.WxMpPayCallback;
-import me.chanjar.weixin.mp.bean.pay.WxMpPayRefundResult;
-import me.chanjar.weixin.mp.bean.pay.WxMpPayResult;
-import me.chanjar.weixin.mp.bean.pay.WxRedpackResult;
-import me.chanjar.weixin.mp.bean.pay.WxSendRedpackRequest;
-import me.chanjar.weixin.mp.bean.pay.WxUnifiedOrderRequest;
-import me.chanjar.weixin.mp.bean.pay.WxUnifiedOrderResult;
+import me.chanjar.weixin.mp.bean.pay.WxPayJsSDKCallback;
+import me.chanjar.weixin.mp.bean.pay.result.WxPayOrderCloseResult;
+import me.chanjar.weixin.mp.bean.pay.request.*;
+import me.chanjar.weixin.mp.bean.pay.result.*;
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.http.Consts;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.conn.ssl.DefaultHostnameVerifier;
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.ssl.SSLContexts;
+import org.apache.http.util.EntityUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.net.ssl.SSLContext;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.security.KeyStore;
+import java.util.*;
/**
* Created by Binary Wang on 2016/7/28.
@@ -40,9 +42,13 @@ import me.chanjar.weixin.mp.bean.pay.WxUnifiedOrderResult;
*/
public class WxMpPayServiceImpl implements WxMpPayService {
- private static final List TRADE_TYPES = Lists.newArrayList("JSAPI",
- "NATIVE", "APP");
- private final Logger log = LoggerFactory.getLogger(WxMpPayServiceImpl.class);
+ protected final Logger log = LoggerFactory.getLogger(this.getClass());
+
+ private static final String PAY_BASE_URL = "https://api.mch.weixin.qq.com";
+ private static final String[] TRADE_TYPES = new String[]{"JSAPI","NATIVE", "APP"};
+ private static final String[] REFUND_ACCOUNT = new String[]{"REFUND_SOURCE_RECHARGE_FUNDS",
+ "REFUND_SOURCE_UNSETTLED_FUNDS"};
+
private WxMpService wxMpService;
public WxMpPayServiceImpl(WxMpService wxMpService) {
@@ -50,98 +56,64 @@ public class WxMpPayServiceImpl implements WxMpPayService {
}
@Override
- public WxMpPayResult getJSSDKPayResult(String transactionId,
- String outTradeNo) throws WxErrorException {
- String nonce_str = System.currentTimeMillis() + "";
-
- SortedMap packageParams = new TreeMap<>();
- packageParams.put("appid",
- this.wxMpService.getWxMpConfigStorage().getAppId());
- packageParams.put("mch_id",
- this.wxMpService.getWxMpConfigStorage().getPartnerId());
-
- if (transactionId != null && !"".equals(transactionId.trim())) {
- packageParams.put("transaction_id", transactionId);
- } else if (outTradeNo != null && !"".equals(outTradeNo.trim())) {
- packageParams.put("out_trade_no", outTradeNo);
- } else {
- throw new IllegalArgumentException(
- "Either 'transactionId' or 'outTradeNo' must be given.");
- }
+ public WxPayRefundResult refund(WxPayRefundRequest request, File keyFile)
+ throws WxErrorException {
+ checkParameters(request);
- packageParams.put("nonce_str", nonce_str);
- packageParams.put("sign", this.createSign(packageParams,
- this.wxMpService.getWxMpConfigStorage().getPartnerKey()));
+ XStream xstream = XStreamInitializer.getInstance();
+ xstream.processAnnotations(WxPayRefundRequest.class);
+ xstream.processAnnotations(WxPayRefundResult.class);
- StringBuilder request = new StringBuilder("");
- for (Map.Entry para : packageParams.entrySet()) {
- request.append(String.format("<%s>%s%s>", para.getKey(),
- para.getValue(), para.getKey()));
- }
- request.append("");
+ request.setAppid(this.wxMpService.getWxMpConfigStorage().getAppId());
+ String partnerId = this.wxMpService.getWxMpConfigStorage().getPartnerId();
+ request.setMchId(partnerId);
+ request.setNonceStr( System.currentTimeMillis() + "");
+ request.setOpUserId(partnerId);
+ String sign = this.createSign(BeanUtils.xmlBean2Map(request), this.wxMpService.getWxMpConfigStorage().getPartnerKey());
+ request.setSign(sign);
- String url = "https://api.mch.weixin.qq.com/pay/orderquery";
- String responseContent = this.wxMpService.post(url, request.toString());
- XStream xstream = XStreamInitializer.getInstance();
- xstream.alias("xml", WxMpPayResult.class);
- return (WxMpPayResult) xstream.fromXML(responseContent);
+ String url = PAY_BASE_URL + "/secapi/pay/refund";
+ String responseContent = this.executeRequestWithKeyFile(url, keyFile, xstream.toXML(request), partnerId);
+ WxPayRefundResult result = (WxPayRefundResult) xstream.fromXML(responseContent);
+ this.checkResult(result);
+ return result;
}
- @Override
- public WxMpPayCallback getJSSDKCallbackData(String xmlData) {
- try {
- XStream xstream = XStreamInitializer.getInstance();
- xstream.alias("xml", WxMpPayCallback.class);
- return (WxMpPayCallback) xstream.fromXML(xmlData);
- } catch (Exception e) {
- e.printStackTrace();
+ private void checkResult(WxPayBaseResult result) throws WxErrorException {
+ if (!"SUCCESS".equalsIgnoreCase(result.getReturnCode())
+ || !"SUCCESS".equalsIgnoreCase(result.getResultCode())) {
+ throw new WxErrorException(WxError.newBuilder().setErrorCode(-1)
+ .setErrorMsg("返回代码:" + result.getReturnCode() + ", 返回信息: "
+ + result.getReturnMsg() + ", 结果代码: " + result.getResultCode() + ", 错误代码: "
+ + result.getErrCode() + ", 错误详情: " + result.getErrCodeDes())
+ .build());
}
-
- return new WxMpPayCallback();
}
- @Override
- public WxMpPayRefundResult refundPay(Map parameters)
- throws WxErrorException {
- SortedMap refundParams = new TreeMap<>(parameters);
- refundParams.put("appid",
- this.wxMpService.getWxMpConfigStorage().getAppId());
- refundParams.put("mch_id",
- this.wxMpService.getWxMpConfigStorage().getPartnerId());
- refundParams.put("nonce_str", System.currentTimeMillis() + "");
- refundParams.put("op_user_id",
- this.wxMpService.getWxMpConfigStorage().getPartnerId());
- String sign = this.createSign(refundParams,
- this.wxMpService.getWxMpConfigStorage().getPartnerKey());
- refundParams.put("sign", sign);
+ private void checkParameters(WxPayRefundRequest request) throws WxErrorException {
+ BeanUtils.checkRequiredFields(request);
- StringBuilder request = new StringBuilder("");
- for (Map.Entry para : refundParams.entrySet()) {
- request.append(String.format("<%s>%s%s>", para.getKey(),
- para.getValue(), para.getKey()));
+ if (StringUtils.isNotBlank(request.getRefundAccount())) {
+ if(!ArrayUtils.contains(REFUND_ACCOUNT, request.getRefundAccount())){
+ throw new IllegalArgumentException("refund_account目前必须为" + Arrays.toString(REFUND_ACCOUNT) + "其中之一");
+ }
}
- request.append("");
-
- String url = "https://api.mch.weixin.qq.com/secapi/pay/refund";
- String responseContent = this.wxMpService.post(url, request.toString());
- XStream xstream = XStreamInitializer.getInstance();
- xstream.processAnnotations(WxMpPayRefundResult.class);
- WxMpPayRefundResult wxMpPayRefundResult = (WxMpPayRefundResult) xstream
- .fromXML(responseContent);
- if (!"SUCCESS".equalsIgnoreCase(wxMpPayRefundResult.getResultCode())
- || !"SUCCESS".equalsIgnoreCase(wxMpPayRefundResult.getReturnCode())) {
- WxError error = new WxError();
- error.setErrorCode(-1);
- error.setErrorMsg("return_code:" + wxMpPayRefundResult.getReturnCode()
- + ";return_msg:" + wxMpPayRefundResult.getReturnMsg()
- + ";result_code:" + wxMpPayRefundResult.getResultCode() + ";err_code"
- + wxMpPayRefundResult.getErrCode() + ";err_code_des"
- + wxMpPayRefundResult.getErrCodeDes());
- throw new WxErrorException(error);
+ if (StringUtils.isBlank(request.getOutTradeNo()) && StringUtils.isBlank(request.getTransactionId())) {
+ throw new IllegalArgumentException("transaction_id 和 out_trade_no 不能同时为空,必须提供一个");
}
+ }
- return wxMpPayRefundResult;
+ @Override
+ public WxPayJsSDKCallback getJSSDKCallbackData(String xmlData) throws WxErrorException {
+ try {
+ XStream xstream = XStreamInitializer.getInstance();
+ xstream.alias("xml", WxPayJsSDKCallback.class);
+ return (WxPayJsSDKCallback) xstream.fromXML(xmlData);
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new WxErrorException(WxError.newBuilder().setErrorMsg("发生异常" + e.getMessage()).build());
+ }
}
@Override
@@ -152,59 +124,31 @@ public class WxMpPayServiceImpl implements WxMpPayService {
}
@Override
- public WxRedpackResult sendRedpack(WxSendRedpackRequest request)
+ public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request, File keyFile)
throws WxErrorException {
XStream xstream = XStreamInitializer.getInstance();
- xstream.processAnnotations(WxSendRedpackRequest.class);
- xstream.processAnnotations(WxRedpackResult.class);
+ xstream.processAnnotations(WxPaySendRedpackRequest.class);
+ xstream.processAnnotations(WxPaySendRedpackResult.class);
request.setWxAppid(this.wxMpService.getWxMpConfigStorage().getAppId());
- request.setMchId(this.wxMpService.getWxMpConfigStorage().getPartnerId());
+ String mchId = this.wxMpService.getWxMpConfigStorage().getPartnerId();
+ request.setMchId(mchId);
request.setNonceStr(System.currentTimeMillis() + "");
- String sign = this.createSign(xmlBean2Map(request),
+ String sign = this.createSign(BeanUtils.xmlBean2Map(request),
this.wxMpService.getWxMpConfigStorage().getPartnerKey());
request.setSign(sign);
- String url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack";
+ String url = PAY_BASE_URL + "/mmpaymkttransfers/sendredpack";
if (request.getAmtType() != null) {
//裂变红包
- url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendgroupredpack";
+ url = PAY_BASE_URL + "/mmpaymkttransfers/sendgroupredpack";
}
- String responseContent = this.wxMpService.post(url, xstream.toXML(request));
- WxRedpackResult redpackResult = (WxRedpackResult) xstream
+ String responseContent = this.executeRequestWithKeyFile(url, keyFile, xstream.toXML(request), mchId);
+ WxPaySendRedpackResult result = (WxPaySendRedpackResult) xstream
.fromXML(responseContent);
- if ("FAIL".equals(redpackResult.getResultCode())) {
- throw new WxErrorException(WxError.newBuilder()
- .setErrorMsg(
- redpackResult.getErrCode() + ":" + redpackResult.getErrCodeDes())
- .build());
- }
-
- return redpackResult;
- }
-
- private Map xmlBean2Map(Object bean) {
- Map result = Maps.newHashMap();
- for (Entry entry : Reflect.on(bean).fields().entrySet()) {
- Reflect reflect = entry.getValue();
- if (reflect.get() == null) {
- continue;
- }
-
- try {
- Field field = bean.getClass().getDeclaredField(entry.getKey());
- if (field.isAnnotationPresent(XStreamAlias.class)) {
- result.put(field.getAnnotation(XStreamAlias.class).value(),
- reflect.get().toString());
- }
- } catch (NoSuchFieldException | SecurityException e) {
- e.printStackTrace();
- }
-
- }
-
+ this.checkResult(result);
return result;
}
@@ -232,87 +176,110 @@ public class WxMpPayServiceImpl implements WxMpPayService {
}
@Override
- public WxUnifiedOrderResult unifiedOrder(WxUnifiedOrderRequest request)
- throws WxErrorException {
- checkParameters(request);
+ public WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) throws WxErrorException {
+ if ((StringUtils.isBlank(transactionId) && StringUtils.isBlank(outTradeNo)) ||
+ (StringUtils.isNotBlank(transactionId) && StringUtils.isNotBlank(outTradeNo))) {
+ throw new IllegalArgumentException("transaction_id 和 out_trade_no 不能同时存在或同时为空,必须二选一");
+ }
XStream xstream = XStreamInitializer.getInstance();
- xstream.processAnnotations(WxUnifiedOrderRequest.class);
- xstream.processAnnotations(WxUnifiedOrderResult.class);
+ xstream.processAnnotations(WxPayOrderQueryRequest.class);
+ xstream.processAnnotations(WxPayOrderQueryResult.class);
+ WxPayOrderQueryRequest request = new WxPayOrderQueryRequest();
+ request.setOutTradeNo(StringUtils.trimToNull(outTradeNo));
+ request.setTransactionId(StringUtils.trimToNull(transactionId));
request.setAppid(this.wxMpService.getWxMpConfigStorage().getAppId());
request.setMchId(this.wxMpService.getWxMpConfigStorage().getPartnerId());
request.setNonceStr(System.currentTimeMillis() + "");
- String sign = this.createSign(xmlBean2Map(request),
- this.wxMpService.getWxMpConfigStorage().getPartnerKey());
+ String sign = this.createSign(BeanUtils.xmlBean2Map(request),
+ this.wxMpService.getWxMpConfigStorage().getPartnerKey());
request.setSign(sign);
- String url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
+ String url = PAY_BASE_URL + "/pay/orderquery";
- String responseContent = this.wxMpService.post(url, xstream.toXML(request));
- WxUnifiedOrderResult result = (WxUnifiedOrderResult) xstream
- .fromXML(responseContent);
- if ("FAIL".equals(result.getResultCode())) {
- throw new WxErrorException(WxError.newBuilder()
- .setErrorMsg(result.getErrCode() + ":" + result.getErrCodeDes())
- .build());
+ String responseContent = this.executeRequest(url, xstream.toXML(request));
+ WxPayOrderQueryResult result = (WxPayOrderQueryResult) xstream.fromXML(responseContent);
+ result.composeCoupons(responseContent);
+ this.checkResult(result);
+ return result;
+ }
+
+ @Override
+ public WxPayOrderCloseResult closeOrder(String outTradeNo) throws WxErrorException {
+ if (StringUtils.isBlank(outTradeNo)) {
+ throw new IllegalArgumentException("out_trade_no 不能为空");
}
- return result;
+ XStream xstream = XStreamInitializer.getInstance();
+ xstream.processAnnotations(WxPayOrderCloseRequest.class);
+ xstream.processAnnotations(WxPayOrderCloseResult.class);
+
+ WxPayOrderCloseRequest request = new WxPayOrderCloseRequest();
+ request.setOutTradeNo(StringUtils.trimToNull(outTradeNo));
+ request.setAppid(this.wxMpService.getWxMpConfigStorage().getAppId());
+ request.setMchId(this.wxMpService.getWxMpConfigStorage().getPartnerId());
+ request.setNonceStr(System.currentTimeMillis() + "");
+ String sign = this.createSign(BeanUtils.xmlBean2Map(request),
+ this.wxMpService.getWxMpConfigStorage().getPartnerKey());
+ request.setSign(sign);
+
+ String url = PAY_BASE_URL + "/pay/closeorder";
+
+ String responseContent = this.executeRequest(url, xstream.toXML(request));
+ WxPayOrderCloseResult result = (WxPayOrderCloseResult) xstream.fromXML(responseContent);
+ this.checkResult(result);
+
+ return result;
}
- private void checkParameters(WxUnifiedOrderRequest request) {
-
- List nullFields = Lists.newArrayList();
- for (Entry entry : Reflect.on(request).fields()
- .entrySet()) {
- Reflect reflect = entry.getValue();
- try {
- Field field = request.getClass().getDeclaredField(entry.getKey());
- if (field.isAnnotationPresent(Required.class)
- && reflect.get() == null) {
- nullFields.add(entry.getKey());
- }
- } catch (NoSuchFieldException | SecurityException e) {
- e.printStackTrace();
- }
- }
+ @Override
+ public WxPayUnifiedOrderResult unifiedOrder(WxPayUnifiedOrderRequest request)
+ throws WxErrorException {
+ checkParameters(request);
- if (!nullFields.isEmpty()) {
- throw new IllegalArgumentException("必填字段[" + nullFields + "]必须提供值");
- }
+ XStream xstream = XStreamInitializer.getInstance();
+ xstream.processAnnotations(WxPayUnifiedOrderRequest.class);
+ xstream.processAnnotations(WxPayUnifiedOrderResult.class);
+
+ request.setAppid(this.wxMpService.getWxMpConfigStorage().getAppId());
+ request.setMchId(this.wxMpService.getWxMpConfigStorage().getPartnerId());
+ request.setNonceStr(System.currentTimeMillis() + "");
+
+ String sign = this.createSign(BeanUtils.xmlBean2Map(request),
+ this.wxMpService.getWxMpConfigStorage().getPartnerKey());
+ request.setSign(sign);
- if (!TRADE_TYPES.contains(request.getTradeType())) {
- throw new IllegalArgumentException(
- "trade_type目前必须为" + TRADE_TYPES + "其中之一");
+ String url = PAY_BASE_URL + "/pay/unifiedorder";
+ String responseContent = this.executeRequest(url, xstream.toXML(request));
+ WxPayUnifiedOrderResult result = (WxPayUnifiedOrderResult) xstream
+ .fromXML(responseContent);
+ this.checkResult(result);
+ return result;
+ }
+
+ private void checkParameters(WxPayUnifiedOrderRequest request) throws WxErrorException {
+ BeanUtils.checkRequiredFields(request);
+
+ if (! ArrayUtils.contains(TRADE_TYPES, request.getTradeType())) {
+ throw new IllegalArgumentException("trade_type目前必须为" + Arrays.toString(TRADE_TYPES) + "其中之一");
}
if ("JSAPI".equals(request.getTradeType()) && request.getOpenid() == null) {
throw new IllegalArgumentException("当 trade_type是'JSAPI'时未指定openid");
}
- if ("NATIVE".equals(request.getTradeType())
- && request.getProductId() == null) {
+ if ("NATIVE".equals(request.getTradeType()) && request.getProductId() == null) {
throw new IllegalArgumentException("当 trade_type是'NATIVE'时未指定product_id");
}
}
@Override
- public Map getPayInfo(WxUnifiedOrderRequest request) throws WxErrorException {
- WxUnifiedOrderResult unifiedOrderResult = this.unifiedOrder(request);
-
- if (!"SUCCESS".equalsIgnoreCase(unifiedOrderResult.getReturnCode())
- || !"SUCCESS".equalsIgnoreCase(unifiedOrderResult.getResultCode())) {
- throw new WxErrorException(WxError.newBuilder().setErrorCode(-1)
- .setErrorMsg("return_code:" + unifiedOrderResult.getReturnCode() + ";return_msg:"
- + unifiedOrderResult.getReturnMsg() + ";result_code:" + unifiedOrderResult.getResultCode() + ";err_code"
- + unifiedOrderResult.getErrCode() + ";err_code_des" + unifiedOrderResult.getErrCodeDes())
- .build());
- }
-
+ public Map getPayInfo(WxPayUnifiedOrderRequest request) throws WxErrorException {
+ WxPayUnifiedOrderResult unifiedOrderResult = this.unifiedOrder(request);
String prepayId = unifiedOrderResult.getPrepayId();
if (StringUtils.isBlank(prepayId)) {
throw new RuntimeException(String.format("Failed to get prepay id due to error code '%s'(%s).",
@@ -335,4 +302,101 @@ public class WxMpPayServiceImpl implements WxMpPayService {
return payInfo;
}
+ @Override
+ public WxEntPayResult entPay(WxEntPayRequest request, File keyFile) throws WxErrorException {
+ BeanUtils.checkRequiredFields(request);
+
+ XStream xstream = XStreamInitializer.getInstance();
+ xstream.processAnnotations(WxEntPayRequest.class);
+ xstream.processAnnotations(WxEntPayResult.class);
+
+ request.setMchAppid(this.wxMpService.getWxMpConfigStorage().getAppId());
+ request.setMchId(this.wxMpService.getWxMpConfigStorage().getPartnerId());
+ request.setNonceStr(System.currentTimeMillis() + "");
+
+ String sign = this.createSign(BeanUtils.xmlBean2Map(request), this.wxMpService.getWxMpConfigStorage().getPartnerKey());
+ request.setSign(sign);
+
+ String url = PAY_BASE_URL + "/mmpaymkttransfers/promotion/transfers";
+
+ String responseContent = this.executeRequestWithKeyFile(url, keyFile, xstream.toXML(request), request.getMchId());
+ WxEntPayResult result = (WxEntPayResult) xstream.fromXML(responseContent);
+ this.checkResult(result);
+ return result;
+ }
+
+ @Override
+ public WxEntPayQueryResult queryEntPay(String partnerTradeNo, File keyFile) throws WxErrorException {
+ XStream xstream = XStreamInitializer.getInstance();
+ xstream.processAnnotations(WxEntPayQueryRequest.class);
+ xstream.processAnnotations(WxEntPayQueryResult.class);
+
+ WxEntPayQueryRequest request = new WxEntPayQueryRequest();
+ request.setAppid(this.wxMpService.getWxMpConfigStorage().getAppId());
+ request.setMchId(this.wxMpService.getWxMpConfigStorage().getPartnerId());
+ request.setNonceStr(System.currentTimeMillis() + "");
+
+ String sign = this.createSign(BeanUtils.xmlBean2Map(request), this.wxMpService.getWxMpConfigStorage().getPartnerKey());
+ request.setSign(sign);
+
+ String url = PAY_BASE_URL + "/mmpaymkttransfers/gettransferinfo";
+
+ String responseContent = this.executeRequestWithKeyFile(url, keyFile, xstream.toXML(request), request.getMchId());
+ WxEntPayQueryResult result = (WxEntPayQueryResult) xstream.fromXML(responseContent);
+ this.checkResult(result);
+ return result;
+ }
+
+ private String executeRequest( String url, String requestStr) throws WxErrorException {
+ HttpPost httpPost = new HttpPost(url);
+ if (this.wxMpService.getHttpProxy() != null) {
+ httpPost.setConfig(RequestConfig.custom().setProxy(this.wxMpService.getHttpProxy()).build());
+ }
+
+ try (CloseableHttpClient httpclient = HttpClients.custom().build()) {
+ httpPost.setEntity(new StringEntity(new String(requestStr.getBytes("UTF-8"), "ISO-8859-1")));
+
+ try (CloseableHttpResponse response = httpclient.execute(httpPost)) {
+ String result = EntityUtils.toString(response.getEntity(), Consts.UTF_8);
+ this.log.debug("\n[URL]: {}\n[PARAMS]: {}\n[RESPONSE]: {}",url, requestStr, result);
+ return result;
+ }
+ } catch (IOException e) {
+ this.log.error("\n[URL]: {}\n[PARAMS]: {}\n[EXCEPTION]: {}", url, requestStr, e.getMessage());
+ throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg(e.getMessage()).build(), e);
+ }finally {
+ httpPost.releaseConnection();
+ }
+ }
+
+ private String executeRequestWithKeyFile( String url, File keyFile, String requestStr, String mchId) throws WxErrorException {
+ try (FileInputStream inputStream = new FileInputStream(keyFile)) {
+ KeyStore keyStore = KeyStore.getInstance("PKCS12");
+ keyStore.load(inputStream, mchId.toCharArray());
+
+ SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, mchId.toCharArray()).build();
+ SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1" }, null,
+ new DefaultHostnameVerifier());
+
+ HttpPost httpPost = new HttpPost(url);
+ if (this.wxMpService.getHttpProxy() != null) {
+ httpPost.setConfig(RequestConfig.custom().setProxy(this.wxMpService.getHttpProxy()).build());
+ }
+
+ try (CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build()) {
+ httpPost.setEntity(new StringEntity(new String(requestStr.getBytes("UTF-8"), "ISO-8859-1")));
+ try (CloseableHttpResponse response = httpclient.execute(httpPost)) {
+ String result = EntityUtils.toString(response.getEntity(), Consts.UTF_8);
+ this.log.debug("\n[URL]: {}\n[PARAMS]: {}\n[RESPONSE]: {}",url, requestStr, result);
+ return result;
+ }
+ }finally {
+ httpPost.releaseConnection();
+ }
+ } catch (Exception e) {
+ this.log.error("\n[URL]: {}\n[PARAMS]: {}\n[EXCEPTION]: {}", url, requestStr, e.getMessage());
+ throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg(e.getMessage()).build(), e);
+ }
+ }
+
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java
index 1a7ffe84..87cf7397 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java
@@ -1,23 +1,9 @@
package me.chanjar.weixin.mp.api.impl;
-import java.io.IOException;
-
-import org.apache.http.HttpHost;
-import org.apache.http.client.config.RequestConfig;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.conn.ssl.DefaultHostnameVerifier;
-import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
-import org.apache.http.impl.client.BasicResponseHandler;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
-
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.bean.result.WxError;
@@ -26,44 +12,28 @@ import me.chanjar.weixin.common.session.StandardSessionManager;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.common.util.RandomUtils;
import me.chanjar.weixin.common.util.crypto.SHA1;
-import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder;
-import me.chanjar.weixin.common.util.http.DefaultApacheHttpClientBuilder;
-import me.chanjar.weixin.common.util.http.RequestExecutor;
-import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
-import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
-import me.chanjar.weixin.common.util.http.URIUtil;
-import me.chanjar.weixin.mp.api.WxMpCardService;
-import me.chanjar.weixin.mp.api.WxMpConfigStorage;
-import me.chanjar.weixin.mp.api.WxMpDataCubeService;
-import me.chanjar.weixin.mp.api.WxMpKefuService;
-import me.chanjar.weixin.mp.api.WxMpMaterialService;
-import me.chanjar.weixin.mp.api.WxMpMenuService;
-import me.chanjar.weixin.mp.api.WxMpPayService;
-import me.chanjar.weixin.mp.api.WxMpQrcodeService;
-import me.chanjar.weixin.mp.api.WxMpService;
-import me.chanjar.weixin.mp.api.WxMpStoreService;
-import me.chanjar.weixin.mp.api.WxMpUserBlacklistService;
-import me.chanjar.weixin.mp.api.WxMpUserService;
-import me.chanjar.weixin.mp.api.WxMpUserTagService;
-import me.chanjar.weixin.mp.bean.WxMpIndustry;
-import me.chanjar.weixin.mp.bean.WxMpMassNews;
-import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage;
-import me.chanjar.weixin.mp.bean.WxMpMassPreviewMessage;
-import me.chanjar.weixin.mp.bean.WxMpMassTagMessage;
-import me.chanjar.weixin.mp.bean.WxMpMassVideo;
-import me.chanjar.weixin.mp.bean.WxMpSemanticQuery;
-import me.chanjar.weixin.mp.bean.WxMpTemplateMessage;
-import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult;
-import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult;
-import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
-import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult;
-import me.chanjar.weixin.mp.bean.result.WxMpUser;
+import me.chanjar.weixin.common.util.http.*;
+import me.chanjar.weixin.mp.api.*;
+import me.chanjar.weixin.mp.bean.*;
+import me.chanjar.weixin.mp.bean.result.*;
+import org.apache.http.HttpHost;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.conn.ssl.DefaultHostnameVerifier;
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
+import org.apache.http.impl.client.BasicResponseHandler;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
public class WxMpServiceImpl implements WxMpService {
private static final JsonParser JSON_PARSER = new JsonParser();
- protected final Logger log = LoggerFactory.getLogger(WxMpServiceImpl.class);
+ protected final Logger log = LoggerFactory.getLogger(this.getClass());
/**
* 全局的是否正在刷新access token的锁
@@ -99,6 +69,8 @@ public class WxMpServiceImpl implements WxMpService {
private WxMpUserBlacklistService blackListService = new WxMpUserBlacklistServiceImpl(this);
+ private WxMpTemplateMsgService templateMsgService = new WxMpTemplateMsgServiceImpl(this);
+
private CloseableHttpClient httpClient;
private HttpHost httpProxy;
@@ -251,35 +223,6 @@ public class WxMpServiceImpl implements WxMpService {
return tmpJsonElement.getAsJsonObject().get("short_url").getAsString();
}
- @Override
- public String templateSend(WxMpTemplateMessage templateMessage) throws WxErrorException {
- String url = "https://api.weixin.qq.com/cgi-bin/message/template/send";
- String responseContent = this.post(url, templateMessage.toJson());
- final JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
- if (jsonObject.get("errcode").getAsInt() == 0){
- return jsonObject.get("msgid").getAsString();
- }
-
- throw new WxErrorException(WxError.fromJson(responseContent));
- }
-
- @Override
- public String setIndustry(WxMpIndustry wxMpIndustry) throws WxErrorException {
- if (null == wxMpIndustry.getPrimaryIndustry() || null == wxMpIndustry.getPrimaryIndustry().getId()
- || null == wxMpIndustry.getSecondIndustry() || null == wxMpIndustry.getSecondIndustry().getId()) {
- throw new IllegalArgumentException("industry id is empty");
- }
- String url = "https://api.weixin.qq.com/cgi-bin/template/api_set_industry";
- return this.post(url, wxMpIndustry.toJson());
- }
-
- @Override
- public WxMpIndustry getIndustry() throws WxErrorException {
- String url = "https://api.weixin.qq.com/cgi-bin/template/get_industry";
- String responseContent = this.get(url, null);
- return WxMpIndustry.fromJson(responseContent);
- }
-
@Override
public WxMpSemanticQueryResult semanticQuery(WxMpSemanticQuery semanticQuery) throws WxErrorException {
String url = "https://api.weixin.qq.com/semantic/semproxy/search";
@@ -477,10 +420,12 @@ public class WxMpServiceImpl implements WxMpService {
}
return null;
} catch (IOException e) {
+ this.log.error("\n[URL]: {}\n[PARAMS]: {}\n[EXCEPTION]: {}", uri, data, e.getMessage());
throw new RuntimeException(e);
}
}
+ @Override
public HttpHost getHttpProxy() {
return this.httpProxy;
}
@@ -591,4 +536,9 @@ public class WxMpServiceImpl implements WxMpService {
return this.storeService;
}
+ @Override
+ public WxMpTemplateMsgService getTemplateMsgService() {
+ return this.templateMsgService;
+ }
+
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImpl.java
index 39c7f729..e1984204 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImpl.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImpl.java
@@ -1,23 +1,19 @@
package me.chanjar.weixin.mp.api.impl;
-import com.google.common.collect.Lists;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
-import me.chanjar.weixin.common.annotation.Required;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
+import me.chanjar.weixin.common.util.BeanUtils;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.WxMpStoreService;
import me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo;
import me.chanjar.weixin.mp.bean.store.WxMpStoreInfo;
import me.chanjar.weixin.mp.bean.store.WxMpStoreListResult;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
-import org.joor.Reflect;
-import java.lang.reflect.Field;
import java.util.List;
-import java.util.Map.Entry;
/**
* Created by Binary Wang on 2016/9/26.
@@ -35,7 +31,7 @@ public class WxMpStoreServiceImpl implements WxMpStoreService {
@Override
public void add(WxMpStoreBaseInfo request) throws WxErrorException {
- checkParameters(request);
+ BeanUtils.checkRequiredFields(request);
String url = API_BASE_URL + "/addpoi";
String response = this.wxMpService.post(url, request.toJson());
@@ -71,28 +67,6 @@ public class WxMpStoreServiceImpl implements WxMpStoreService {
}
}
- private void checkParameters(WxMpStoreBaseInfo request) {
- List nullFields = Lists.newArrayList();
- for (Entry entry : Reflect.on(request).fields()
- .entrySet()) {
- Reflect reflect = entry.getValue();
- try {
- Field field = request.getClass().getDeclaredField(entry.getKey());
- if (field.isAnnotationPresent(Required.class)
- && reflect.get() == null) {
- nullFields.add(entry.getKey());
- }
- } catch (NoSuchFieldException | SecurityException e) {
- e.printStackTrace();
- }
- }
-
- if (!nullFields.isEmpty()) {
- throw new IllegalArgumentException("必填字段[" + nullFields + "]必须提供值");
- }
-
- }
-
@Override
public WxMpStoreListResult list(int begin, int limit)
throws WxErrorException {
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImpl.java
new file mode 100644
index 00000000..82ce829c
--- /dev/null
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImpl.java
@@ -0,0 +1,95 @@
+package me.chanjar.weixin.mp.api.impl;
+
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import me.chanjar.weixin.common.bean.result.WxError;
+import me.chanjar.weixin.common.exception.WxErrorException;
+import me.chanjar.weixin.mp.api.WxMpService;
+import me.chanjar.weixin.mp.api.WxMpTemplateMsgService;
+import me.chanjar.weixin.mp.bean.template.WxMpTemplate;
+import me.chanjar.weixin.mp.bean.template.WxMpTemplateIndustry;
+import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
+
+import java.util.List;
+
+/**
+ *
+ * Created by Binary Wang on 2016-10-14.
+ * @author binarywang(Binary Wang)
+ *
+ */
+public class WxMpTemplateMsgServiceImpl implements WxMpTemplateMsgService {
+ public static final String API_URL_PREFIX = "https://api.weixin.qq.com/cgi-bin/template";
+ private static final JsonParser JSON_PARSER = new JsonParser();
+
+ private WxMpService wxMpService;
+
+ public WxMpTemplateMsgServiceImpl(WxMpService wxMpService) {
+ this.wxMpService = wxMpService;
+ }
+
+ @Override
+ public String sendTemplateMsg(WxMpTemplateMessage templateMessage) throws WxErrorException {
+ String url = "https://api.weixin.qq.com/cgi-bin/message/template/send";
+ String responseContent = this.wxMpService.post(url, templateMessage.toJson());
+ final JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
+ if (jsonObject.get("errcode").getAsInt() == 0) {
+ return jsonObject.get("msgid").getAsString();
+ }
+ throw new WxErrorException(WxError.fromJson(responseContent));
+ }
+
+ @Override
+ public boolean setIndustry(WxMpTemplateIndustry wxMpIndustry) throws WxErrorException {
+ if (null == wxMpIndustry.getPrimaryIndustry() || null == wxMpIndustry.getPrimaryIndustry().getId()
+ || null == wxMpIndustry.getSecondIndustry() || null == wxMpIndustry.getSecondIndustry().getId()) {
+ throw new IllegalArgumentException("行业Id不能为空,请核实");
+ }
+
+ String url = API_URL_PREFIX + "/api_set_industry";
+ this.wxMpService.post(url, wxMpIndustry.toJson());
+ return true;
+ }
+
+ @Override
+ public WxMpTemplateIndustry getIndustry() throws WxErrorException {
+ String url = API_URL_PREFIX + "/get_industry";
+ String responseContent = this.wxMpService.get(url, null);
+ return WxMpTemplateIndustry.fromJson(responseContent);
+ }
+
+ @Override
+ public String addTemplate(String shortTemplateId) throws WxErrorException {
+ String url = API_URL_PREFIX + "/api_add_template";
+ JsonObject jsonObject = new JsonObject();
+ jsonObject.addProperty("template_id_short", shortTemplateId);
+ String responseContent = this.wxMpService.post(url, jsonObject.toString());
+ final JsonObject result = JSON_PARSER.parse(responseContent).getAsJsonObject();
+ if (result.get("errcode").getAsInt() == 0) {
+ return result.get("template_id").getAsString();
+ }
+
+ throw new WxErrorException(WxError.fromJson(responseContent));
+ }
+
+ @Override
+ public List getAllPrivateTemplate() throws WxErrorException {
+ String url = API_URL_PREFIX + "/get_all_private_template";
+ return WxMpTemplate.fromJson(this.wxMpService.get(url, null));
+ }
+
+ @Override
+ public boolean delPrivateTemplate(String templateId) throws WxErrorException {
+ String url = API_URL_PREFIX + "/del_private_template";
+ JsonObject jsonObject = new JsonObject();
+ jsonObject.addProperty("template_id", templateId);
+ String responseContent = this.wxMpService.post(url, jsonObject.toString());
+ WxError error = WxError.fromJson(responseContent);
+ if (error.getErrorCode() == 0) {
+ return true;
+ }
+
+ throw new WxErrorException(error);
+ }
+
+}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImpl.java
index 9267407c..c796cbd3 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImpl.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImpl.java
@@ -1,9 +1,6 @@
package me.chanjar.weixin.mp.api.impl;
-import java.util.List;
-
import com.google.gson.JsonObject;
-
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.WxMpUserService;
@@ -11,6 +8,8 @@ import me.chanjar.weixin.mp.bean.WxMpUserQuery;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import me.chanjar.weixin.mp.bean.result.WxMpUserList;
+import java.util.List;
+
/**
* Created by Binary Wang on 2016/7/21.
*/
@@ -31,6 +30,11 @@ public class WxMpUserServiceImpl implements WxMpUserService {
this.wxMpService.post(url, json.toString());
}
+ @Override
+ public WxMpUser userInfo(String openid) throws WxErrorException {
+ return this.userInfo(openid, null);
+ }
+
@Override
public WxMpUser userInfo(String openid, String lang) throws WxErrorException {
String url = API_URL_PREFIX + "/info";
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java
index 4d3639c8..d1bdae1e 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java
@@ -1,9 +1,14 @@
package me.chanjar.weixin.mp.api.impl;
+import java.util.List;
+
+import org.apache.commons.lang3.StringUtils;
+
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
+
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
@@ -11,13 +16,10 @@ import me.chanjar.weixin.mp.api.WxMpUserTagService;
import me.chanjar.weixin.mp.bean.tag.WxTagListUser;
import me.chanjar.weixin.mp.bean.tag.WxUserTag;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
-import org.apache.commons.lang3.StringUtils;
-
-import java.util.List;
/**
*
- * @author binarywang(https://github.com/binarywang)
+ * @author binarywang(Binary Wang)
* Created by Binary Wang on 2016/9/2.
*/
public class WxMpUserTagServiceImpl implements WxMpUserTagService {
@@ -102,7 +104,7 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService {
@Override
public boolean batchTagging(Long tagId, String[] openids)
throws WxErrorException {
- String url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging";
+ String url = API_URL_PREFIX + "/members/batchtagging";
JsonObject json = new JsonObject();
json.addProperty("tagid", tagId);
@@ -124,7 +126,7 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService {
@Override
public boolean batchUntagging(Long tagId, String[] openids)
throws WxErrorException {
- String url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchuntagging";
+ String url = API_URL_PREFIX + "/members/batchuntagging";
JsonObject json = new JsonObject();
json.addProperty("tagid", tagId);
@@ -144,8 +146,8 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService {
}
@Override
- public List userTagList(String openid) throws WxErrorException {
- String url = "https://api.weixin.qq.com/cgi-bin/tags/getidlist";
+ public List userTagList(String openid) throws WxErrorException {
+ String url = API_URL_PREFIX + "/getidlist";
JsonObject json = new JsonObject();
json.addProperty("openid", openid);
@@ -154,7 +156,7 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService {
return WxMpGsonBuilder.create().fromJson(
new JsonParser().parse(responseContent).getAsJsonObject().get("tagid_list"),
- new TypeToken>() {
+ new TypeToken>() {
}.getType());
}
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/Industry.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/Industry.java
deleted file mode 100644
index da5b5134..00000000
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/Industry.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package me.chanjar.weixin.mp.bean;
-
-import java.io.Serializable;
-
-/**
- * @author miller
- * 官方文档中,创建和获取的数据结构不一样。所以采用冗余字段的方式,实现相应的接口
- */
-public class Industry implements Serializable {
- private static final long serialVersionUID = -1707184885588012142L;
- private String id;
- private String firstClass;
- private String secondClass;
-
- public String getId() {
- return this.id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public String getFirstClass() {
- return this.firstClass;
- }
-
- public void setFirstClass(String firstClass) {
- this.firstClass = firstClass;
- }
-
- public String getSecondClass() {
- return this.secondClass;
- }
-
- public void setSecondClass(String secondClass) {
- this.secondClass = secondClass;
- }
-}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpCard.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpCard.java
index 7bb4330f..bc50ce05 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpCard.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpCard.java
@@ -1,6 +1,8 @@
package me.chanjar.weixin.mp.bean;
+import me.chanjar.weixin.common.util.ToStringUtils;
+
/**
* 微信卡券
*
@@ -61,12 +63,6 @@ public class WxMpCard {
@Override
public String toString() {
- return "WxMpCard{" +
- "cardId='" + this.cardId + '\'' +
- ", beginTime=" + this.beginTime +
- ", endTime=" + this.endTime +
- ", userCardStatus='" + this.userCardStatus + '\'' +
- ", canConsume=" + this.canConsume +
- '}';
+ return ToStringUtils.toSimpleString(this);
}
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpIndustry.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpIndustry.java
deleted file mode 100644
index 281b9315..00000000
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpIndustry.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package me.chanjar.weixin.mp.bean;
-
-
-import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
-
-import java.io.Serializable;
-
-/**
- * @author miller
- */
-public class WxMpIndustry implements Serializable {
- private static final long serialVersionUID = -7700398224795914722L;
- private Industry primaryIndustry;
- private Industry secondIndustry;
-
- public static WxMpIndustry fromJson(String json) {
- return WxMpGsonBuilder.create().fromJson(json, WxMpIndustry.class);
- }
-
- public String toJson() {
- return WxMpGsonBuilder.create().toJson(this);
- }
-
- public Industry getPrimaryIndustry() {
- return this.primaryIndustry;
- }
-
- public void setPrimaryIndustry(Industry primaryIndustry) {
- this.primaryIndustry = primaryIndustry;
- }
-
- public Industry getSecondIndustry() {
- return this.secondIndustry;
- }
-
- public void setSecondIndustry(Industry secondIndustry) {
- this.secondIndustry = secondIndustry;
- }
-}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassNews.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassNews.java
index 4b059ea8..3e65fcde 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassNews.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassNews.java
@@ -1,5 +1,6 @@
package me.chanjar.weixin.mp.bean;
+import me.chanjar.weixin.common.util.ToStringUtils;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
import java.io.Serializable;
@@ -14,7 +15,7 @@ import java.util.List;
public class WxMpMassNews implements Serializable {
/**
- *
+ *
*/
private static final long serialVersionUID = 565937155013581016L;
private List articles = new ArrayList<>();
@@ -137,14 +138,12 @@ public class WxMpMassNews implements Serializable {
@Override
public String toString() {
- return "WxMpMassNewsArticle [" + "thumbMediaId=" + this.thumbMediaId + ", author=" + this.author + ", title=" + this.title +
- ", contentSourceUrl=" + this.contentSourceUrl + ", content=" + this.content + ", digest=" + this.digest +
- ", showCoverPic=" + this.showCoverPic + "]";
+ return ToStringUtils.toSimpleString(this);
}
}
@Override
public String toString() {
- return "WxMpMassNews [" + "articles=" + this.articles + "]";
+ return ToStringUtils.toSimpleString(this);
}
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassPreviewMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassPreviewMessage.java
index 78e699e9..b49ffc38 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassPreviewMessage.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassPreviewMessage.java
@@ -8,9 +8,6 @@ import java.io.Serializable;
* @author miller
*/
public class WxMpMassPreviewMessage implements Serializable {
- /**
- *
- */
private static final long serialVersionUID = 9095211638358424020L;
private String toWxUsername;
private String msgType;
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleResult.java
index 3dd28459..35cae74d 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleResult.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleResult.java
@@ -1,16 +1,15 @@
package me.chanjar.weixin.mp.bean.datacube;
-import java.util.List;
-
import com.google.gson.JsonParser;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
-
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
+import java.util.List;
+
/**
* 图文分析数据接口返回结果对象
- * @author binarywang(https://github.com/binarywang)
+ * @author binarywang(Binary Wang)
* Created by Binary Wang on 2016/8/24.
*/
public class WxDataCubeArticleResult extends WxDataCubeBaseResult {
@@ -26,7 +25,9 @@ public class WxDataCubeArticleResult extends WxDataCubeBaseResult {
/**
* msgid
- * 请注意:这里的msgid实际上是由msgid(图文消息id,这也就是群发接口调用后返回的msg_data_id)和index(消息次序索引)组成, 例如12003_3, 其中12003是msgid,即一次群发的消息的id; 3为index,假设该次群发的图文消息共5个文章(因为可能为多图文),3表示5个中的第3个
+ * 请注意:这里的msgid实际上是由msgid(图文消息id,这也就是群发接口调用后返回的msg_data_id)
+ * 和index(消息次序索引)组成, 例如12003_3, 其中12003是msgid,即一次群发的消息的id; 3为index,
+ * 假设该次群发的图文消息共5个文章(因为可能为多图文),3表示5个中的第3个
*/
@SerializedName("msgid")
private String msgId;
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleTotal.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleTotal.java
index 37401cf8..d3236be3 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleTotal.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleTotal.java
@@ -10,7 +10,7 @@ import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
/**
* 图文分析数据接口返回结果对象
- * @author binarywang(https://github.com/binarywang)
+ * @author binarywang(Binary Wang)
* Created by Binary Wang on 2016/8/24.
*/
public class WxDataCubeArticleTotal extends WxDataCubeBaseResult {
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleTotalDetail.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleTotalDetail.java
index cbbf148f..e228a3cc 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleTotalDetail.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeArticleTotalDetail.java
@@ -4,7 +4,7 @@ import com.google.gson.annotations.SerializedName;
/**
* 获取图文群发总数据接口(getarticletotal)中的详细字段
- * @author binarywang(https://github.com/binarywang)
+ * @author binarywang(Binary Wang)
* Created by Binary Wang on 2016/8/24.
*/
public class WxDataCubeArticleTotalDetail {
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeBaseResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeBaseResult.java
index f819ab42..a9415d9f 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeBaseResult.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeBaseResult.java
@@ -1,18 +1,17 @@
package me.chanjar.weixin.mp.bean.datacube;
import com.google.gson.annotations.SerializedName;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
+import me.chanjar.weixin.common.util.ToStringUtils;
/**
* 统计接口的共用属性类
- * @author binarywang(https://github.com/binarywang)
+ * @author binarywang(Binary Wang)
* Created by Binary Wang on 2016/8/25.
*/
public class WxDataCubeBaseResult {
@Override
public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
+ return ToStringUtils.toSimpleString(this);
}
/**
@@ -29,5 +28,5 @@ public class WxDataCubeBaseResult {
public void setRefDate(String refDate) {
this.refDate = refDate;
}
-
+
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeInterfaceResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeInterfaceResult.java
index 82a45dcf..2088453c 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeInterfaceResult.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeInterfaceResult.java
@@ -10,7 +10,7 @@ import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
/**
* 接口分析数据接口返回结果对象
- * @author binarywang(https://github.com/binarywang)
+ * @author binarywang(Binary Wang)
* Created by Binary Wang on 2016/8/30.
*/
public class WxDataCubeInterfaceResult extends WxDataCubeBaseResult {
@@ -98,5 +98,5 @@ public class WxDataCubeInterfaceResult extends WxDataCubeBaseResult {
new TypeToken>() {
}.getType());
}
-
+
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeMsgResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeMsgResult.java
index 908dfca8..01e40e80 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeMsgResult.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeMsgResult.java
@@ -10,7 +10,7 @@ import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
/**
* 消息分析数据接口返回结果对象
- * @author binarywang(https://github.com/binarywang)
+ * @author binarywang(Binary Wang)
* Created by Binary Wang on 2016/8/29.
*/
public class WxDataCubeMsgResult extends WxDataCubeBaseResult {
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeUserCumulate.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeUserCumulate.java
index 039bd189..40e35ded 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeUserCumulate.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeUserCumulate.java
@@ -1,17 +1,14 @@
package me.chanjar.weixin.mp.bean.datacube;
-import java.io.Serializable;
-import java.util.Date;
-import java.util.List;
-
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
-
+import me.chanjar.weixin.common.util.ToStringUtils;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
+import java.io.Serializable;
+import java.util.Date;
+import java.util.List;
+
/**
*
* 累计用户数据接口的返回JSON数据包
@@ -46,7 +43,7 @@ public class WxDataCubeUserCumulate implements Serializable {
@Override
public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
+ return ToStringUtils.toSimpleString(this);
}
public static List fromJson(String json) {
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeUserSummary.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeUserSummary.java
index 4802027e..8f478885 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeUserSummary.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeUserSummary.java
@@ -1,17 +1,14 @@
package me.chanjar.weixin.mp.bean.datacube;
-import java.io.Serializable;
-import java.util.Date;
-import java.util.List;
-
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
-
+import me.chanjar.weixin.common.util.ToStringUtils;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
+import java.io.Serializable;
+import java.util.Date;
+import java.util.List;
+
/**
*
* 用户增减数据接口的返回JSON数据包
@@ -65,7 +62,7 @@ public class WxDataCubeUserSummary implements Serializable {
@Override
public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
+ return ToStringUtils.toSimpleString(this);
}
public static List fromJson(String json) {
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpCustomMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/WxMpKefuMessage.java
similarity index 80%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpCustomMessage.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/WxMpKefuMessage.java
index a7f1670f..228351fd 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpCustomMessage.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/WxMpKefuMessage.java
@@ -1,24 +1,25 @@
-package me.chanjar.weixin.mp.bean;
+package me.chanjar.weixin.mp.bean.kefu;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
-import me.chanjar.weixin.mp.bean.custombuilder.ImageBuilder;
-import me.chanjar.weixin.mp.bean.custombuilder.MusicBuilder;
-import me.chanjar.weixin.mp.bean.custombuilder.NewsBuilder;
-import me.chanjar.weixin.mp.bean.custombuilder.TextBuilder;
-import me.chanjar.weixin.mp.bean.custombuilder.VideoBuilder;
-import me.chanjar.weixin.mp.bean.custombuilder.VoiceBuilder;
-import me.chanjar.weixin.mp.bean.custombuilder.WxCardBuilder;
+import me.chanjar.weixin.mp.builder.kefu.ImageBuilder;
+import me.chanjar.weixin.mp.builder.kefu.MpNewsBuilder;
+import me.chanjar.weixin.mp.builder.kefu.MusicBuilder;
+import me.chanjar.weixin.mp.builder.kefu.NewsBuilder;
+import me.chanjar.weixin.mp.builder.kefu.TextBuilder;
+import me.chanjar.weixin.mp.builder.kefu.VideoBuilder;
+import me.chanjar.weixin.mp.builder.kefu.VoiceBuilder;
+import me.chanjar.weixin.mp.builder.kefu.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 String toUser;
@@ -32,18 +33,85 @@ public class WxMpCustomMessage implements Serializable {
private String hqMusicUrl;
private String kfAccount;
private String cardId;
+ private String mpNewsMediaId;
private List articles = new ArrayList<>();
+ /**
+ * 获得文本消息builder
+ */
+ public static TextBuilder TEXT() {
+ return new TextBuilder();
+ }
+
+ /**
+ * 获得图片消息builder
+ */
+ public static ImageBuilder IMAGE() {
+ return new ImageBuilder();
+ }
+
+ /**
+ * 获得语音消息builder
+ */
+ public static VoiceBuilder VOICE() {
+ return new VoiceBuilder();
+ }
+
+ /**
+ * 获得视频消息builder
+ */
+ public static VideoBuilder VIDEO() {
+ return new VideoBuilder();
+ }
+
+ /**
+ * 获得音乐消息builder
+ */
+ public static MusicBuilder MUSIC() {
+ return new MusicBuilder();
+ }
+
+ /**
+ * 获得图文消息(点击跳转到外链)builder
+ */
+ public static NewsBuilder NEWS() {
+ return new NewsBuilder();
+ }
+
+ /**
+ * 获得图文消息(点击跳转到图文消息页面)builder
+ */
+ public static MpNewsBuilder MPNEWS() {
+ return new MpNewsBuilder();
+ }
+
+ /**
+ * 获得卡券消息builder
+ */
+ public static WxCardBuilder WXCARD() {
+ return new WxCardBuilder();
+ }
+
public String getToUser() {
return this.toUser;
}
+
public void setToUser(String toUser) {
this.toUser = toUser;
}
+
public String getMsgType() {
return this.msgType;
}
+ public String getMpNewsMediaId() {
+ return this.mpNewsMediaId;
+ }
+
+ public void setMpNewsMediaId(String mpNewsMediaId) {
+ this.mpNewsMediaId = mpNewsMediaId;
+ }
+
/**
*
* 请使用
@@ -53,52 +121,68 @@ public class WxMpCustomMessage implements Serializable {
* {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_MUSIC}
* {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_VIDEO}
* {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_NEWS}
+ * {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_MPNEWS}
* {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_WXCARD}
*
+ *
* @param msgType
*/
public void setMsgType(String msgType) {
this.msgType = msgType;
}
+
public String getContent() {
return this.content;
}
+
public void setContent(String content) {
this.content = content;
}
+
public String getMediaId() {
return this.mediaId;
}
+
public void setMediaId(String mediaId) {
this.mediaId = mediaId;
}
+
public String getThumbMediaId() {
return this.thumbMediaId;
}
+
public void setThumbMediaId(String thumbMediaId) {
this.thumbMediaId = thumbMediaId;
}
+
public String getTitle() {
return this.title;
}
+
public void setTitle(String title) {
this.title = title;
}
+
public String getDescription() {
return this.description;
}
+
public void setDescription(String description) {
this.description = description;
}
+
public String getMusicUrl() {
return this.musicUrl;
}
+
public void setMusicUrl(String musicUrl) {
this.musicUrl = musicUrl;
}
+
public String getHqMusicUrl() {
return this.hqMusicUrl;
}
+
public void setHqMusicUrl(String hqMusicUrl) {
this.hqMusicUrl = hqMusicUrl;
}
@@ -114,6 +198,7 @@ public class WxMpCustomMessage implements Serializable {
public List getArticles() {
return this.articles;
}
+
public void setArticles(List articles) {
this.articles = articles;
}
@@ -122,8 +207,15 @@ public class WxMpCustomMessage implements Serializable {
return WxMpGsonBuilder.INSTANCE.create().toJson(this);
}
- public static class WxArticle {
+ public String getKfAccount() {
+ return this.kfAccount;
+ }
+ public void setKfAccount(String kfAccount) {
+ this.kfAccount = kfAccount;
+ }
+
+ public static class WxArticle {
private String title;
private String description;
private String url;
@@ -132,85 +224,34 @@ public class WxMpCustomMessage implements Serializable {
public String getTitle() {
return this.title;
}
+
public void setTitle(String title) {
this.title = title;
}
+
public String getDescription() {
return this.description;
}
+
public void setDescription(String description) {
this.description = description;
}
+
public String getUrl() {
return this.url;
}
+
public void setUrl(String url) {
this.url = url;
}
+
public String getPicUrl() {
return this.picUrl;
}
+
public void setPicUrl(String picUrl) {
this.picUrl = picUrl;
}
}
-
- /**
- * 获得文本消息builder
- */
- public static TextBuilder TEXT() {
- return new TextBuilder();
- }
-
- /**
- * 获得图片消息builder
- */
- public static ImageBuilder IMAGE() {
- return new ImageBuilder();
- }
-
- /**
- * 获得语音消息builder
- */
- public static VoiceBuilder VOICE() {
- return new VoiceBuilder();
- }
-
- /**
- * 获得视频消息builder
- */
- public static VideoBuilder VIDEO() {
- return new VideoBuilder();
- }
-
- /**
- * 获得音乐消息builder
- */
- public static MusicBuilder MUSIC() {
- return new MusicBuilder();
- }
-
- /**
- * 获得图文消息builder
- */
- public static NewsBuilder NEWS() {
- return new NewsBuilder();
- }
-
-
- /**
- * 获得卡券消息builder
- */
- public static WxCardBuilder WXCARD() {
- return new WxCardBuilder();
- }
-
- public String getKfAccount() {
- return this.kfAccount;
- }
-
- public void setKfAccount(String kfAccount) {
- this.kfAccount = kfAccount;
- }
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/request/WxMpKfSessionRequest.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/request/WxMpKfSessionRequest.java
index e821916e..ac59e323 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/request/WxMpKfSessionRequest.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/request/WxMpKfSessionRequest.java
@@ -1,14 +1,11 @@
package me.chanjar.weixin.mp.bean.kefu.request;
-import java.io.Serializable;
-
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-
import com.google.gson.annotations.SerializedName;
-
+import me.chanjar.weixin.common.util.ToStringUtils;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
+import java.io.Serializable;
+
public class WxMpKfSessionRequest implements Serializable {
private static final long serialVersionUID = -5451863610674856927L;
@@ -17,7 +14,7 @@ public class WxMpKfSessionRequest implements Serializable {
*/
@SerializedName("kf_account")
private String kfAccount;
-
+
/**
* openid 客户openid
*/
@@ -31,9 +28,9 @@ public class WxMpKfSessionRequest implements Serializable {
@Override
public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
+ return ToStringUtils.toSimpleString(this);
}
-
+
public String toJson() {
return WxMpGsonBuilder.INSTANCE.create().toJson(this);
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfInfo.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfInfo.java
index 37154aa4..868bf519 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfInfo.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfInfo.java
@@ -1,12 +1,10 @@
package me.chanjar.weixin.mp.bean.kefu.result;
-import java.io.Serializable;
-
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
+import me.chanjar.weixin.common.util.ToStringUtils;
+
+import java.io.Serializable;
/**
* 客服基本信息以及客服在线状态信息
@@ -127,7 +125,7 @@ public class WxMpKfInfo implements Serializable {
@Override
public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
+ return ToStringUtils.toSimpleString(this);
}
public String getWxAccount() {
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfList.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfList.java
index 062ff9ac..9ec9eeff 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfList.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfList.java
@@ -1,15 +1,12 @@
package me.chanjar.weixin.mp.bean.kefu.result;
-import java.util.List;
-
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-
import com.google.gson.annotations.SerializedName;
-
+import me.chanjar.weixin.common.util.ToStringUtils;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
+
+import java.util.List;
/**
- *
+ *
* @author Binary Wang
*
*/
@@ -19,7 +16,7 @@ public class WxMpKfList {
@Override
public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
+ return ToStringUtils.toSimpleString(this);
}
public List getKfList() {
@@ -28,8 +25,8 @@ public class WxMpKfList {
public void setKfList(List kfList) {
this.kfList = kfList;
- }
-
+ }
+
public static WxMpKfList fromJson(String json) {
return WxMpGsonBuilder.INSTANCE.create().fromJson(json, WxMpKfList.class);
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfMsgList.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfMsgList.java
index 570f2def..7c04acb3 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfMsgList.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfMsgList.java
@@ -1,9 +1,8 @@
package me.chanjar.weixin.mp.bean.kefu.result;
import com.google.gson.annotations.SerializedName;
+import me.chanjar.weixin.common.util.ToStringUtils;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
import java.util.List;
@@ -46,7 +45,7 @@ public class WxMpKfMsgList {
@Override
public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
+ return ToStringUtils.toSimpleString(this);
}
public static WxMpKfMsgList fromJson(String responseContent) {
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfMsgRecord.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfMsgRecord.java
index 7f326ac1..0ed9c0b2 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfMsgRecord.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfMsgRecord.java
@@ -1,9 +1,7 @@
package me.chanjar.weixin.mp.bean.kefu.result;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-
import com.google.gson.annotations.SerializedName;
+import me.chanjar.weixin.common.util.ToStringUtils;
/**
* Created by Binary Wang on 2016/7/18.
@@ -41,8 +39,9 @@ public class WxMpKfMsgRecord {
@Override
public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
+ return ToStringUtils.toSimpleString(this);
}
+
public String getWorker() {
return this.worker;
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfOnlineList.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfOnlineList.java
index b4a418f6..97500095 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfOnlineList.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfOnlineList.java
@@ -1,15 +1,12 @@
package me.chanjar.weixin.mp.bean.kefu.result;
-import java.util.List;
-
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-
import com.google.gson.annotations.SerializedName;
-
+import me.chanjar.weixin.common.util.ToStringUtils;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
+
+import java.util.List;
/**
- *
+ *
* @author Binary Wang
*
*/
@@ -19,9 +16,9 @@ public class WxMpKfOnlineList {
@Override
public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
+ return ToStringUtils.toSimpleString(this);
}
-
+
public List getKfOnlineList() {
return this.kfOnlineList;
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSession.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSession.java
index e29f45b8..da29b4ae 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSession.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSession.java
@@ -1,12 +1,10 @@
package me.chanjar.weixin.mp.bean.kefu.result;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-
import com.google.gson.annotations.SerializedName;
+import me.chanjar.weixin.common.util.ToStringUtils;
/**
- *
+ *
* @author Binary Wang
*
*/
@@ -39,9 +37,9 @@ public class WxMpKfSession {
@Override
public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
+ return ToStringUtils.toSimpleString(this);
}
-
+
public String getKfAccount() {
return this.kfAccount;
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSessionGetResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSessionGetResult.java
index 22a6cf24..2eb73143 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSessionGetResult.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSessionGetResult.java
@@ -1,14 +1,11 @@
package me.chanjar.weixin.mp.bean.kefu.result;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-
import com.google.gson.annotations.SerializedName;
-
+import me.chanjar.weixin.common.util.ToStringUtils;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
/**
- *
+ *
* @author Binary Wang
*
*/
@@ -27,13 +24,13 @@ public class WxMpKfSessionGetResult {
@Override
public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
+ return ToStringUtils.toSimpleString(this);
}
-
+
public static WxMpKfSessionGetResult fromJson(String json) {
return WxMpGsonBuilder.INSTANCE.create().fromJson(json, WxMpKfSessionGetResult.class);
}
-
+
public String getKfAccount() {
return this.kfAccount;
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSessionList.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSessionList.java
index dea7e243..a9a0640e 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSessionList.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSessionList.java
@@ -1,16 +1,13 @@
package me.chanjar.weixin.mp.bean.kefu.result;
-import java.util.List;
-
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-
import com.google.gson.annotations.SerializedName;
-
+import me.chanjar.weixin.common.util.ToStringUtils;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
+import java.util.List;
+
/**
- *
+ *
* @author Binary Wang
*
*/
@@ -23,7 +20,7 @@ public class WxMpKfSessionList {
@Override
public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
+ return ToStringUtils.toSimpleString(this);
}
public static WxMpKfSessionList fromJson(String json) {
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSessionWaitCaseList.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSessionWaitCaseList.java
index dc2ab06b..22bcc4da 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSessionWaitCaseList.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/kefu/result/WxMpKfSessionWaitCaseList.java
@@ -1,16 +1,13 @@
package me.chanjar.weixin.mp.bean.kefu.result;
-import java.util.List;
-
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-
import com.google.gson.annotations.SerializedName;
-
+import me.chanjar.weixin.common.util.ToStringUtils;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
+import java.util.List;
+
/**
- *
+ *
* @author Binary Wang
*
*/
@@ -29,7 +26,7 @@ public class WxMpKfSessionWaitCaseList {
@Override
public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
+ return ToStringUtils.toSimpleString(this);
}
public static WxMpKfSessionWaitCaseList fromJson(String json) {
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMediaImgUploadResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMediaImgUploadResult.java
similarity index 91%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMediaImgUploadResult.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMediaImgUploadResult.java
index 58ff57a3..387a791a 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMediaImgUploadResult.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMediaImgUploadResult.java
@@ -1,4 +1,4 @@
-package me.chanjar.weixin.mp.bean.result;
+package me.chanjar.weixin.mp.bean.material;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
@@ -9,7 +9,7 @@ import java.io.Serializable;
*/
public class WxMediaImgUploadResult implements Serializable {
/**
- *
+ *
*/
private static final long serialVersionUID = 1996392453428768829L;
private String url;
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMaterial.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterial.java
similarity index 97%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMaterial.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterial.java
index 058d9034..8725510a 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMaterial.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterial.java
@@ -1,4 +1,4 @@
-package me.chanjar.weixin.mp.bean;
+package me.chanjar.weixin.mp.bean.material;
import java.io.File;
import java.util.HashMap;
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMaterialArticleUpdate.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialArticleUpdate.java
similarity index 95%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMaterialArticleUpdate.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialArticleUpdate.java
index f8ee265e..371b7e0d 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMaterialArticleUpdate.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialArticleUpdate.java
@@ -1,4 +1,4 @@
-package me.chanjar.weixin.mp.bean;
+package me.chanjar.weixin.mp.bean.material;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
@@ -7,7 +7,7 @@ import java.io.Serializable;
public class WxMpMaterialArticleUpdate implements Serializable {
/**
- *
+ *
*/
private static final long serialVersionUID = -7611963949517780270L;
private String mediaId;
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMaterialCountResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialCountResult.java
similarity index 78%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMaterialCountResult.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialCountResult.java
index 94e20d50..6dd74889 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMaterialCountResult.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialCountResult.java
@@ -1,12 +1,10 @@
-package me.chanjar.weixin.mp.bean.result;
+package me.chanjar.weixin.mp.bean.material;
+
+import me.chanjar.weixin.common.util.ToStringUtils;
import java.io.Serializable;
public class WxMpMaterialCountResult implements Serializable {
-
- /**
- *
- */
private static final long serialVersionUID = -5568772662085874138L;
private int voiceCount;
private int videoCount;
@@ -47,8 +45,7 @@ public class WxMpMaterialCountResult implements Serializable {
@Override
public String toString() {
- return "WxMpMaterialCountResult [" + "voiceCount=" + this.voiceCount + ", videoCount=" + this.videoCount
- + ", imageCount=" + this.imageCount + ", newsCount=" + this.newsCount + "]";
+ return ToStringUtils.toSimpleString(this);
}
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMaterialFileBatchGetResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialFileBatchGetResult.java
similarity index 81%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMaterialFileBatchGetResult.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialFileBatchGetResult.java
index 40eaecc1..5df9f454 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMaterialFileBatchGetResult.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialFileBatchGetResult.java
@@ -1,14 +1,12 @@
-package me.chanjar.weixin.mp.bean.result;
+package me.chanjar.weixin.mp.bean.material;
+
+import me.chanjar.weixin.common.util.ToStringUtils;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
public class WxMpMaterialFileBatchGetResult implements Serializable {
-
- /**
- *
- */
private static final long serialVersionUID = -560388368297267884L;
private int totalCount;
private int itemCount;
@@ -40,7 +38,7 @@ public class WxMpMaterialFileBatchGetResult implements Serializable {
@Override
public String toString() {
- return "WxMpMaterialFileBatchGetResult [" + "totalCount=" + this.totalCount + ", itemCount=" + this.itemCount + ", items=" + this.items + "]";
+ return ToStringUtils.toSimpleString(this);
}
public static class WxMaterialFileBatchGetNewsItem {
@@ -83,7 +81,7 @@ public class WxMpMaterialFileBatchGetResult implements Serializable {
@Override
public String toString() {
- return "WxMaterialFileBatchGetNewsItem [" + "mediaId=" + this.mediaId + ", updateTime=" + this.updateTime + ", name=" + this.name + ", url=" + this.url + "]";
+ return ToStringUtils.toSimpleString(this);
}
}
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMaterialNews.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialNews.java
similarity index 88%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMaterialNews.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialNews.java
index df40f6c3..70b11fbf 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMaterialNews.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialNews.java
@@ -1,5 +1,6 @@
-package me.chanjar.weixin.mp.bean;
+package me.chanjar.weixin.mp.bean.material;
+import me.chanjar.weixin.common.util.ToStringUtils;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
import java.io.Serializable;
@@ -7,11 +8,8 @@ import java.util.ArrayList;
import java.util.List;
public class WxMpMaterialNews implements Serializable {
-
- /**
- *
- */
private static final long serialVersionUID = -3283203652013494976L;
+
private List articles = new ArrayList<>();
public List getArticles() {
@@ -81,7 +79,6 @@ public class WxMpMaterialNews implements Serializable {
/**
* 点击图文消息跳转链接
- * @return
*/
private String url;
@@ -159,14 +156,12 @@ public class WxMpMaterialNews implements Serializable {
@Override
public String toString() {
- return "WxMpMassNewsArticle [" + "thumbMediaId=" + this.thumbMediaId + "thumbUrl=" + this.thumbUrl + ", author=" + this.author + ", title=" + this.title +
- ", contentSourceUrl=" + this.contentSourceUrl + ", content=" + this.content + ", digest=" + this.digest +
- ", showCoverPic=" + this.showCoverPic +", url=" + this.url + "]";
+ return ToStringUtils.toSimpleString(this);
}
}
@Override
public String toString() {
- return "WxMpMaterialNews [" + "articles=" + this.articles + "]";
+ return ToStringUtils.toSimpleString(this);
}
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMaterialNewsBatchGetResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialNewsBatchGetResult.java
similarity index 79%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMaterialNewsBatchGetResult.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialNewsBatchGetResult.java
index 48563244..03f0a6d8 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMaterialNewsBatchGetResult.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialNewsBatchGetResult.java
@@ -1,17 +1,14 @@
-package me.chanjar.weixin.mp.bean.result;
+package me.chanjar.weixin.mp.bean.material;
-import me.chanjar.weixin.mp.bean.WxMpMaterialNews;
+import me.chanjar.weixin.common.util.ToStringUtils;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
public class WxMpMaterialNewsBatchGetResult implements Serializable {
-
- /**
- *
- */
private static final long serialVersionUID = -1617952797921001666L;
+
private int totalCount;
private int itemCount;
private List items;
@@ -42,7 +39,7 @@ public class WxMpMaterialNewsBatchGetResult implements Serializable {
@Override
public String toString() {
- return "WxMpMaterialNewsBatchGetResult [" + "totalCount=" + this.totalCount + ", itemCount=" + this.itemCount + ", items=" + this.items + "]";
+ return ToStringUtils.toSimpleString(this);
}
public static class WxMaterialNewsBatchGetNewsItem {
@@ -76,7 +73,7 @@ public class WxMpMaterialNewsBatchGetResult implements Serializable {
@Override
public String toString() {
- return "WxMaterialNewsBatchGetNewsItem [" + "mediaId=" + this.mediaId + ", updateTime=" + this.updateTime + ", content=" + this.content + "]";
+ return ToStringUtils.toSimpleString(this);
}
}
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMaterialUploadResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialUploadResult.java
similarity index 94%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMaterialUploadResult.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialUploadResult.java
index cb9cecd1..2b3a1e57 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMaterialUploadResult.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialUploadResult.java
@@ -1,4 +1,4 @@
-package me.chanjar.weixin.mp.bean.result;
+package me.chanjar.weixin.mp.bean.material;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
@@ -7,7 +7,7 @@ import java.io.Serializable;
public class WxMpMaterialUploadResult implements Serializable {
/**
- *
+ *
*/
private static final long serialVersionUID = -128818731449449537L;
private String mediaId;
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMaterialVideoInfoResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialVideoInfoResult.java
similarity index 95%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMaterialVideoInfoResult.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialVideoInfoResult.java
index 456544d1..06b85b7e 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMaterialVideoInfoResult.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialVideoInfoResult.java
@@ -1,4 +1,4 @@
-package me.chanjar.weixin.mp.bean.result;
+package me.chanjar.weixin.mp.bean.material;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
@@ -7,7 +7,7 @@ import java.io.Serializable;
public class WxMpMaterialVideoInfoResult implements Serializable {
/**
- *
+ *
*/
private static final long serialVersionUID = 1269131745333792202L;
private String title;
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessage.java
similarity index 91%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlMessage.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessage.java
index 9adcb54d..732c0d54 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlMessage.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessage.java
@@ -1,22 +1,19 @@
-package me.chanjar.weixin.mp.bean;
-
-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 org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
+package me.chanjar.weixin.mp.bean.message;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
-
+import me.chanjar.weixin.common.util.ToStringUtils;
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.mp.util.crypto.WxMpCryptUtil;
import me.chanjar.weixin.mp.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;
/**
*
@@ -56,6 +53,9 @@ public class WxMpXmlMessage implements Serializable {
@XStreamConverter(value = XStreamCDataConverter.class)
private String content;
+ @XStreamAlias("MenuId")
+ private Long menuId;
+
@XStreamAlias("MsgId")
private Long msgId;
@@ -239,6 +239,54 @@ public class WxMpXmlMessage implements Serializable {
@XStreamAlias("msg")
private String msg;
+ ///////////////////////////////////////
+ // 微信认证事件推送
+ ///////////////////////////////////////
+ /**
+ * ExpiredTime
+ * 资质认证成功/名称认证成功: 有效期 (整形),指的是时间戳,将于该时间戳认证过期
+ * 年审通知: 有效期 (整形),指的是时间戳,将于该时间戳认证过期,需尽快年审
+ * 认证过期失效通知: 有效期 (整形),指的是时间戳,表示已于该时间戳认证过期,需要重新发起微信认证
+ */
+ @XStreamAlias("ExpiredTime")
+ private Long expiredTime;
+ /**
+ * FailTime
+ * 失败发生时间 (整形),时间戳
+ */
+ @XStreamAlias("FailTime")
+ private Long failTime;
+ /**
+ * FailReason
+ * 认证失败的原因
+ */
+ @XStreamAlias("FailReason")
+ private String failReason;
+
+ public Long getExpiredTime() {
+ return this.expiredTime;
+ }
+
+ public void setExpiredTime(Long expiredTime) {
+ this.expiredTime = expiredTime;
+ }
+
+ public Long getFailTime() {
+ return this.failTime;
+ }
+
+ public void setFailTime(Long failTime) {
+ this.failTime = failTime;
+ }
+
+ public String getFailReason() {
+ return this.failReason;
+ }
+
+ public void setFailReason(String failReason) {
+ this.failReason = failReason;
+ }
+
public String getStoreUniqId() {
return this.storeUniqId;
}
@@ -639,6 +687,14 @@ public class WxMpXmlMessage implements Serializable {
this.sendLocationInfo = sendLocationInfo;
}
+ public Long getMenuId() {
+ return this.menuId;
+ }
+
+ public void setMenuId(Long menuId) {
+ this.menuId = menuId;
+ }
+
public String getKfAccount() {
return this.kfAccount;
}
@@ -667,7 +723,7 @@ public class WxMpXmlMessage implements Serializable {
public static class ScanCodeInfo {
@Override
public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
+ return ToStringUtils.toSimpleString(this);
}
@XStreamAlias("ScanType")
@@ -707,7 +763,7 @@ public class WxMpXmlMessage implements Serializable {
public static class SendPicsInfo {
@Override
public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
+ return ToStringUtils.toSimpleString(this);
}
@XStreamAlias("Count")
@@ -732,8 +788,7 @@ public class WxMpXmlMessage implements Serializable {
public static class Item {
@Override
public String toString() {
- return ToStringBuilder.reflectionToString(this,
- ToStringStyle.JSON_STYLE);
+ return ToStringUtils.toSimpleString(this);
}
@XStreamAlias("PicMd5Sum")
@@ -775,7 +830,7 @@ public class WxMpXmlMessage implements Serializable {
@Override
public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
+ return ToStringUtils.toSimpleString(this);
}
public String getLocationX() {
@@ -821,6 +876,6 @@ public class WxMpXmlMessage implements Serializable {
@Override
public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
+ return ToStringUtils.toSimpleString(this);
}
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutImageMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutImageMessage.java
similarity index 93%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutImageMessage.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutImageMessage.java
index 18204a51..62852ca8 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutImageMessage.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutImageMessage.java
@@ -1,4 +1,4 @@
-package me.chanjar.weixin.mp.bean;
+package me.chanjar.weixin.mp.bean.message;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
@@ -9,7 +9,7 @@ import me.chanjar.weixin.common.util.xml.XStreamMediaIdConverter;
public class WxMpXmlOutImageMessage extends WxMpXmlOutMessage {
/**
- *
+ *
*/
private static final long serialVersionUID = -2684778597067990723L;
@XStreamAlias("Image")
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMessage.java
similarity index 96%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutMessage.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMessage.java
index 2eb6818b..5b8b81e5 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutMessage.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMessage.java
@@ -1,10 +1,10 @@
-package me.chanjar.weixin.mp.bean;
+package me.chanjar.weixin.mp.bean.message;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
-import me.chanjar.weixin.mp.bean.outxmlbuilder.*;
+import me.chanjar.weixin.mp.builder.outxml.*;
import me.chanjar.weixin.mp.util.crypto.WxMpCryptUtil;
import me.chanjar.weixin.mp.util.xml.XStreamTransformer;
@@ -18,14 +18,14 @@ public abstract class WxMpXmlOutMessage implements Serializable {
@XStreamAlias("ToUserName")
@XStreamConverter(value=XStreamCDataConverter.class)
protected String toUserName;
-
+
@XStreamAlias("FromUserName")
@XStreamConverter(value=XStreamCDataConverter.class)
protected String fromUserName;
-
+
@XStreamAlias("CreateTime")
protected Long createTime;
-
+
@XStreamAlias("MsgType")
@XStreamConverter(value=XStreamCDataConverter.class)
protected String msgType;
@@ -61,7 +61,7 @@ public abstract class WxMpXmlOutMessage implements Serializable {
public void setMsgType(String msgType) {
this.msgType = msgType;
}
-
+
public String toXml() {
return XStreamTransformer.toXml((Class) this.getClass(), this);
}
@@ -95,28 +95,28 @@ public abstract class WxMpXmlOutMessage implements Serializable {
public static VoiceBuilder VOICE() {
return new VoiceBuilder();
}
-
+
/**
* 获得视频消息builder
*/
public static VideoBuilder VIDEO() {
return new VideoBuilder();
}
-
+
/**
* 获得音乐消息builder
*/
public static MusicBuilder MUSIC() {
return new MusicBuilder();
}
-
+
/**
* 获得图文消息builder
*/
public static NewsBuilder NEWS() {
return new NewsBuilder();
}
-
+
/**
* 获得客服消息builder
*/
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutMusicMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMusicMessage.java
similarity index 97%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutMusicMessage.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMusicMessage.java
index ec71167c..a5b48619 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutMusicMessage.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMusicMessage.java
@@ -1,4 +1,4 @@
-package me.chanjar.weixin.mp.bean;
+package me.chanjar.weixin.mp.bean.message;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
@@ -9,7 +9,7 @@ import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
public class WxMpXmlOutMusicMessage extends WxMpXmlOutMessage {
/**
- *
+ *
*/
private static final long serialVersionUID = -4159937804975448945L;
@XStreamAlias("Music")
@@ -34,7 +34,7 @@ public class WxMpXmlOutMusicMessage extends WxMpXmlOutMessage {
public void setDescription(String description) {
this.music.setDescription(description);
}
-
+
public String getThumbMediaId() {
return this.music.getThumbMediaId();
}
@@ -58,10 +58,10 @@ public class WxMpXmlOutMusicMessage extends WxMpXmlOutMessage {
public void setHqMusicUrl(String hqMusicUrl) {
this.music.setHqMusicUrl(hqMusicUrl);
}
-
+
@XStreamAlias("Music")
public static class Music {
-
+
@XStreamAlias("Title")
@XStreamConverter(value=XStreamCDataConverter.class)
private String title;
@@ -73,15 +73,15 @@ public class WxMpXmlOutMusicMessage extends WxMpXmlOutMessage {
@XStreamAlias("ThumbMediaId")
@XStreamConverter(value=XStreamCDataConverter.class)
private String thumbMediaId;
-
+
@XStreamAlias("MusicUrl")
@XStreamConverter(value=XStreamCDataConverter.class)
private String musicUrl;
-
+
@XStreamAlias("HQMusicUrl")
@XStreamConverter(value=XStreamCDataConverter.class)
private String hqMusicUrl;
-
+
public String getTitle() {
return this.title;
}
@@ -121,7 +121,7 @@ public class WxMpXmlOutMusicMessage extends WxMpXmlOutMessage {
public void setHqMusicUrl(String hqMusicUrl) {
this.hqMusicUrl = hqMusicUrl;
}
-
+
}
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutNewsMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutNewsMessage.java
similarity index 96%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutNewsMessage.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutNewsMessage.java
index 170023a3..413a6d7c 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutNewsMessage.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutNewsMessage.java
@@ -1,4 +1,4 @@
-package me.chanjar.weixin.mp.bean;
+package me.chanjar.weixin.mp.bean.message;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
@@ -12,16 +12,16 @@ import java.util.List;
public class WxMpXmlOutNewsMessage extends WxMpXmlOutMessage {
/**
- *
+ *
*/
private static final long serialVersionUID = -4604402850905714772L;
@XStreamAlias("ArticleCount")
protected int articleCount;
-
+
@XStreamAlias("Articles")
protected final List- articles = new ArrayList<>();
-
+
public WxMpXmlOutNewsMessage() {
this.msgType = WxConsts.XML_MSG_NEWS;
}
@@ -34,15 +34,15 @@ public class WxMpXmlOutNewsMessage extends WxMpXmlOutMessage {
this.articles.add(item);
this.articleCount = this.articles.size();
}
-
+
public List
- getArticles() {
return this.articles;
}
-
-
+
+
@XStreamAlias("item")
public static class Item {
-
+
@XStreamAlias("Title")
@XStreamConverter(value=XStreamCDataConverter.class)
private String Title;
@@ -54,11 +54,11 @@ public class WxMpXmlOutNewsMessage extends WxMpXmlOutMessage {
@XStreamAlias("PicUrl")
@XStreamConverter(value=XStreamCDataConverter.class)
private String PicUrl;
-
+
@XStreamAlias("Url")
@XStreamConverter(value=XStreamCDataConverter.class)
private String Url;
-
+
public String getTitle() {
return this.Title;
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutTextMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTextMessage.java
similarity index 93%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutTextMessage.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTextMessage.java
index 4c439a7c..0719b1ed 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutTextMessage.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTextMessage.java
@@ -1,4 +1,4 @@
-package me.chanjar.weixin.mp.bean;
+package me.chanjar.weixin.mp.bean.message;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
@@ -7,9 +7,9 @@ import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
@XStreamAlias("xml")
public class WxMpXmlOutTextMessage extends WxMpXmlOutMessage {
-
+
/**
- *
+ *
*/
private static final long serialVersionUID = -3972786455288763361L;
@XStreamAlias("Content")
@@ -19,7 +19,7 @@ public class WxMpXmlOutTextMessage extends WxMpXmlOutMessage {
public WxMpXmlOutTextMessage() {
this.msgType = WxConsts.XML_MSG_TEXT;
}
-
+
public String getContent() {
return this.content;
}
@@ -28,5 +28,5 @@ public class WxMpXmlOutTextMessage extends WxMpXmlOutMessage {
this.content = content;
}
-
+
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutTransferCustomerServiceMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTransferKefuMessage.java
similarity index 84%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutTransferCustomerServiceMessage.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTransferKefuMessage.java
index a1a48bbe..b0eece70 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutTransferCustomerServiceMessage.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTransferKefuMessage.java
@@ -1,4 +1,4 @@
-package me.chanjar.weixin.mp.bean;
+package me.chanjar.weixin.mp.bean.message;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
@@ -6,13 +6,13 @@ import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
@XStreamAlias("xml")
-public class WxMpXmlOutTransferCustomerServiceMessage extends WxMpXmlOutMessage {
+public class WxMpXmlOutTransferKefuMessage extends WxMpXmlOutMessage {
private static final long serialVersionUID = 1850903037285841322L;
-
+
@XStreamAlias("TransInfo")
protected TransInfo transInfo;
- public WxMpXmlOutTransferCustomerServiceMessage() {
+ public WxMpXmlOutTransferKefuMessage() {
this.msgType = WxConsts.CUSTOM_MSG_TRANSFER_CUSTOMER_SERVICE;
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutVideoMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVideoMessage.java
similarity index 97%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutVideoMessage.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVideoMessage.java
index a8f751cf..3c042f6d 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutVideoMessage.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVideoMessage.java
@@ -1,4 +1,4 @@
-package me.chanjar.weixin.mp.bean;
+package me.chanjar.weixin.mp.bean.message;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
@@ -9,7 +9,7 @@ import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
public class WxMpXmlOutVideoMessage extends WxMpXmlOutMessage {
/**
- *
+ *
*/
private static final long serialVersionUID = 1745902309380113978L;
@XStreamAlias("Video")
@@ -42,11 +42,11 @@ public class WxMpXmlOutVideoMessage extends WxMpXmlOutMessage {
public void setDescription(String description) {
this.video.setDescription(description);
}
-
+
@XStreamAlias("Video")
public static class Video {
-
+
@XStreamAlias("MediaId")
@XStreamConverter(value=XStreamCDataConverter.class)
private String mediaId;
@@ -82,7 +82,7 @@ public class WxMpXmlOutVideoMessage extends WxMpXmlOutMessage {
public void setDescription(String description) {
this.description = description;
}
-
+
}
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutVoiceMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVoiceMessage.java
similarity index 93%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutVoiceMessage.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVoiceMessage.java
index a47766dc..ec354ddf 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutVoiceMessage.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVoiceMessage.java
@@ -1,4 +1,4 @@
-package me.chanjar.weixin.mp.bean;
+package me.chanjar.weixin.mp.bean.message;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
@@ -9,7 +9,7 @@ import me.chanjar.weixin.common.util.xml.XStreamMediaIdConverter;
public class WxMpXmlOutVoiceMessage extends WxMpXmlOutMessage {
/**
- *
+ *
*/
private static final long serialVersionUID = 240367390249860551L;
@XStreamAlias("Voice")
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/TransferCustomerServiceBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/TransferCustomerServiceBuilder.java
deleted file mode 100644
index 87ec3a04..00000000
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/TransferCustomerServiceBuilder.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package me.chanjar.weixin.mp.bean.outxmlbuilder;
-
-import me.chanjar.weixin.common.util.StringUtils;
-import me.chanjar.weixin.mp.bean.WxMpXmlOutTransferCustomerServiceMessage;
-
-/**
- * 客服消息builder
- *
- * 用法: WxMpCustomMessage m = WxMpXmlOutMessage.TRANSFER_CUSTOMER_SERVICE().content(...).toUser(...).build();
- *
- *
- * @author chanjarster
- */
-public final class TransferCustomerServiceBuilder extends BaseBuilder {
- private String kfAccount;
-
- public TransferCustomerServiceBuilder kfAccount(String kf) {
- this.kfAccount = kf;
- return this;
- }
-
- @Override
- public WxMpXmlOutTransferCustomerServiceMessage build() {
- WxMpXmlOutTransferCustomerServiceMessage m = new WxMpXmlOutTransferCustomerServiceMessage();
- setCommon(m);
- if(StringUtils.isNotBlank(this.kfAccount)){
- WxMpXmlOutTransferCustomerServiceMessage.TransInfo transInfo = new WxMpXmlOutTransferCustomerServiceMessage.TransInfo();
- transInfo.setKfAccount(this.kfAccount);
- m.setTransInfo(transInfo);
- }
- return m;
- }
-}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxMpPayCallback.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxMpPayCallback.java
deleted file mode 100644
index e32e721e..00000000
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxMpPayCallback.java
+++ /dev/null
@@ -1,283 +0,0 @@
-package me.chanjar.weixin.mp.bean.pay;
-
-import java.io.Serializable;
-
-/**
- * pre> 订单支付状态回调
- *
- * 支付结果通知(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7)
- *
- * /pre>
- *
- * @author ukid
- */
-public class WxMpPayCallback implements Serializable {
- /**
- *
- */
- private static final long serialVersionUID = -4143804055690843641L;
- private String return_code;
- private String return_msg;
-
- private String appid;
- private String mch_id;
- private String device_info;
- private String nonce_str;
- private String sign;
- private String result_code;
- private String err_code;
- private String err_code_des;
- private String openid;
- private String is_subscribe;
- private String trade_type;
- private String bank_type;
- private String total_fee;
- private String fee_type;
- private String cash_fee;
- private String cash_fee_type;
- private String coupon_fee;
- private String coupon_count;
- private String coupon_batch_id_$n;
- private String coupon_id_$n;
- private String coupon_fee_$n;
- private String transaction_id;
- private String out_trade_no;
- private String attach;
- private String time_end;
-
- public String getReturn_code() {
- return this.return_code;
- }
-
- public String getReturn_msg() {
- return this.return_msg;
- }
-
- public String getAppid() {
- return this.appid;
- }
-
- public String getMch_id() {
- return this.mch_id;
- }
-
- public String getDevice_info() {
- return this.device_info;
- }
-
- public String getNonce_str() {
- return this.nonce_str;
- }
-
- public String getSign() {
- return this.sign;
- }
-
- public String getResult_code() {
- return this.result_code;
- }
-
- public String getErr_code() {
- return this.err_code;
- }
-
- public String getErr_code_des() {
- return this.err_code_des;
- }
-
- public String getOpenid() {
- return this.openid;
- }
-
- public String getIs_subscribe() {
- return this.is_subscribe;
- }
-
- public String getTrade_type() {
- return this.trade_type;
- }
-
- public String getBank_type() {
- return this.bank_type;
- }
-
- public String getTotal_fee() {
- return this.total_fee;
- }
-
- public String getFee_type() {
- return this.fee_type;
- }
-
- public String getCash_fee() {
- return this.cash_fee;
- }
-
- public String getCash_fee_type() {
- return this.cash_fee_type;
- }
-
- public String getCoupon_fee() {
- return this.coupon_fee;
- }
-
- public String getCoupon_count() {
- return this.coupon_count;
- }
-
- public String getCoupon_batch_id_$n() {
- return this.coupon_batch_id_$n;
- }
-
- public String getCoupon_id_$n() {
- return this.coupon_id_$n;
- }
-
- public String getCoupon_fee_$n() {
- return this.coupon_fee_$n;
- }
-
- public String getTransaction_id() {
- return this.transaction_id;
- }
-
- public String getOut_trade_no() {
- return this.out_trade_no;
- }
-
- public String getAttach() {
- return this.attach;
- }
-
- public String getTime_end() {
- return this.time_end;
- }
-
- public void setReturn_code(String return_code) {
- this.return_code = return_code;
- }
-
- public void setReturn_msg(String return_msg) {
- this.return_msg = return_msg;
- }
-
- public void setAppid(String appid) {
- this.appid = appid;
- }
-
- public void setMch_id(String mch_id) {
- this.mch_id = mch_id;
- }
-
- public void setDevice_info(String device_info) {
- this.device_info = device_info;
- }
-
- public void setNonce_str(String nonce_str) {
- this.nonce_str = nonce_str;
- }
-
- public void setSign(String sign) {
- this.sign = sign;
- }
-
- public void setResult_code(String result_code) {
- this.result_code = result_code;
- }
-
- public void setErr_code(String err_code) {
- this.err_code = err_code;
- }
-
- public void setErr_code_des(String err_code_des) {
- this.err_code_des = err_code_des;
- }
-
- public void setOpenid(String openid) {
- this.openid = openid;
- }
-
- public void setIs_subscribe(String is_subscribe) {
- this.is_subscribe = is_subscribe;
- }
-
- public void setTrade_type(String trade_type) {
- this.trade_type = trade_type;
- }
-
- public void setBank_type(String bank_type) {
- this.bank_type = bank_type;
- }
-
- public void setTotal_fee(String total_fee) {
- this.total_fee = total_fee;
- }
-
- public void setFee_type(String fee_type) {
- this.fee_type = fee_type;
- }
-
- public void setCash_fee(String cash_fee) {
- this.cash_fee = cash_fee;
- }
-
- public void setCash_fee_type(String cash_fee_type) {
- this.cash_fee_type = cash_fee_type;
- }
-
- public void setCoupon_fee(String coupon_fee) {
- this.coupon_fee = coupon_fee;
- }
-
- public void setCoupon_count(String coupon_count) {
- this.coupon_count = coupon_count;
- }
-
- public void setCoupon_batch_id_$n(String coupon_batch_id_$n) {
- this.coupon_batch_id_$n = coupon_batch_id_$n;
- }
-
- public void setCoupon_id_$n(String coupon_id_$n) {
- this.coupon_id_$n = coupon_id_$n;
- }
-
- public void setCoupon_fee_$n(String coupon_fee_$n) {
- this.coupon_fee_$n = coupon_fee_$n;
- }
-
- public void setTransaction_id(String transaction_id) {
- this.transaction_id = transaction_id;
- }
-
- public void setOut_trade_no(String out_trade_no) {
- this.out_trade_no = out_trade_no;
- }
-
- public void setAttach(String attach) {
- this.attach = attach;
- }
-
- public void setTime_end(String time_end) {
- this.time_end = time_end;
- }
-
- @Override
- public String toString() {
- return "WxMpPayCallback [return_code=" + this.return_code + ", return_msg="
- + this.return_msg + ", appid=" + this.appid + ", mch_id=" + this.mch_id
- + ", device_info=" + this.device_info + ", nonce_str=" + this.nonce_str
- + ", sign=" + this.sign + ", result_code=" + this.result_code
- + ", err_code=" + this.err_code + ", err_code_des=" + this.err_code_des
- + ", openid=" + this.openid + ", is_subscribe=" + this.is_subscribe
- + ", trade_type=" + this.trade_type + ", bank_type=" + this.bank_type
- + ", total_fee=" + this.total_fee + ", fee_type=" + this.fee_type
- + ", cash_fee=" + this.cash_fee + ", cash_fee_type=" + this.cash_fee_type
- + ", coupon_fee=" + this.coupon_fee + ", coupon_count="
- + this.coupon_count + ", coupon_batch_id_$n=" + this.coupon_batch_id_$n
- + ", coupon_id_$n=" + this.coupon_id_$n + ", coupon_fee_$n="
- + this.coupon_fee_$n + ", transaction_id=" + this.transaction_id
- + ", out_trade_no=" + this.out_trade_no + ", attach=" + this.attach
- + ", time_end=" + this.time_end + "]";
- }
-
-}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxMpPrepayIdResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxMpPrepayIdResult.java
deleted file mode 100644
index cff9d787..00000000
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxMpPrepayIdResult.java
+++ /dev/null
@@ -1,124 +0,0 @@
-package me.chanjar.weixin.mp.bean.pay;
-
-import java.io.Serializable;
-
-/**
- *
- * 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识"返回的结果
- * 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1)
- *
- *
- * @author chanjarster
- */
-@Deprecated
-public class WxMpPrepayIdResult implements Serializable {
- private static final long serialVersionUID = -8970574397788396143L;
- private String return_code;
- private String return_msg;
- private String appid;
- private String mch_id;
- private String nonce_str;
- private String sign;
- private String result_code;
- private String prepay_id;
- private String trade_type;
- private String err_code;
- private String err_code_des;
- private String code_url;
-
- public String getReturn_code() {
- return this.return_code;
- }
-
- public void setReturn_code(String return_code) {
- this.return_code = return_code;
- }
-
- public String getReturn_msg() {
- return this.return_msg;
- }
-
- public void setReturn_msg(String return_msg) {
- this.return_msg = return_msg;
- }
-
- public String getAppid() {
- return this.appid;
- }
-
- public void setAppid(String appid) {
- this.appid = appid;
- }
-
- public String getMch_id() {
- return this.mch_id;
- }
-
- public void setMch_id(String mch_id) {
- this.mch_id = mch_id;
- }
-
- public String getNonce_str() {
- return this.nonce_str;
- }
-
- public void setNonce_str(String nonce_str) {
- this.nonce_str = nonce_str;
- }
-
- public String getSign() {
- return this.sign;
- }
-
- public void setSign(String sign) {
- this.sign = sign;
- }
-
- public String getResult_code() {
- return this.result_code;
- }
-
- public void setResult_code(String result_code) {
- this.result_code = result_code;
- }
-
- public String getPrepay_id() {
- return this.prepay_id;
- }
-
- public void setPrepay_id(String prepay_id) {
- this.prepay_id = prepay_id;
- }
-
- public String getTrade_type() {
- return this.trade_type;
- }
-
- public void setTrade_type(String trade_type) {
- this.trade_type = trade_type;
- }
-
- public String getErr_code() {
- return this.err_code;
- }
-
- public void setErr_code(String err_code) {
- this.err_code = err_code;
- }
-
- public String getErr_code_des() {
- return this.err_code_des;
- }
-
- public void setErr_code_des(String err_code_des) {
- this.err_code_des = err_code_des;
- }
-
- public String getCode_url() {
- return this.code_url;
- }
-
- public void setCode_url(String code_url) {
- this.code_url = code_url;
- }
-}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxMpPayResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxPayJsSDKCallback.java
similarity index 78%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxMpPayResult.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxPayJsSDKCallback.java
index 2978ba17..07a3fe16 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxMpPayResult.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxPayJsSDKCallback.java
@@ -1,259 +1,267 @@
package me.chanjar.weixin.mp.bean.pay;
-import java.io.Serializable;
+import me.chanjar.weixin.common.util.ToStringUtils;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
+import java.io.Serializable;
/**
*
- * 查询订单支付状态返回的结果
- *
- * 查询订单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2)
- *
- *
+ * 订单支付状态回调
+ * 支付结果通知(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7)
+ * /pre>
*
* @author ukid
*/
-public class WxMpPayResult implements Serializable {
- @Override
- public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
- }
-
- private static final long serialVersionUID = -570934170727777190L;
-
+public class WxPayJsSDKCallback implements Serializable {
+ private static final long serialVersionUID = -4143804055690843641L;
private String return_code;
private String return_msg;
+
private String appid;
private String mch_id;
+ private String device_info;
private String nonce_str;
private String sign;
private String result_code;
private String err_code;
private String err_code_des;
- private String trade_state;
- private String trade_state_desc;
- private String device_info;
private String openid;
private String is_subscribe;
private String trade_type;
private String bank_type;
private String total_fee;
- private String coupon_fee;
private String fee_type;
+ private String cash_fee;
+ private String cash_fee_type;
+ private String coupon_fee;
+ private String coupon_count;
+ private String coupon_batch_id_$n;
+ private String coupon_id_$n;
+ private String coupon_fee_$n;
private String transaction_id;
private String out_trade_no;
private String attach;
private String time_end;
- /**
- * 现金支付金额 cash_fee 是 Int 100 现金支付金额订单现金支付金额,详见支付金额
- */
- private String cash_fee;
-
- /**
- * 现金支付货币类型 cash_fee_type 否
- *
- */
- private String cash_fee_type;
public String getReturn_code() {
return this.return_code;
}
+ public void setReturn_code(String return_code) {
+ this.return_code = return_code;
+ }
+
public String getReturn_msg() {
return this.return_msg;
}
+ public void setReturn_msg(String return_msg) {
+ this.return_msg = return_msg;
+ }
+
public String getAppid() {
return this.appid;
}
+ public void setAppid(String appid) {
+ this.appid = appid;
+ }
+
public String getMch_id() {
return this.mch_id;
}
+ public void setMch_id(String mch_id) {
+ this.mch_id = mch_id;
+ }
+
+ public String getDevice_info() {
+ return this.device_info;
+ }
+
+ public void setDevice_info(String device_info) {
+ this.device_info = device_info;
+ }
+
public String getNonce_str() {
return this.nonce_str;
}
+ public void setNonce_str(String nonce_str) {
+ this.nonce_str = nonce_str;
+ }
+
public String getSign() {
return this.sign;
}
+ public void setSign(String sign) {
+ this.sign = sign;
+ }
+
public String getResult_code() {
return this.result_code;
}
+ public void setResult_code(String result_code) {
+ this.result_code = result_code;
+ }
+
public String getErr_code() {
return this.err_code;
}
- public String getErr_code_des() {
- return this.err_code_des;
+ public void setErr_code(String err_code) {
+ this.err_code = err_code;
}
- public String getTrade_state() {
- return this.trade_state;
+ public String getErr_code_des() {
+ return this.err_code_des;
}
- public String getDevice_info() {
- return this.device_info;
+ public void setErr_code_des(String err_code_des) {
+ this.err_code_des = err_code_des;
}
public String getOpenid() {
return this.openid;
}
+ public void setOpenid(String openid) {
+ this.openid = openid;
+ }
+
public String getIs_subscribe() {
return this.is_subscribe;
}
+ public void setIs_subscribe(String is_subscribe) {
+ this.is_subscribe = is_subscribe;
+ }
+
public String getTrade_type() {
return this.trade_type;
}
+ public void setTrade_type(String trade_type) {
+ this.trade_type = trade_type;
+ }
+
public String getBank_type() {
return this.bank_type;
}
+ public void setBank_type(String bank_type) {
+ this.bank_type = bank_type;
+ }
+
public String getTotal_fee() {
return this.total_fee;
}
- public String getCoupon_fee() {
- return this.coupon_fee;
+ public void setTotal_fee(String total_fee) {
+ this.total_fee = total_fee;
}
public String getFee_type() {
return this.fee_type;
}
- public String getTransaction_id() {
- return this.transaction_id;
- }
-
- public String getOut_trade_no() {
- return this.out_trade_no;
- }
-
- public String getAttach() {
- return this.attach;
- }
-
- public String getTime_end() {
- return this.time_end;
+ public void setFee_type(String fee_type) {
+ this.fee_type = fee_type;
}
- public void setReturn_code(String return_code) {
- this.return_code = return_code;
+ public String getCash_fee() {
+ return this.cash_fee;
}
- public void setReturn_msg(String return_msg) {
- this.return_msg = return_msg;
+ public void setCash_fee(String cash_fee) {
+ this.cash_fee = cash_fee;
}
- public void setAppid(String appid) {
- this.appid = appid;
+ public String getCash_fee_type() {
+ return this.cash_fee_type;
}
- public void setMch_id(String mch_id) {
- this.mch_id = mch_id;
+ public void setCash_fee_type(String cash_fee_type) {
+ this.cash_fee_type = cash_fee_type;
}
- public void setNonce_str(String nonce_str) {
- this.nonce_str = nonce_str;
+ public String getCoupon_fee() {
+ return this.coupon_fee;
}
- public void setSign(String sign) {
- this.sign = sign;
+ public void setCoupon_fee(String coupon_fee) {
+ this.coupon_fee = coupon_fee;
}
- public void setResult_code(String result_code) {
- this.result_code = result_code;
+ public String getCoupon_count() {
+ return this.coupon_count;
}
- public void setErr_code(String err_code) {
- this.err_code = err_code;
+ public void setCoupon_count(String coupon_count) {
+ this.coupon_count = coupon_count;
}
- public void setErr_code_des(String err_code_des) {
- this.err_code_des = err_code_des;
+ public String getCoupon_batch_id_$n() {
+ return this.coupon_batch_id_$n;
}
- public void setTrade_state(String trade_state) {
- this.trade_state = trade_state;
+ public void setCoupon_batch_id_$n(String coupon_batch_id_$n) {
+ this.coupon_batch_id_$n = coupon_batch_id_$n;
}
- public void setDevice_info(String device_info) {
- this.device_info = device_info;
+ public String getCoupon_id_$n() {
+ return this.coupon_id_$n;
}
- public void setOpenid(String openid) {
- this.openid = openid;
+ public void setCoupon_id_$n(String coupon_id_$n) {
+ this.coupon_id_$n = coupon_id_$n;
}
- public void setIs_subscribe(String is_subscribe) {
- this.is_subscribe = is_subscribe;
+ public String getCoupon_fee_$n() {
+ return this.coupon_fee_$n;
}
- public void setTrade_type(String trade_type) {
- this.trade_type = trade_type;
+ public void setCoupon_fee_$n(String coupon_fee_$n) {
+ this.coupon_fee_$n = coupon_fee_$n;
}
- public void setBank_type(String bank_type) {
- this.bank_type = bank_type;
- }
-
- public void setTotal_fee(String total_fee) {
- this.total_fee = total_fee;
- }
-
- public void setCoupon_fee(String coupon_fee) {
- this.coupon_fee = coupon_fee;
- }
-
- public void setFee_type(String fee_type) {
- this.fee_type = fee_type;
+ public String getTransaction_id() {
+ return this.transaction_id;
}
public void setTransaction_id(String transaction_id) {
this.transaction_id = transaction_id;
}
- public void setOut_trade_no(String out_trade_no) {
- this.out_trade_no = out_trade_no;
- }
-
- public void setAttach(String attach) {
- this.attach = attach;
+ public String getOut_trade_no() {
+ return this.out_trade_no;
}
- public void setTime_end(String time_end) {
- this.time_end = time_end;
+ public void setOut_trade_no(String out_trade_no) {
+ this.out_trade_no = out_trade_no;
}
- public String getTrade_state_desc() {
- return this.trade_state_desc;
+ public String getAttach() {
+ return this.attach;
}
- public void setTrade_state_desc(String trade_state_desc) {
- this.trade_state_desc = trade_state_desc;
+ public void setAttach(String attach) {
+ this.attach = attach;
}
- public String getCash_fee() {
- return this.cash_fee;
+ public String getTime_end() {
+ return this.time_end;
}
- public void setCash_fee(String cash_fee) {
- this.cash_fee = cash_fee;
+ public void setTime_end(String time_end) {
+ this.time_end = time_end;
}
- public String getCash_fee_type() {
- return this.cash_fee_type;
+ @Override
+ public String toString() {
+ return ToStringUtils.toSimpleString(this);
}
- public void setCash_fee_type(String cash_fee_type) {
- this.cash_fee_type = cash_fee_type;
- }
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxRedpackResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxRedpackResult.java
deleted file mode 100644
index 297e07d7..00000000
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxRedpackResult.java
+++ /dev/null
@@ -1,105 +0,0 @@
-package me.chanjar.weixin.mp.bean.pay;
-
-import java.io.Serializable;
-
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-
-import com.thoughtworks.xstream.annotations.XStreamAlias;
-
-/**
- * 向微信用户个人发现金红包返回结果
- * https://pay.weixin.qq.com/wiki/doc/api/cash_coupon.php?chapter=13_5
- * @author kane
- *
- */
-@XStreamAlias("xml")
-public class WxRedpackResult implements Serializable {
-
- private static final long serialVersionUID = -4837415036337132073L;
-
- @XStreamAlias("return_code")
- private String returnCode;
- @XStreamAlias("return_msg")
- private String returnMsg;
- @XStreamAlias("sign")
- private String sign;
- @XStreamAlias("result_code")
- private String resultCode;
-
- @XStreamAlias("err_code")
- private String errCode;
- @XStreamAlias("err_code_des")
- private String errCodeDes;
- @XStreamAlias("mch_billno")
- private String mchBillno;
- @XStreamAlias("mch_id")
- private String mchId;
- @XStreamAlias("wxappid")
- private String wxappid;
- @XStreamAlias("re_openid")
- private String reOpenid;
- @XStreamAlias("total_amount")
- private int totalAmount;
- @XStreamAlias("send_time")
- private String sendTime;
- @XStreamAlias("send_listid")
- private String sendListid;
-
- public String getErrCode() {
- return this.errCode;
- }
-
- public String getErrCodeDes() {
- return this.errCodeDes;
- }
-
- public String getReturnCode() {
- return this.returnCode;
- }
-
- public String getReturnMsg() {
- return this.returnMsg;
- }
-
- public String getSign() {
- return this.sign;
- }
-
- public String getResultCode() {
- return this.resultCode;
- }
-
- public String getMchBillno() {
- return this.mchBillno;
- }
-
- public String getMchId() {
- return this.mchId;
- }
-
- public String getWxappid() {
- return this.wxappid;
- }
-
- public String getReOpenid() {
- return this.reOpenid;
- }
-
- public int getTotalAmount() {
- return this.totalAmount;
- }
-
- public String getSendTime() {
- return this.sendTime;
- }
-
- public String getSendListid() {
- return this.sendListid;
- }
-
- @Override
- public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
- }
-}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxEntPayQueryRequest.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxEntPayQueryRequest.java
new file mode 100644
index 00000000..5982d3ee
--- /dev/null
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxEntPayQueryRequest.java
@@ -0,0 +1,74 @@
+package me.chanjar.weixin.mp.bean.pay.request;
+
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+import me.chanjar.weixin.common.annotation.Required;
+import me.chanjar.weixin.common.util.ToStringUtils;
+
+/**
+ *
+ * 企业付款请求对象
+ * 注释中各行每个字段描述对应如下:
+ *
字段名
+ * 变量名
+ * 是否必填
+ * 类型
+ * 示例值
+ * 描述
+ *
+ * Created by Binary Wang on 2016/10/19.
+ * @author binarywang (https://github.com/binarywang)
+ */
+@XStreamAlias("xml")
+public class WxEntPayQueryRequest extends WxPayBaseRequest {
+ /**
+ *
+ * 商户号
+ * mch_id
+ * 是
+ * 10000098
+ * String(32)
+ * 微信支付分配的商户号
+ *
+ */
+ @SuppressWarnings("hiding")
+ @XStreamAlias("mchid")
+ private String mchId;
+
+ /**
+ *
+ * 商户订单号
+ * partner_trade_no
+ * 是
+ * 10000098201411111234567890
+ * String
+ * 商户订单号
+ *
+ */
+ @Required
+ @XStreamAlias("partner_trade_no")
+ private String partnerTradeNo;
+
+ @Override
+ public String getMchId() {
+ return this.mchId;
+ }
+
+ @Override
+ public void setMchId(String mchId) {
+ this.mchId = mchId;
+ }
+
+ public String getPartnerTradeNo() {
+ return this.partnerTradeNo;
+ }
+
+ public void setPartnerTradeNo(String partnerTradeNo) {
+ this.partnerTradeNo = partnerTradeNo;
+ }
+
+ @Override
+ public String toString() {
+ return ToStringUtils.toSimpleString(this);
+ }
+
+}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxEntPayRequest.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxEntPayRequest.java
new file mode 100644
index 00000000..ef6e8d0a
--- /dev/null
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxEntPayRequest.java
@@ -0,0 +1,282 @@
+package me.chanjar.weixin.mp.bean.pay.request;
+
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+import me.chanjar.weixin.common.util.ToStringUtils;
+
+/**
+ *
+ * 企业付款请求对象
+ * 注释中各行每个字段描述对应如下:
+ *
字段名
+ * 变量名
+ * 是否必填
+ * 类型
+ * 示例值
+ * 描述
+ *
+ * Created by Binary Wang on 2016/10/02.
+ * @author binarywang (https://github.com/binarywang)
+ */
+@XStreamAlias("xml")
+public class WxEntPayRequest {
+ /**
+ *
+ * 公众账号appid
+ * mch_appid
+ * 是
+ * wx8888888888888888
+ * String
+ * 微信分配的公众账号ID(企业号corpid即为此appId)
+ *
+ */
+ @XStreamAlias("mch_appid")
+ private String mchAppid;
+
+ /**
+ *
+ * 商户号
+ * mchid
+ * 是
+ * 1900000109
+ * String(32)
+ * 微信支付分配的商户号
+ *
+ */
+ @XStreamAlias("mchid")
+ private String mchId;
+
+ /**
+ *
+ * 设备号
+ * device_info
+ * 否
+ * 13467007045764
+ * String(32)
+ *微信支付分配的终端设备号
+ *
+ */
+ @XStreamAlias("device_info")
+ private String deviceInfo;
+
+ /**
+ *
+ * 随机字符串
+ * nonce_str
+ *是
+ *5K8264ILTKCH16CQ2502SI8ZNMTM67VS
+ *String(32)
+ *随机字符串,不长于32位
+ *
+ */
+ @XStreamAlias("nonce_str")
+ private String nonceStr;
+
+ /**
+ *
+ * 签名
+ * sign
+ * 是
+ * C380BEC2BFD727A4B6845133519F3AD6
+ * String(32)
+ *签名,详见签名算法
+ *
+ */
+ @XStreamAlias("sign")
+ private String sign;
+
+ /**
+ *
+ * 商户订单号
+ * partner_trade_no
+ * 是
+ * 10000098201411111234567890
+ * String
+ * 商户订单号
+ *
+ */
+ @XStreamAlias("partner_trade_no")
+ private String partnerTradeNo;
+
+ /**
+ *
+ * 需保持唯一性 用户openid
+ * openid
+ * 是
+ * oxTWIuGaIt6gTKsQRLau2M0yL16E
+ * String
+ * 商户appid下,某用户的openid
+ *
+ */
+ @XStreamAlias("openid")
+ private String openid;
+
+ /**
+ *
+ * 校验用户姓名选项
+ * check_name
+ * 是
+ * OPTION_CHECK
+ * String
+ * NO_CHECK:不校验真实姓名
+ * FORCE_CHECK:强校验真实姓名(未实名认证的用户会校验失败,无法转账)
+ * OPTION_CHECK:针对已实名认证的用户才校验真实姓名(未实名认证用户不校验,可以转账成功)
+ *
+ */
+ @XStreamAlias("check_name")
+ private String checkName;
+
+ /**
+ *
+ * 收款用户姓名
+ * re_user_name
+ * 可选
+ * 马花花
+ * String
+ * 收款用户真实姓名。
+ * 如果check_name设置为FORCE_CHECK或OPTION_CHECK, 则必填用户真实姓名
+ *
+ */
+ @XStreamAlias("re_user_name")
+ private String reUserName;
+
+ /**
+ *
+ * 金额
+ * amount
+ * 是
+ * 10099
+ * int
+ * 企业付款金额, 单位为分
+ *
+ */
+ @XStreamAlias("amount")
+ private Integer amount;
+
+ /**
+ *
+ * 企业付款描述信息
+ * desc
+ * 是
+ * 理赔
+ * String
+ * 企业付款操作说明信息。必填。
+ *
+ */
+ @XStreamAlias("desc")
+ private String description;
+
+ /**
+ *
+ * Ip地址
+ * spbill_create_ip
+ * 是
+ * 192.168.0.1
+ * String(32)
+ * 调用接口的机器Ip地址
+ *
+ */
+ @XStreamAlias("spbill_create_ip")
+ private String spbillCreateIp;
+
+ public String getMchAppid() {
+ return this.mchAppid;
+ }
+
+ public void setMchAppid(String mchAppid) {
+ this.mchAppid = mchAppid;
+ }
+
+ public String getMchId() {
+ return this.mchId;
+ }
+
+ public void setMchId(String mchId) {
+ this.mchId = mchId;
+ }
+
+ public String getDeviceInfo() {
+ return this.deviceInfo;
+ }
+
+ public void setDeviceInfo(String deviceInfo) {
+ this.deviceInfo = deviceInfo;
+ }
+
+ public String getNonceStr() {
+ return this.nonceStr;
+ }
+
+ public void setNonceStr(String nonceStr) {
+ this.nonceStr = nonceStr;
+ }
+
+ public String getSign() {
+ return this.sign;
+ }
+
+ public void setSign(String sign) {
+ this.sign = sign;
+ }
+
+ public String getPartnerTradeNo() {
+ return this.partnerTradeNo;
+ }
+
+ public void setPartnerTradeNo(String partnerTradeNo) {
+ this.partnerTradeNo = partnerTradeNo;
+ }
+
+ public String getOpenid() {
+ return this.openid;
+ }
+
+ public void setOpenid(String openid) {
+ this.openid = openid;
+ }
+
+ public String getCheckName() {
+ return this.checkName;
+ }
+
+ public void setCheckName(String checkName) {
+ this.checkName = checkName;
+ }
+
+ public String getReUserName() {
+ return this.reUserName;
+ }
+
+ public void setReUserName(String reUserName) {
+ this.reUserName = reUserName;
+ }
+
+ public Integer getAmount() {
+ return this.amount;
+ }
+
+ public void setAmount(Integer amount) {
+ this.amount = amount;
+ }
+
+ public String getDescription() {
+ return this.description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getSpbillCreateIp() {
+ return this.spbillCreateIp;
+ }
+
+ public void setSpbillCreateIp(String spbillCreateIp) {
+ this.spbillCreateIp = spbillCreateIp;
+ }
+
+ @Override
+ public String toString() {
+ return ToStringUtils.toSimpleString(this);
+ }
+
+}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayBaseRequest.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayBaseRequest.java
new file mode 100644
index 00000000..341c3b2e
--- /dev/null
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayBaseRequest.java
@@ -0,0 +1,106 @@
+package me.chanjar.weixin.mp.bean.pay.request;
+
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+import me.chanjar.weixin.common.util.ToStringUtils;
+
+/**
+ *
+ * Created by Binary Wang on 2016-10-24.
+ * 微信支付请求对象共用的参数存放类
+ * 注释中各行每个字段描述对应如下:
+ *
字段名
+ * 变量名
+ * 是否必填
+ * 类型
+ * 示例值
+ * 描述
+ *
+ * @author binarywang(Binary Wang)
+ */
+public abstract class WxPayBaseRequest {
+ /**
+ *
+ * 公众账号ID
+ * appid
+ * 是
+ * String(32)
+ * wxd678efh567hg6787
+ * 微信分配的公众账号ID(企业号corpid即为此appId)
+ *
+ */
+ @XStreamAlias("appid")
+ protected String appid;
+ /**
+ *
+ * 商户号
+ * mch_id
+ * 是
+ * String(32)
+ * 1230000109
+ * 微信支付分配的商户号
+ *
+ */
+ @XStreamAlias("mch_id")
+ protected String mchId;
+ /**
+ *
+ * 随机字符串
+ * nonce_str
+ * 是
+ * String(32)
+ * 5K8264ILTKCH16CQ2502SI8ZNMTM67VS
+ * 随机字符串,不长于32位。推荐随机数生成算法
+ *
+ */
+ @XStreamAlias("nonce_str")
+ protected String nonceStr;
+ /**
+ *
+ * 签名
+ * sign
+ * 是
+ * String(32)
+ * C380BEC2BFD727A4B6845133519F3AD6
+ * 签名,详见签名生成算法
+ *
+ */
+ @XStreamAlias("sign")
+ protected String sign;
+
+ public String getAppid() {
+ return this.appid;
+ }
+
+ public void setAppid(String appid) {
+ this.appid = appid;
+ }
+
+ public String getMchId() {
+ return this.mchId;
+ }
+
+ public void setMchId(String mchId) {
+ this.mchId = mchId;
+ }
+
+ public String getNonceStr() {
+ return this.nonceStr;
+ }
+
+ public void setNonceStr(String nonceStr) {
+ this.nonceStr = nonceStr;
+ }
+
+ public String getSign() {
+ return this.sign;
+ }
+
+ public void setSign(String sign) {
+ this.sign = sign;
+ }
+
+ @Override
+ public String toString() {
+ return ToStringUtils.toSimpleString(this);
+ }
+}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayOrderCloseRequest.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayOrderCloseRequest.java
new file mode 100644
index 00000000..8f26750f
--- /dev/null
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayOrderCloseRequest.java
@@ -0,0 +1,36 @@
+package me.chanjar.weixin.mp.bean.pay.request;
+
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+
+/**
+ *
+ * 关闭订单请求对象类
+ * Created by Binary Wang on 2016-10-27.
+ * @author binarywang(Binary Wang)
+ *
+ */
+@XStreamAlias("xml")
+public class WxPayOrderCloseRequest extends WxPayBaseRequest{
+
+ /**
+ *
+ * 商户订单号
+ * out_trade_no
+ * 二选一
+ * String(32)
+ * 20150806125346
+ * 商户系统内部的订单号,当没提供transaction_id时需要传这个。
+ *
+ */
+ @XStreamAlias("out_trade_no")
+ private String outTradeNo;
+
+ public String getOutTradeNo() {
+ return this.outTradeNo;
+ }
+
+ public void setOutTradeNo(String outTradeNo) {
+ this.outTradeNo = outTradeNo;
+ }
+
+}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayOrderQueryRequest.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayOrderQueryRequest.java
new file mode 100644
index 00000000..3cc7dd2b
--- /dev/null
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayOrderQueryRequest.java
@@ -0,0 +1,63 @@
+package me.chanjar.weixin.mp.bean.pay.request;
+
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+
+/**
+ *
+ * 订单查询请求对象
+ * Created by Binary Wang on 2016-10-24.
+ * 注释中各行每个字段描述对应如下:
+ *
字段名
+ * 变量名
+ * 是否必填
+ * 类型
+ * 示例值
+ * 描述
+ *
+ * @author binarywang(Binary Wang)
+ */
+@XStreamAlias("xml")
+public class WxPayOrderQueryRequest extends WxPayBaseRequest {
+
+ /**
+ *
+ * 微信订单号
+ * transaction_id
+ * 二选一
+ * String(32)
+ * 1009660380201506130728806387
+ * 微信的订单号,优先使用
+ *
+ */
+ @XStreamAlias("transaction_id")
+ private String transactionId;
+
+ /**
+ *
+ * 商户订单号
+ * out_trade_no
+ * 二选一
+ * String(32)
+ * 20150806125346
+ * 商户系统内部的订单号,当没提供transaction_id时需要传这个。
+ *
+ */
+ @XStreamAlias("out_trade_no")
+ private String outTradeNo;
+
+ public String getTransactionId() {
+ return this.transactionId;
+ }
+
+ public void setTransactionId(String transactionId) {
+ this.transactionId = transactionId;
+ }
+
+ public String getOutTradeNo() {
+ return this.outTradeNo;
+ }
+
+ public void setOutTradeNo(String outTradeNo) {
+ this.outTradeNo = outTradeNo;
+ }
+}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayRefundRequest.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayRefundRequest.java
new file mode 100644
index 00000000..9a0c0178
--- /dev/null
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayRefundRequest.java
@@ -0,0 +1,302 @@
+package me.chanjar.weixin.mp.bean.pay.request;
+
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+
+import me.chanjar.weixin.common.annotation.Required;
+
+/**
+ *
+ * 微信支付-申请退款请求参数
+ * 注释中各行每个字段描述对应如下:
+ *
字段名
+ * 变量名
+ * 是否必填
+ * 类型
+ * 示例值
+ * 描述
+ *
+ *
+ * @author binarywang(Binary Wang)
+ * Created by Binary Wang on 2016-10-08.
+ */
+@XStreamAlias("xml")
+public class WxPayRefundRequest {
+ /**
+ *
+ * 公众账号ID
+ * appid
+ * 是
+ * String(32)
+ * wx8888888888888888
+ * 微信分配的公众账号ID(企业号corpid即为此appId)
+ *
+ */
+ @XStreamAlias("appid")
+ private String appid;
+
+ /**
+ *
+ * 商户号
+ * mch_id
+ * 是
+ * String(32)
+ * 1900000109
+ * 微信支付分配的商户号
+ *
+ */
+ @XStreamAlias("mch_id")
+ private String mchId;
+
+ /**
+ *
+ * 设备号
+ * device_info
+ * 否
+ * String(32)
+ * 13467007045764
+ * 终端设备号
+ *
+ */
+ @XStreamAlias("device_info")
+ private String deviceInfo;
+
+ /**
+ *
+ * 随机字符串
+ * nonce_str
+ * 是
+ * String(32)
+ * 5K8264ILTKCH16CQ2502SI8ZNMTM67VS
+ * 随机字符串,不长于32位。推荐随机数生成算法
+ *
+ */
+ @XStreamAlias("nonce_str")
+ private String nonceStr;
+
+ /**
+ *
+ * 签名
+ * sign
+ * 是
+ * String(32)
+ * C380BEC2BFD727A4B6845133519F3AD6
+ * 签名,详见签名生成算法
+ *
+ */
+ @XStreamAlias("sign")
+ private String sign;
+
+ /**
+ *
+ * 微信订单号
+ * transaction_id
+ * 跟out_trade_no二选一
+ * String(28)
+ * 1217752501201400000000000000
+ * 微信生成的订单号,在支付通知中有返回
+ *
+ */
+ @XStreamAlias("transaction_id")
+ private String transactionId;
+
+ /**
+ *
+ * 商户订单号
+ * out_trade_no
+ * 跟transaction_id二选一
+ * String(32)
+ * 1217752501201400000000000000
+ * 商户侧传给微信的订单号
+ *
+ */
+ @XStreamAlias("out_trade_no")
+ private String outTradeNo;
+
+ /**
+ *
+ * 商户退款单号
+ * out_refund_no
+ * 是
+ * String(32)
+ * 1217752501201400000000000000
+ * 商户系统内部的退款单号,商户系统内部唯一,同一退款单号多次请求只退一笔
+ *
+ */
+ @Required
+ @XStreamAlias("out_refund_no")
+ private String outRefundNo;
+
+ /**
+ *
+ * 订单金额
+ * total_fee
+ * 是
+ * Int
+ * 100
+ * 订单总金额,单位为分,只能为整数,详见支付金额
+ *
+ */
+ @Required
+ @XStreamAlias("total_fee")
+ private Integer totalFee;
+
+ /**
+ *
+ * 退款金额
+ * refund_fee
+ * 是
+ * Int
+ * 100
+ * 退款总金额,订单总金额,单位为分,只能为整数,详见支付金额
+ *
+ */
+ @Required
+ @XStreamAlias("refund_fee")
+ private Integer refundFee;
+
+ /**
+ *
+ * 货币种类
+ * refund_fee_type
+ * 否
+ * String(8)
+ * CNY
+ * 货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型
+ *
+ */
+ @XStreamAlias("refund_fee_type")
+ private String refundFeeType;
+
+ /**
+ *
+ * 操作员
+ * op_user_id
+ * 是
+ * String(32)
+ * 1900000109
+ * 操作员帐号, 默认为商户号
+ *
+ */
+ //@Required
+ @XStreamAlias("op_user_id")
+ private String opUserId;
+
+ /**
+ *
+ * 退款资金来源
+ * refund_account
+ * 否
+ * String(30)
+ * REFUND_SOURCE_RECHARGE_FUNDS
+ * 仅针对老资金流商户使用,
+ *
REFUND_SOURCE_UNSETTLED_FUNDS---未结算资金退款(默认使用未结算资金退款),
+ * REFUND_SOURCE_RECHARGE_FUNDS---可用余额退款
+ *
+ */
+ @XStreamAlias("refund_account")
+ private String refundAccount;
+
+ public String getAppid() {
+ return this.appid;
+ }
+
+ public void setAppid(String appid) {
+ this.appid = appid;
+ }
+
+ public String getMchId() {
+ return this.mchId;
+ }
+
+ public void setMchId(String mchId) {
+ this.mchId = mchId;
+ }
+
+ public String getDeviceInfo() {
+ return this.deviceInfo;
+ }
+
+ public void setDeviceInfo(String deviceInfo) {
+ this.deviceInfo = deviceInfo;
+ }
+
+ public String getNonceStr() {
+ return this.nonceStr;
+ }
+
+ public void setNonceStr(String nonceStr) {
+ this.nonceStr = nonceStr;
+ }
+
+ public String getSign() {
+ return this.sign;
+ }
+
+ public void setSign(String sign) {
+ this.sign = sign;
+ }
+
+ public String getTransactionId() {
+ return this.transactionId;
+ }
+
+ public void setTransactionId(String transactionId) {
+ this.transactionId = transactionId;
+ }
+
+ public String getOutTradeNo() {
+ return this.outTradeNo;
+ }
+
+ public void setOutTradeNo(String outTradeNo) {
+ this.outTradeNo = outTradeNo;
+ }
+
+ public String getOutRefundNo() {
+ return this.outRefundNo;
+ }
+
+ public void setOutRefundNo(String outRefundNo) {
+ this.outRefundNo = outRefundNo;
+ }
+
+ public Integer getTotalFee() {
+ return this.totalFee;
+ }
+
+ public void setTotalFee(Integer totalFee) {
+ this.totalFee = totalFee;
+ }
+
+ public Integer getRefundFee() {
+ return this.refundFee;
+ }
+
+ public void setRefundFee(Integer refundFee) {
+ this.refundFee = refundFee;
+ }
+
+ public String getRefundFeeType() {
+ return this.refundFeeType;
+ }
+
+ public void setRefundFeeType(String refundFeeType) {
+ this.refundFeeType = refundFeeType;
+ }
+
+ public String getOpUserId() {
+ return this.opUserId;
+ }
+
+ public void setOpUserId(String opUserId) {
+ this.opUserId = opUserId;
+ }
+
+ public String getRefundAccount() {
+ return this.refundAccount;
+ }
+
+ public void setRefundAccount(String refundAccount) {
+ this.refundAccount = refundAccount;
+ }
+}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxSendRedpackRequest.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPaySendRedpackRequest.java
similarity index 96%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxSendRedpackRequest.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPaySendRedpackRequest.java
index abe0d68f..cad2cc52 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxSendRedpackRequest.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPaySendRedpackRequest.java
@@ -1,4 +1,4 @@
-package me.chanjar.weixin.mp.bean.pay;
+package me.chanjar.weixin.mp.bean.pay.request;
import com.thoughtworks.xstream.annotations.XStreamAlias;
@@ -8,7 +8,7 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
* @author binarywang (https://github.com/binarywang)
*/
@XStreamAlias("xml")
-public class WxSendRedpackRequest {
+public class WxPaySendRedpackRequest {
/**
* mch_billno
* 商户订单号(每个订单号必须唯一) 组成:mch_id+yyyymmdd+10位一天内不能重复的数字。 接口根据商户订单号支持重入,如出现超时可再调用。
@@ -18,7 +18,7 @@ public class WxSendRedpackRequest {
/**
* send_name
- * 商户名称
+ * 商户名称
* 红包发送者名称
*/
@XStreamAlias("send_name")
@@ -117,7 +117,7 @@ public class WxSendRedpackRequest {
* 场景id
* PRODUCT_1:商品促销
* PRODUCT_2:抽奖
- * PRODUCT_3:虚拟物品兑奖
+ * PRODUCT_3:虚拟物品兑奖
* PRODUCT_4:企业内部福利
* PRODUCT_5:渠道分润
* PRODUCT_6:保险回馈
@@ -135,7 +135,7 @@ public class WxSendRedpackRequest {
* 活动信息
* posttime:用户操作的时间戳
* mobile:业务系统账号的手机号,国家代码-手机号。不需要+号
- * deviceid :mac 地址或者设备唯一标识
+ * deviceid :mac 地址或者设备唯一标识
* clientversion :用户操作的客户端版本
* 把值为非空的信息用key=value进行拼接,再进行urlencode
* urlencode(posttime=xx&mobile=xx&deviceid=xx)
@@ -150,7 +150,7 @@ public class WxSendRedpackRequest {
* consume_mch_id
* 资金授权商户号
* 资金授权商户号
- * 服务商替特约商户发放时使用
+ * 服务商替特约商户发放时使用
* 非必填字段
*
*/
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxUnifiedOrderRequest.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayUnifiedOrderRequest.java
similarity index 87%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxUnifiedOrderRequest.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayUnifiedOrderRequest.java
index ccdfff90..195e13b0 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxUnifiedOrderRequest.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/request/WxPayUnifiedOrderRequest.java
@@ -1,7 +1,4 @@
-package me.chanjar.weixin.mp.bean.pay;
-
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
+package me.chanjar.weixin.mp.bean.pay.request;
import com.thoughtworks.xstream.annotations.XStreamAlias;
@@ -11,7 +8,7 @@ import me.chanjar.weixin.common.annotation.Required;
*
* 统一下单请求参数对象
* 参考文档:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1
- * 每个字段描述对应如下:
+ * 注释中各行每个字段描述对应如下:
*
字段名
* 变量名
* 是否必填
@@ -23,33 +20,7 @@ import me.chanjar.weixin.common.annotation.Required;
* @author binarywang (https://github.com/binarywang)
*/
@XStreamAlias("xml")
-public class WxUnifiedOrderRequest {
-
- /**
- *
- * 公众账号ID
- * appid
- * 是
- * String(32)
- * wxd678efh567hg6787
- * 微信分配的公众账号ID(企业号corpid即为此appId)
- *
- */
- @XStreamAlias("appid")
- private String appid;
-
- /**
- *
- * 商户号
- * mch_id
- * 是
- * String(32)
- * 1230000109
- * 微信支付分配的商户号
- *
- */
- @XStreamAlias("mch_id")
- private String mchId;
+public class WxPayUnifiedOrderRequest extends WxPayBaseRequest {
/**
*
@@ -64,32 +35,6 @@ public class WxUnifiedOrderRequest {
@XStreamAlias("device_info")
private String deviceInfo;
- /**
- *
- * 随机字符串
- * nonce_str
- * 是
- * String(32)
- * 5K8264ILTKCH16CQ2502SI8ZNMTM67VS
- * 随机字符串,不长于32位。推荐随机数生成算法
- *
- */
- @XStreamAlias("nonce_str")
- private String nonceStr;
-
- /**
- *
- * 签名
- * sign
- * 是
- * String(32)
- * C380BEC2BFD727A4B6845133519F3AD6
- * 签名,详见签名生成算法
- *
- */
- @XStreamAlias("sign")
- private String sign;
-
/**
*
* 商品描述
@@ -322,21 +267,6 @@ public class WxUnifiedOrderRequest {
@XStreamAlias("openid")
private String openid;
- public String getAppid() {
- return this.appid;
- }
-
- public void setAppid(String appid) {
- this.appid = appid;
- }
-
- public String getMchId() {
- return this.mchId;
- }
-
- public void setMchId(String mchId) {
- this.mchId = mchId;
- }
public String getDeviceInfo() {
return this.deviceInfo;
@@ -346,22 +276,6 @@ public class WxUnifiedOrderRequest {
this.deviceInfo = deviceInfo;
}
- public String getNonceStr() {
- return this.nonceStr;
- }
-
- public void setNonceStr(String nonceStr) {
- this.nonceStr = nonceStr;
- }
-
- public String getSign() {
- return this.sign;
- }
-
- public void setSign(String sign) {
- this.sign = sign;
- }
-
public String getBody() {
return this.body;
}
@@ -482,11 +396,6 @@ public class WxUnifiedOrderRequest {
this.openid = openid;
}
- @Override
- public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
- }
-
public static WxUnifiedOrderRequestBuilder builder() {
return new WxUnifiedOrderRequestBuilder();
}
@@ -613,7 +522,7 @@ public class WxUnifiedOrderRequest {
return this;
}
- public WxUnifiedOrderRequestBuilder from(WxUnifiedOrderRequest origin) {
+ public WxUnifiedOrderRequestBuilder from(WxPayUnifiedOrderRequest origin) {
this.appid(origin.appid);
this.mchId(origin.mchId);
this.deviceInfo(origin.deviceInfo);
@@ -637,8 +546,8 @@ public class WxUnifiedOrderRequest {
return this;
}
- public WxUnifiedOrderRequest build() {
- WxUnifiedOrderRequest m = new WxUnifiedOrderRequest();
+ public WxPayUnifiedOrderRequest build() {
+ WxPayUnifiedOrderRequest m = new WxPayUnifiedOrderRequest();
m.appid = this.appid;
m.mchId = this.mchId;
m.deviceInfo = this.deviceInfo;
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxEntPayQueryResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxEntPayQueryResult.java
new file mode 100644
index 00000000..8ffbeff2
--- /dev/null
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxEntPayQueryResult.java
@@ -0,0 +1,138 @@
+package me.chanjar.weixin.mp.bean.pay.result;
+
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+
+/**
+ * 企业付款查询返回结果
+ * Created by Binary Wang on 2016/10/19.
+ * @author binarywang (https://github.com/binarywang)
+ */
+@XStreamAlias("xml")
+public class WxEntPayQueryResult extends WxPayBaseResult {
+
+ /**
+ * 商户订单号
+ */
+ @XStreamAlias("partner_trade_no")
+ private String partnerTradeNo;
+
+ /**
+ * 付款单号
+ */
+ @XStreamAlias("detail_id")
+ private String detailId;
+
+ /**
+ * 转账状态
+ */
+ @XStreamAlias("status")
+ private String status;
+
+ /**
+ * 失败原因
+ */
+ @XStreamAlias("reason")
+ private String reason;
+
+ /**
+ * 收款用户openid
+ */
+ @XStreamAlias("openid")
+ private String openid;
+
+ /**
+ * 收款用户姓名
+ */
+ @XStreamAlias("transfer_name")
+ private String transferName;
+
+ /**
+ * 付款金额
+ */
+ @XStreamAlias("payment_amount")
+ private Integer paymentAmount;
+
+ /**
+ * 转账时间
+ */
+ @XStreamAlias("transfer_time")
+ private String transferTime;
+
+ /**
+ * 付款描述
+ */
+ @XStreamAlias("desc")
+ private String desc;
+
+ public String getPartnerTradeNo() {
+ return this.partnerTradeNo;
+ }
+
+ public void setPartnerTradeNo(String partnerTradeNo) {
+ this.partnerTradeNo = partnerTradeNo;
+ }
+
+ public String getDetailId() {
+ return this.detailId;
+ }
+
+ public void setDetailId(String detailId) {
+ this.detailId = detailId;
+ }
+
+ public String getStatus() {
+ return this.status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public String getReason() {
+ return this.reason;
+ }
+
+ public void setReason(String reason) {
+ this.reason = reason;
+ }
+
+ public String getOpenid() {
+ return this.openid;
+ }
+
+ public void setOpenid(String openid) {
+ this.openid = openid;
+ }
+
+ public String getTransferName() {
+ return this.transferName;
+ }
+
+ public void setTransferName(String transferName) {
+ this.transferName = transferName;
+ }
+
+ public Integer getPaymentAmount() {
+ return this.paymentAmount;
+ }
+
+ public void setPaymentAmount(Integer paymentAmount) {
+ this.paymentAmount = paymentAmount;
+ }
+
+ public String getTransferTime() {
+ return this.transferTime;
+ }
+
+ public void setTransferTime(String transferTime) {
+ this.transferTime = transferTime;
+ }
+
+ public String getDesc() {
+ return this.desc;
+ }
+
+ public void setDesc(String desc) {
+ this.desc = desc;
+ }
+}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxEntPayResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxEntPayResult.java
new file mode 100644
index 00000000..5a8c4b75
--- /dev/null
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxEntPayResult.java
@@ -0,0 +1,83 @@
+package me.chanjar.weixin.mp.bean.pay.result;
+
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+
+/**
+ * 企业付款返回结果
+ * Created by Binary Wang on 2016/10/02.
+ * @author binarywang (https://github.com/binarywang)
+ */
+@XStreamAlias("xml")
+public class WxEntPayResult extends WxPayBaseResult {
+
+ /**
+ * 商户appid
+ */
+ @XStreamAlias("mch_appid")
+ private String mchAppid;
+
+ /**
+ * 设备号
+ */
+ @XStreamAlias("device_info")
+ private String deviceInfo;
+
+ //############以下字段在return_code 和result_code都为SUCCESS的时候有返回##############
+ /**
+ * 商户订单号
+ */
+ @XStreamAlias("partner_trade_no")
+ private String partnerTradeNo;
+
+ /**
+ * 微信订单号
+ */
+ @XStreamAlias("payment_no")
+ private String paymentNo;
+
+ /**
+ * 微信支付成功时间
+ */
+ @XStreamAlias("payment_time")
+ private String paymentTime;
+
+ public String getMchAppid() {
+ return this.mchAppid;
+ }
+
+ public void setMchAppid(String mchAppid) {
+ this.mchAppid = mchAppid;
+ }
+
+ public String getDeviceInfo() {
+ return this.deviceInfo;
+ }
+
+ public void setDeviceInfo(String deviceInfo) {
+ this.deviceInfo = deviceInfo;
+ }
+
+ public String getPartnerTradeNo() {
+ return this.partnerTradeNo;
+ }
+
+ public void setPartnerTradeNo(String partnerTradeNo) {
+ this.partnerTradeNo = partnerTradeNo;
+ }
+
+ public String getPaymentNo() {
+ return this.paymentNo;
+ }
+
+ public void setPaymentNo(String paymentNo) {
+ this.paymentNo = paymentNo;
+ }
+
+ public String getPaymentTime() {
+ return this.paymentTime;
+ }
+
+ public void setPaymentTime(String paymentTime) {
+ this.paymentTime = paymentTime;
+ }
+}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxUnifiedOrderResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java
similarity index 61%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxUnifiedOrderResult.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java
index 18817461..64310138 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxUnifiedOrderResult.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayBaseResult.java
@@ -1,57 +1,75 @@
-package me.chanjar.weixin.mp.bean.pay;
-
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
+package me.chanjar.weixin.mp.bean.pay.result;
import com.thoughtworks.xstream.annotations.XStreamAlias;
+import me.chanjar.weixin.common.util.ToStringUtils;
/**
*
- * 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识"返回的结果
- * 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1)
+ * 微信支付结果共用属性类
+ * Created by Binary Wang on 2016-10-24.
+ * @author binarywang(Binary Wang)
*
- *
- * @author chanjarster
*/
-@XStreamAlias("xml")
-public class WxUnifiedOrderResult {
+public abstract class WxPayBaseResult {
+ @Override
+ public String toString() {
+ return ToStringUtils.toSimpleString(this);
+ }
+ /**
+ * 返回状态码
+ */
@XStreamAlias("return_code")
- private String returnCode;
+ protected String returnCode;
+ /**
+ * 返回信息
+ */
@XStreamAlias("return_msg")
- private String returnMsg;
+ protected String returnMsg;
+
+ /**
+ * 业务结果
+ */
+ @XStreamAlias("result_code")
+ private String resultCode;
+
+ /**
+ * 错误代码
+ */
+ @XStreamAlias("err_code")
+ private String errCode;
+ /**
+ * 错误代码描述
+ */
+ @XStreamAlias("err_code_des")
+ private String errCodeDes;
+
+ /**
+ * 公众账号ID
+ */
@XStreamAlias("appid")
private String appid;
+ /**
+ * 商户号
+ */
@XStreamAlias("mch_id")
private String mchId;
+ /**
+ * 随机字符串
+ */
@XStreamAlias("nonce_str")
private String nonceStr;
+ /**
+ * 签名
+ */
@XStreamAlias("sign")
private String sign;
- @XStreamAlias("result_code")
- private String resultCode;
-
- @XStreamAlias("prepay_id")
- private String prepayId;
-
- @XStreamAlias("trade_type")
- private String tradeType;
-
- @XStreamAlias("err_code")
- private String errCode;
-
- @XStreamAlias("err_code_des")
- private String errCodeDes;
-
- @XStreamAlias("code_url")
- private String codeURL;
-
public String getReturnCode() {
return this.returnCode;
}
@@ -68,6 +86,30 @@ public class WxUnifiedOrderResult {
this.returnMsg = returnMsg;
}
+ public String getResultCode() {
+ return this.resultCode;
+ }
+
+ public void setResultCode(String resultCode) {
+ this.resultCode = resultCode;
+ }
+
+ public String getErrCode() {
+ return this.errCode;
+ }
+
+ public void setErrCode(String errCode) {
+ this.errCode = errCode;
+ }
+
+ public String getErrCodeDes() {
+ return this.errCodeDes;
+ }
+
+ public void setErrCodeDes(String errCodeDes) {
+ this.errCodeDes = errCodeDes;
+ }
+
public String getAppid() {
return this.appid;
}
@@ -99,57 +141,4 @@ public class WxUnifiedOrderResult {
public void setSign(String sign) {
this.sign = sign;
}
-
- public String getResultCode() {
- return this.resultCode;
- }
-
- public void setResultCode(String resultCode) {
- this.resultCode = resultCode;
- }
-
- public String getPrepayId() {
- return this.prepayId;
- }
-
- public void setPrepayId(String prepayId) {
- this.prepayId = prepayId;
- }
-
- public String getTradeType() {
- return this.tradeType;
- }
-
- public void setTradeType(String tradeType) {
- this.tradeType = tradeType;
- }
-
- public String getErrCode() {
- return this.errCode;
- }
-
- public void setErrCode(String errCode) {
- this.errCode = errCode;
- }
-
- public String getErrCodeDes() {
- return this.errCodeDes;
- }
-
- public void setErrCodeDes(String errCodeDes) {
- this.errCodeDes = errCodeDes;
- }
-
- public String getCodeURL() {
- return this.codeURL;
- }
-
- public void setCodeURL(String codeURL) {
- this.codeURL = codeURL;
- }
-
- @Override
- public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
- }
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderCloseResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderCloseResult.java
new file mode 100644
index 00000000..ccfa07bf
--- /dev/null
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderCloseResult.java
@@ -0,0 +1,28 @@
+package me.chanjar.weixin.mp.bean.pay.result;
+
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+
+/**
+ *
+ * 关闭订单结果对象类
+ * Created by Binary Wang on 2016-10-27.
+ * @author binarywang(Binary Wang)
+ *
+ */
+@XStreamAlias("xml")
+public class WxPayOrderCloseResult extends WxPayBaseResult {
+
+ /**
+ * 业务结果描述
+ */
+ @XStreamAlias("result_msg")
+ private String resultMsg;
+
+ public String getResultMsg() {
+ return this.resultMsg;
+ }
+
+ public void setResultMsg(String resultMsg) {
+ this.resultMsg = resultMsg;
+ }
+}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResult.java
new file mode 100644
index 00000000..17b3a412
--- /dev/null
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayOrderQueryResult.java
@@ -0,0 +1,469 @@
+package me.chanjar.weixin.mp.bean.pay.result;
+
+import java.util.List;
+
+import com.google.common.collect.Lists;
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+
+/**
+ *
+ * 查询订单 返回结果对象
+ * Created by Binary Wang on 2016-10-24.
+ * 注释中各行每个字段描述对应如下:
+ *
字段名
+ * 变量名
+ * 是否必填
+ * 类型
+ * 示例值
+ * 描述
+ *
+ * @author binarywang(Binary Wang)
+ */
+@XStreamAlias("xml")
+public class WxPayOrderQueryResult extends WxPayBaseResult {
+
+ /**
+ * 设备号
+ * device_info
+ * 否
+ * String(32)
+ * 013467007045764
+ * 微信支付分配的终端设备号,
+ *
+ */
+ @XStreamAlias("device_info")
+ private String deviceInfo;
+
+ /**
+ * 用户标识
+ * openid
+ * 是
+ * String(128)
+ * oUpF8uMuAJO_M2pxb1Q9zNjWeS6o
+ * 用户在商户appid下的唯一标识
+ *
+ */
+ @XStreamAlias("openid")
+ private String openid;
+
+ /**
+ * 是否关注公众账号
+ * is_subscribe
+ * 否
+ * String(1)
+ * Y
+ * 用户是否关注公众账号,Y-关注,N-未关注,仅在公众账号类型支付有效
+ *
+ */
+ @XStreamAlias("is_subscribe")
+ private String isSubscribe;
+
+ /**
+ * 交易类型
+ * trade_type
+ * 是
+ * String(16)
+ * JSAPI
+ * 调用接口提交的交易类型,取值如下:JSAPI,NATIVE,APP,MICROPAY,详细说明见参数规定
+ *
+ */
+ @XStreamAlias("trade_type")
+ private String tradeType;
+
+ /**
+ * 交易状态
+ * trade_state
+ * 是
+ * String(32)
+ * SUCCESS
+ * SUCCESS—支付成功,REFUND—转入退款,NOTPAY—未支付,CLOSED—已关闭,REVOKED—已撤销(刷卡支付),USERPAYING--用户支付中,PAYERROR--支付失败(其他原因,如银行返回失败)
+ *
+ */
+ @XStreamAlias("trade_state")
+ private String tradeState;
+
+ /**
+ * 付款银行
+ * bank_type
+ * 是
+ * String(16)
+ * CMC
+ * 银行类型,采用字符串类型的银行标识
+ *
+ */
+ @XStreamAlias("bank_type")
+ private String bankType;
+
+ /**
+ * 订单金额
+ * total_fee
+ * 是
+ * Int
+ * 100
+ * 订单总金额,单位为分
+ *
+ */
+ @XStreamAlias("total_fee")
+ private Integer totalFee;
+
+ /**
+ * 应结订单金额
+ * settlement_total_fee
+ * 否
+ * Int
+ * 100
+ * 应结订单金额=订单金额-非充值代金券金额,应结订单金额<=订单金额。
+ *
+ */
+ @XStreamAlias("settlement_total_fee")
+ private Integer settlementTotalFee;
+
+ /**
+ * 货币种类
+ * fee_type
+ * 否
+ * String(8)
+ * CNY
+ * 货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型
+ *
+ */
+ @XStreamAlias("fee_type")
+ private String feeType;
+
+ /**
+ * 现金支付金额
+ * cash_fee
+ * 是
+ * Int
+ * 100
+ * 现金支付金额订单现金支付金额,详见支付金额
+ *
+ */
+ @XStreamAlias("cash_fee")
+ private Integer cashFee;
+
+ /**
+ * 现金支付货币类型
+ * cash_fee_type
+ * 否
+ * String(16)
+ * CNY
+ * 货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型
+ *
+ */
+ @XStreamAlias("cash_fee_type")
+ private String cashFeeType;
+
+ /**
+ * 代金券金额
+ * coupon_fee
+ * 否
+ * Int
+ * 100
+ * “代金券”金额<=订单金额,订单金额-“代金券”金额=现金支付金额,详见支付金额
+ *
+ */
+ @XStreamAlias("coupon_fee")
+ private Integer couponFee;
+
+ /**
+ * 代金券使用数量
+ * coupon_count
+ * 否
+ * Int
+ * 1
+ * 代金券使用数量
+ *
+ */
+ @XStreamAlias("coupon_count")
+ private Integer couponCount;
+
+ private List coupons;
+
+ public static class Coupon {
+ /**
+ * 代金券类型
+ * coupon_type_$n
+ * 否
+ * String
+ * CASH
+ *
CASH--充值代金券
+ * NO_CASH---非充值代金券
+ * 订单使用代金券时有返回(取值:CASH、NO_CASH)。$n为下标,从0开始编号,举例:coupon_type_$0
+ *
+ */
+ private String couponType;
+
+ /**
+ * 代金券ID
+ * coupon_id_$n
+ * 否
+ * String(20)
+ * 10000
+ * 代金券ID, $n为下标,从0开始编号
+ *
+ */
+ private String couponId;
+
+ /**
+ * 单个代金券支付金额
+ * coupon_fee_$n
+ * 否
+ * Int
+ * 100
+ * 单个代金券支付金额, $n为下标,从0开始编号
+ *
+ */
+ private Integer couponFee;
+
+ public Coupon(String couponType, String couponId, Integer couponFee) {
+ this.couponType = couponType;
+ this.couponId = couponId;
+ this.couponFee = couponFee;
+ }
+
+ public String getCouponType() {
+ return this.couponType;
+ }
+
+ public void setCouponType(String couponType) {
+ this.couponType = couponType;
+ }
+
+ public String getCouponId() {
+ return this.couponId;
+ }
+
+ public void setCouponId(String couponId) {
+ this.couponId = couponId;
+ }
+
+ public Integer getCouponFee() {
+ return this.couponFee;
+ }
+
+ public void setCouponFee(Integer couponFee) {
+ this.couponFee = couponFee;
+ }
+
+ }
+
+ /**
+ * 微信支付订单号
+ * transaction_id
+ * 是
+ * String(32)
+ * 1009660380201506130728806387
+ * 微信支付订单号
+ *
+ */
+ @XStreamAlias("transaction_id")
+ private String transactionId;
+
+ /**
+ * 商户订单号
+ * out_trade_no
+ * 是
+ * String(32)
+ * 20150806125346
+ * 商户系统的订单号,与请求一致。
+ *
+ */
+ @XStreamAlias("out_trade_no")
+ private String outTradeNo;
+
+ /**
+ * 附加数据
+ * attach
+ * 否
+ * String(128)
+ * 深圳分店
+ * 附加数据,原样返回
+ *
+ */
+ @XStreamAlias("attach")
+ private String attach;
+
+ /**
+ * 支付完成时间
+ * time_end
+ * 是
+ * String(14)
+ * 20141030133525
+ * 订单支付时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。其他详见时间规则
+ *
+ */
+ @XStreamAlias("time_end")
+ private String timeEnd;
+
+ /**
+ * 交易状态描述
+ * trade_state_desc
+ * 是
+ * String(256)
+ * 支付失败,请重新下单支付
+ * 对当前查询订单状态的描述和下一步操作的指引
+ *
+ */
+ @XStreamAlias("trade_state_desc")
+ private String tradeStateDesc;
+
+ public String getDeviceInfo() {
+ return this.deviceInfo;
+ }
+
+ public void setDeviceInfo(String deviceInfo) {
+ this.deviceInfo = deviceInfo;
+ }
+
+ public String getOpenid() {
+ return this.openid;
+ }
+
+ public void setOpenid(String openid) {
+ this.openid = openid;
+ }
+
+ public String getIsSubscribe() {
+ return this.isSubscribe;
+ }
+
+ public void setIsSubscribe(String isSubscribe) {
+ this.isSubscribe = isSubscribe;
+ }
+
+ public String getTradeType() {
+ return this.tradeType;
+ }
+
+ public void setTradeType(String tradeType) {
+ this.tradeType = tradeType;
+ }
+
+ public String getTradeState() {
+ return this.tradeState;
+ }
+
+ public void setTradeState(String tradeState) {
+ this.tradeState = tradeState;
+ }
+
+ public String getBankType() {
+ return this.bankType;
+ }
+
+ public void setBankType(String bankType) {
+ this.bankType = bankType;
+ }
+
+ public Integer getTotalFee() {
+ return this.totalFee;
+ }
+
+ public void setTotalFee(Integer totalFee) {
+ this.totalFee = totalFee;
+ }
+
+ public Integer getSettlementTotalFee() {
+ return this.settlementTotalFee;
+ }
+
+ public void setSettlementTotalFee(Integer settlementTotalFee) {
+ this.settlementTotalFee = settlementTotalFee;
+ }
+
+ public String getFeeType() {
+ return this.feeType;
+ }
+
+ public void setFeeType(String feeType) {
+ this.feeType = feeType;
+ }
+
+ public Integer getCashFee() {
+ return this.cashFee;
+ }
+
+ public void setCashFee(Integer cashFee) {
+ this.cashFee = cashFee;
+ }
+
+ public String getCashFeeType() {
+ return this.cashFeeType;
+ }
+
+ public void setCashFeeType(String cashFeeType) {
+ this.cashFeeType = cashFeeType;
+ }
+
+ public Integer getCouponFee() {
+ return this.couponFee;
+ }
+
+ public void setCouponFee(Integer couponFee) {
+ this.couponFee = couponFee;
+ }
+
+ public Integer getCouponCount() {
+ return this.couponCount;
+ }
+
+ public void setCouponCount(Integer couponCount) {
+ this.couponCount = couponCount;
+ }
+
+ public List getCoupons() {
+ return this.coupons;
+ }
+
+ public void setCoupons(List coupons) {
+ this.coupons = coupons;
+ }
+
+ public String getTransactionId() {
+ return this.transactionId;
+ }
+
+ public void setTransactionId(String transactionId) {
+ this.transactionId = transactionId;
+ }
+
+ public String getOutTradeNo() {
+ return this.outTradeNo;
+ }
+
+ public void setOutTradeNo(String outTradeNo) {
+ this.outTradeNo = outTradeNo;
+ }
+
+ public String getAttach() {
+ return this.attach;
+ }
+
+ public void setAttach(String attach) {
+ this.attach = attach;
+ }
+
+ public String getTimeEnd() {
+ return this.timeEnd;
+ }
+
+ public void setTimeEnd(String timeEnd) {
+ this.timeEnd = timeEnd;
+ }
+
+ public String getTradeStateDesc() {
+ return this.tradeStateDesc;
+ }
+
+ public void setTradeStateDesc(String tradeStateDesc) {
+ this.tradeStateDesc = tradeStateDesc;
+ }
+
+ public void composeCoupons(String xmlString){
+ if(this.couponCount != null && this.couponCount > 0 ){
+ this.coupons = Lists.newArrayList();
+ //TODO 暂时待实现
+ }
+ }
+}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxMpPayRefundResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundResult.java
similarity index 57%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxMpPayRefundResult.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundResult.java
index 3f917fe0..d00e2db5 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxMpPayRefundResult.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayRefundResult.java
@@ -1,278 +1,173 @@
-package me.chanjar.weixin.mp.bean.pay;
+package me.chanjar.weixin.mp.bean.pay.result;
import java.io.Serializable;
import com.thoughtworks.xstream.annotations.XStreamAlias;
/**
+ *
* 微信支付-申请退款返回结果
* https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4
+ *
* @author liukaitj
*
*/
@XStreamAlias("xml")
-public class WxMpPayRefundResult implements Serializable {
-
+public class WxPayRefundResult extends WxPayBaseResult implements Serializable{
private static final long serialVersionUID = 1L;
- @XStreamAlias("return_code")
- private String returnCode;
-
- @XStreamAlias("return_msg")
- private String returnMsg;
-
- @XStreamAlias("result_code")
- private String resultCode;
-
- @XStreamAlias("err_code")
- private String errCode;
-
- @XStreamAlias("err_code_des")
- private String errCodeDes;
-
- @XStreamAlias("appid")
- private String appid;
-
- @XStreamAlias("mch_id")
- private String mchId;
-
@XStreamAlias("device_info")
private String deviceInfo;
-
- @XStreamAlias("nonce_str")
- private String nonceStr;
-
- @XStreamAlias("sign")
- private String sign;
-
+
@XStreamAlias("transaction_id")
private String transactionId;
-
+
@XStreamAlias("out_trade_no")
private String outTradeNo;
-
+
@XStreamAlias("out_refund_no")
private String outRefundNo;
-
+
@XStreamAlias("refund_id")
private String refundId;
-
+
@XStreamAlias("refund_channel")
private String refundChannel;
-
+
@XStreamAlias("refund_fee")
private String refundFee;
-
+
@XStreamAlias("total_fee")
private String totalFee;
-
+
@XStreamAlias("fee_type")
private String feeType;
-
+
@XStreamAlias("cash_fee")
private String cashFee;
-
+
@XStreamAlias("cash_refund_fee")
- private String cashRefundfee;
-
+ private String cashRefundFee;
+
@XStreamAlias("coupon_refund_fee")
private String couponRefundFee;
-
+
@XStreamAlias("coupon_refund_count")
private String couponRefundCount;
-
+
@XStreamAlias("coupon_refund_id")
private String couponRefundId;
- public String getReturnCode() {
- return this.returnCode;
- }
-
- public void setReturnCode(String returnCode) {
- this.returnCode = returnCode;
- }
-
- public String getReturnMsg() {
- return this.returnMsg;
- }
-
- public void setReturnMsg(String returnMsg) {
- this.returnMsg = returnMsg;
- }
-
- public String getResultCode() {
- return this.resultCode;
- }
-
- public void setResultCode(String resultCode) {
- this.resultCode = resultCode;
- }
-
- public String getErrCode() {
- return this.errCode;
- }
-
- public void setErrCode(String errCode) {
- this.errCode = errCode;
- }
-
- public String getErrCodeDes() {
- return this.errCodeDes;
- }
-
- public void setErrCodeDes(String errCodeDes) {
- this.errCodeDes = errCodeDes;
- }
-
- public String getAppid() {
- return this.appid;
- }
-
- public void setAppid(String appid) {
- this.appid = appid;
- }
-
- public String getMchId() {
- return this.mchId;
- }
-
- public void setMchId(String mchId) {
- this.mchId = mchId;
- }
-
public String getDeviceInfo() {
return this.deviceInfo;
}
-
+
public void setDeviceInfo(String deviceInfo) {
this.deviceInfo = deviceInfo;
}
-
- public String getNonceStr() {
- return this.nonceStr;
- }
-
- public void setNonceStr(String nonceStr) {
- this.nonceStr = nonceStr;
- }
-
- public String getSign() {
- return this.sign;
- }
-
- public void setSign(String sign) {
- this.sign = sign;
- }
-
+
public String getTransactionId() {
return this.transactionId;
}
-
+
public void setTransactionId(String transactionId) {
this.transactionId = transactionId;
}
-
+
public String getOutTradeNo() {
return this.outTradeNo;
}
-
+
public void setOutTradeNo(String outTradeNo) {
this.outTradeNo = outTradeNo;
}
-
+
public String getOutRefundNo() {
return this.outRefundNo;
}
-
+
public void setOutRefundNo(String outRefundNo) {
this.outRefundNo = outRefundNo;
}
-
+
public String getRefundId() {
return this.refundId;
}
-
+
public void setRefundId(String refundId) {
this.refundId = refundId;
}
-
+
public String getRefundChannel() {
return this.refundChannel;
}
-
+
public void setRefundChannel(String refundChannel) {
this.refundChannel = refundChannel;
}
-
+
public String getRefundFee() {
return this.refundFee;
}
-
+
public void setRefundFee(String refundFee) {
this.refundFee = refundFee;
}
-
+
public String getTotalFee() {
return this.totalFee;
}
-
+
public void setTotalFee(String totalFee) {
this.totalFee = totalFee;
}
-
+
public String getFeeType() {
return this.feeType;
}
-
+
public void setFeeType(String feeType) {
this.feeType = feeType;
}
-
+
public String getCashFee() {
return this.cashFee;
}
-
+
public void setCashFee(String cashFee) {
this.cashFee = cashFee;
}
-
- public String getCashRefundfee() {
- return this.cashRefundfee;
+
+ public String getCashRefundFee() {
+ return this.cashRefundFee;
}
-
- public void setCashRefundfee(String cashRefundfee) {
- this.cashRefundfee = cashRefundfee;
+
+ public void setCashRefundFee(String cashRefundFee) {
+ this.cashRefundFee = cashRefundFee;
}
-
+
public String getCouponRefundFee() {
return this.couponRefundFee;
}
-
+
public void setCouponRefundFee(String couponRefundFee) {
this.couponRefundFee = couponRefundFee;
}
-
+
public String getCouponRefundCount() {
return this.couponRefundCount;
}
-
+
public void setCouponRefundCount(String couponRefundCount) {
this.couponRefundCount = couponRefundCount;
}
-
+
public String getCouponRefundId() {
return this.couponRefundId;
}
-
+
public void setCouponRefundId(String couponRefundId) {
this.couponRefundId = couponRefundId;
}
-
- @Override
- public String toString() {
- return "[" +
- "return_code:" + this.returnCode + ";" +
- "return_msg" + this.returnMsg + ";";
- }
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPaySendRedpackResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPaySendRedpackResult.java
new file mode 100644
index 00000000..8fe009bc
--- /dev/null
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPaySendRedpackResult.java
@@ -0,0 +1,82 @@
+package me.chanjar.weixin.mp.bean.pay.result;
+
+import java.io.Serializable;
+
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+
+/**
+ * 向微信用户个人发现金红包返回结果
+ * https://pay.weixin.qq.com/wiki/doc/api/cash_coupon.php?chapter=13_5
+ * @author kane
+ *
+ */
+@XStreamAlias("xml")
+public class WxPaySendRedpackResult extends WxPayBaseResult implements Serializable {
+ private static final long serialVersionUID = -4837415036337132073L;
+
+ @XStreamAlias("mch_billno")
+ private String mchBillno;
+
+ @XStreamAlias("wxappid")
+ private String wxappid;
+
+ @XStreamAlias("re_openid")
+ private String reOpenid;
+
+ @XStreamAlias("total_amount")
+ private int totalAmount;
+
+ @XStreamAlias("send_time")
+ private String sendTime;
+
+ @XStreamAlias("send_listid")
+ private String sendListid;
+
+ public String getMchBillno() {
+ return this.mchBillno;
+ }
+
+ public void setMchBillno(String mchBillno) {
+ this.mchBillno = mchBillno;
+ }
+
+ public String getWxappid() {
+ return this.wxappid;
+ }
+
+ public void setWxappid(String wxappid) {
+ this.wxappid = wxappid;
+ }
+
+ public String getReOpenid() {
+ return this.reOpenid;
+ }
+
+ public void setReOpenid(String reOpenid) {
+ this.reOpenid = reOpenid;
+ }
+
+ public int getTotalAmount() {
+ return this.totalAmount;
+ }
+
+ public void setTotalAmount(int totalAmount) {
+ this.totalAmount = totalAmount;
+ }
+
+ public String getSendTime() {
+ return this.sendTime;
+ }
+
+ public void setSendTime(String sendTime) {
+ this.sendTime = sendTime;
+ }
+
+ public String getSendListid() {
+ return this.sendListid;
+ }
+
+ public void setSendListid(String sendListid) {
+ this.sendListid = sendListid;
+ }
+}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayUnifiedOrderResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayUnifiedOrderResult.java
new file mode 100644
index 00000000..70c13519
--- /dev/null
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/result/WxPayUnifiedOrderResult.java
@@ -0,0 +1,48 @@
+package me.chanjar.weixin.mp.bean.pay.result;
+
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+
+/**
+ *
+ * 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识"返回的结果
+ * 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1)
+ *
+ *
+ * @author chanjarster
+ */
+@XStreamAlias("xml")
+public class WxPayUnifiedOrderResult extends WxPayBaseResult {
+
+ @XStreamAlias("prepay_id")
+ private String prepayId;
+
+ @XStreamAlias("trade_type")
+ private String tradeType;
+
+ @XStreamAlias("code_url")
+ private String codeURL;
+
+ public String getPrepayId() {
+ return this.prepayId;
+ }
+
+ public void setPrepayId(String prepayId) {
+ this.prepayId = prepayId;
+ }
+
+ public String getTradeType() {
+ return this.tradeType;
+ }
+
+ public void setTradeType(String tradeType) {
+ this.tradeType = tradeType;
+ }
+
+ public String getCodeURL() {
+ return this.codeURL;
+ }
+
+ public void setCodeURL(String codeURL) {
+ this.codeURL = codeURL;
+ }
+}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpCardResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpCardResult.java
index 8ce5ca47..b39d2fed 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpCardResult.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpCardResult.java
@@ -1,8 +1,7 @@
package me.chanjar.weixin.mp.bean.result;
+import me.chanjar.weixin.common.util.ToStringUtils;
import me.chanjar.weixin.mp.bean.WxMpCard;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
import java.io.Serializable;
@@ -15,7 +14,7 @@ import java.io.Serializable;
public class WxMpCardResult implements Serializable {
/**
- *
+ *
*/
private static final long serialVersionUID = -7950878428289035637L;
@@ -65,7 +64,7 @@ public class WxMpCardResult implements Serializable {
@Override
public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
+ return ToStringUtils.toSimpleString(this);
}
public String getUserCardStatus() {
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUser.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUser.java
index f56ccf5c..8d7090fd 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUser.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUser.java
@@ -1,18 +1,15 @@
package me.chanjar.weixin.mp.bean.result;
-import java.io.Serializable;
-import java.lang.reflect.Type;
-import java.util.List;
-
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
-
+import me.chanjar.weixin.common.util.ToStringUtils;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
+import java.io.Serializable;
+import java.lang.reflect.Type;
+import java.util.List;
+
/**
* 微信用户信息
* @author chanjarster
@@ -41,10 +38,6 @@ public class WxMpUser implements Serializable {
return this.subscribe;
}
- public Boolean isSubscribe() {
- return this.subscribe;
- }
-
public void setSubscribe(Boolean subscribe) {
this.subscribe = subscribe;
}
@@ -179,7 +172,7 @@ public class WxMpUser implements Serializable {
@Override
public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
+ return ToStringUtils.toSimpleString(this);
}
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/store/WxMpStoreBaseInfo.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/store/WxMpStoreBaseInfo.java
index dcfd3153..91d52d2e 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/store/WxMpStoreBaseInfo.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/store/WxMpStoreBaseInfo.java
@@ -4,22 +4,21 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.annotations.SerializedName;
import me.chanjar.weixin.common.annotation.Required;
+import me.chanjar.weixin.common.util.ToStringUtils;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
import java.math.BigDecimal;
import java.util.List;
/**
* 门店基础信息
- * @author binarywang(https://github.com/binarywang)
+ * @author binarywang(Binary Wang)
* Created by Binary Wang on 2016-09-23.
*/
public class WxMpStoreBaseInfo {
@Override
public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
+ return ToStringUtils.toSimpleString(this);
}
public static WxMpStoreBaseInfo fromJson(String json) {
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/store/WxMpStoreInfo.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/store/WxMpStoreInfo.java
index 5b44b860..1450bc3c 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/store/WxMpStoreInfo.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/store/WxMpStoreInfo.java
@@ -1,15 +1,12 @@
package me.chanjar.weixin.mp.bean.store;
-import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-
import com.google.gson.annotations.SerializedName;
+import me.chanjar.weixin.common.util.ToStringUtils;
public class WxMpStoreInfo {
@Override
public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
+ return ToStringUtils.toSimpleString(this);
}
@SerializedName("base_info")
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/store/WxMpStoreListResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/store/WxMpStoreListResult.java
index 2bc514ed..f9cc3fbe 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/store/WxMpStoreListResult.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/store/WxMpStoreListResult.java
@@ -1,24 +1,21 @@
package me.chanjar.weixin.mp.bean.store;
-import java.util.List;
-
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-
import com.google.gson.annotations.SerializedName;
-
+import me.chanjar.weixin.common.util.ToStringUtils;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
+import java.util.List;
+
/**
* 门店列表结果类
- * @author binarywang(https://github.com/binarywang)
+ * @author binarywang(Binary Wang)
* Created by Binary Wang on 2016-09-27.
*
*/
public class WxMpStoreListResult {
@Override
public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
+ return ToStringUtils.toSimpleString(this);
}
public static WxMpStoreListResult fromJson(String json) {
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxTagListUser.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxTagListUser.java
index b07314ba..e1307be7 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxTagListUser.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxTagListUser.java
@@ -1,17 +1,14 @@
package me.chanjar.weixin.mp.bean.tag;
-import java.util.List;
-
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-
import com.google.gson.annotations.SerializedName;
-
+import me.chanjar.weixin.common.util.ToStringUtils;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
+import java.util.List;
+
/**
* 获取标签下粉丝列表的结果对象
- * @author binarywang(https://github.com/binarywang)
+ * @author binarywang(Binary Wang)
* Created by Binary Wang on 2016-09-19.
*/
public class WxTagListUser {
@@ -26,7 +23,7 @@ public class WxTagListUser {
@Override
public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
+ return ToStringUtils.toSimpleString(this);
}
/**
@@ -74,7 +71,7 @@ public class WxTagListUser {
public static class WxTagListUserData {
@Override
public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
+ return ToStringUtils.toSimpleString(this);
}
/**
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxUserTag.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxUserTag.java
index 53e247a7..6554c261 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxUserTag.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxUserTag.java
@@ -1,18 +1,15 @@
package me.chanjar.weixin.mp.bean.tag;
-import java.util.List;
-
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
-
+import me.chanjar.weixin.common.util.ToStringUtils;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
+import java.util.List;
+
/**
* 用户标签对象
- * @author binarywang(https://github.com/binarywang)
+ * @author binarywang(Binary Wang)
* Created by Binary Wang on 2016/9/2.
*/
public class WxUserTag {
@@ -73,6 +70,6 @@ public class WxUserTag {
@Override
public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
+ return ToStringUtils.toSimpleString(this);
}
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/template/WxMpTemplate.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/template/WxMpTemplate.java
new file mode 100644
index 00000000..368284f2
--- /dev/null
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/template/WxMpTemplate.java
@@ -0,0 +1,123 @@
+package me.chanjar.weixin.mp.bean.template;
+
+import com.google.gson.JsonParser;
+import com.google.gson.annotations.SerializedName;
+import com.google.gson.reflect.TypeToken;
+import me.chanjar.weixin.common.util.ToStringUtils;
+import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
+
+import java.util.List;
+
+/**
+ *
+ * 模板列表信息
+ * Created by Binary Wang on 2016-10-17.
+ * @author binarywang(Binary Wang)
+ *
+ */
+public class WxMpTemplate {
+
+ private static final JsonParser JSON_PARSER = new JsonParser();
+
+ public static List fromJson(String json) {
+ return WxMpGsonBuilder.create().fromJson(JSON_PARSER.parse(json).getAsJsonObject().get("template_list"),
+ new TypeToken>() {
+ }.getType());
+ }
+
+ @Override
+ public String toString() {
+ return ToStringUtils.toSimpleString(this);
+ }
+
+ /**
+ * template_id
+ * 模板ID
+ */
+ @SerializedName("template_id")
+ private String templateId;
+
+ /**
+ * title
+ * 模板标题
+ */
+ @SerializedName("title")
+ private String title;
+
+ /**
+ * primary_industry
+ * 模板所属行业的一级行业
+ */
+ @SerializedName("primary_industry")
+ private String primaryIndustry;
+
+ /**
+ * deputy_industry
+ * 模板所属行业的二级行业
+ */
+ @SerializedName("deputy_industry")
+ private String deputyIndustry;
+
+ /**
+ * content
+ * 模板内容
+ */
+ @SerializedName("content")
+ private String content;
+
+ /**
+ * example
+ * 模板示例
+ */
+ @SerializedName("example")
+ private String example;
+
+ public String getTemplateId() {
+ return this.templateId;
+ }
+
+ public void setTemplateId(String templateId) {
+ this.templateId = templateId;
+ }
+
+ public String getTitle() {
+ return this.title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getPrimaryIndustry() {
+ return this.primaryIndustry;
+ }
+
+ public void setPrimaryIndustry(String primaryIndustry) {
+ this.primaryIndustry = primaryIndustry;
+ }
+
+ public String getDeputyIndustry() {
+ return this.deputyIndustry;
+ }
+
+ public void setDeputyIndustry(String deputyIndustry) {
+ this.deputyIndustry = deputyIndustry;
+ }
+
+ public String getContent() {
+ return this.content;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+
+ public String getExample() {
+ return this.example;
+ }
+
+ public void setExample(String example) {
+ this.example = example;
+ }
+
+}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpTemplateData.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/template/WxMpTemplateData.java
similarity index 95%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpTemplateData.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/template/WxMpTemplateData.java
index d46ae24b..0eb0eaa5 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpTemplateData.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/template/WxMpTemplateData.java
@@ -1,4 +1,4 @@
-package me.chanjar.weixin.mp.bean;
+package me.chanjar.weixin.mp.bean.template;
import java.io.Serializable;
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/template/WxMpTemplateIndustry.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/template/WxMpTemplateIndustry.java
new file mode 100644
index 00000000..6d0db1ab
--- /dev/null
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/template/WxMpTemplateIndustry.java
@@ -0,0 +1,106 @@
+package me.chanjar.weixin.mp.bean.template;
+
+
+import me.chanjar.weixin.common.util.ToStringUtils;
+import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
+
+import java.io.Serializable;
+
+/**
+ * @author miller
+ */
+public class WxMpTemplateIndustry implements Serializable {
+ private static final long serialVersionUID = -7700398224795914722L;
+ private Industry primaryIndustry;
+ private Industry secondIndustry;
+
+ public WxMpTemplateIndustry() {
+ }
+
+ public WxMpTemplateIndustry(Industry primaryIndustry, Industry secondIndustry) {
+ this.primaryIndustry = primaryIndustry;
+ this.secondIndustry = secondIndustry;
+ }
+
+ /**
+ * @author miller
+ * 官方文档中,创建和获取的数据结构不一样。所以采用冗余字段的方式,实现相应的接口
+ */
+ public static class Industry implements Serializable {
+ private static final long serialVersionUID = -1707184885588012142L;
+ private String id;
+ private String firstClass;
+ private String secondClass;
+
+ public Industry() {
+ }
+
+ public Industry(String id) {
+ this.id = id;
+ }
+
+ public Industry(String id, String firstClass, String secondClass) {
+ this.id = id;
+ this.firstClass = firstClass;
+ this.secondClass = secondClass;
+ }
+
+ @Override
+ public String toString() {
+ return ToStringUtils.toSimpleString(this);
+ }
+
+ public String getId() {
+ return this.id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getFirstClass() {
+ return this.firstClass;
+ }
+
+ public void setFirstClass(String firstClass) {
+ this.firstClass = firstClass;
+ }
+
+ public String getSecondClass() {
+ return this.secondClass;
+ }
+
+ public void setSecondClass(String secondClass) {
+ this.secondClass = secondClass;
+ }
+ }
+
+ @Override
+ public String toString() {
+ return ToStringUtils.toSimpleString(this);
+ }
+
+ public static WxMpTemplateIndustry fromJson(String json) {
+ return WxMpGsonBuilder.create().fromJson(json, WxMpTemplateIndustry.class);
+ }
+
+ public String toJson() {
+ return WxMpGsonBuilder.create().toJson(this);
+ }
+
+ public Industry getPrimaryIndustry() {
+ return this.primaryIndustry;
+ }
+
+ public void setPrimaryIndustry(Industry primaryIndustry) {
+ this.primaryIndustry = primaryIndustry;
+ }
+
+ public Industry getSecondIndustry() {
+ return this.secondIndustry;
+ }
+
+ public void setSecondIndustry(Industry secondIndustry) {
+ this.secondIndustry = secondIndustry;
+ }
+}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpTemplateMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/template/WxMpTemplateMessage.java
similarity index 98%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpTemplateMessage.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/template/WxMpTemplateMessage.java
index 408abb50..106e5fb6 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpTemplateMessage.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/template/WxMpTemplateMessage.java
@@ -1,4 +1,4 @@
-package me.chanjar.weixin.mp.bean;
+package me.chanjar.weixin.mp.bean.template;
import java.io.Serializable;
import java.util.ArrayList;
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/BaseBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/BaseBuilder.java
similarity index 57%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/BaseBuilder.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/BaseBuilder.java
index 18bf81f9..c5285d6f 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/BaseBuilder.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/BaseBuilder.java
@@ -1,6 +1,6 @@
-package me.chanjar.weixin.mp.bean.custombuilder;
+package me.chanjar.weixin.mp.builder.kefu;
-import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
+import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
public class BaseBuilder {
protected String msgType;
@@ -11,8 +11,8 @@ public class BaseBuilder {
return (T) this;
}
- public WxMpCustomMessage build() {
- WxMpCustomMessage m = new WxMpCustomMessage();
+ public WxMpKefuMessage build() {
+ WxMpKefuMessage m = new WxMpKefuMessage();
m.setMsgType(this.msgType);
m.setToUser(this.toUser);
return m;
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/ImageBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/ImageBuilder.java
similarity index 62%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/ImageBuilder.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/ImageBuilder.java
index 1fb5363c..9533f5b3 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/ImageBuilder.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/ImageBuilder.java
@@ -1,12 +1,12 @@
-package me.chanjar.weixin.mp.bean.custombuilder;
+package me.chanjar.weixin.mp.builder.kefu;
import me.chanjar.weixin.common.api.WxConsts;
-import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
+import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
/**
* 获得消息builder
*
- * 用法: WxMpCustomMessage m = WxMpCustomMessage.IMAGE().mediaId(...).toUser(...).build();
+ * 用法: WxMpKefuMessage m = WxMpKefuMessage.IMAGE().mediaId(...).toUser(...).build();
*
* @author chanjarster
*
@@ -24,8 +24,8 @@ public final class ImageBuilder extends BaseBuilder {
}
@Override
- public WxMpCustomMessage build() {
- WxMpCustomMessage m = super.build();
+ public WxMpKefuMessage build() {
+ WxMpKefuMessage m = super.build();
m.setMediaId(this.mediaId);
return m;
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/MpNewsBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/MpNewsBuilder.java
new file mode 100644
index 00000000..615802b3
--- /dev/null
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/MpNewsBuilder.java
@@ -0,0 +1,33 @@
+package me.chanjar.weixin.mp.builder.kefu;
+
+import me.chanjar.weixin.common.api.WxConsts;
+import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
+
+/**
+ * 图文消息builder
+ *
+ * 用法:
+ * WxMpKefuMessage m = WxMpKefuMessage.NEWS().mediaId("xxxxx").toUser(...).build();
+ *
+ * @author Binary Wang
+ *
+ */
+public final class MpNewsBuilder extends BaseBuilder {
+ private String mediaId;
+
+ public MpNewsBuilder() {
+ this.msgType = WxConsts.CUSTOM_MSG_MPNEWS;
+ }
+
+ public MpNewsBuilder mediaId(String mediaId) {
+ this.mediaId = mediaId;
+ return this;
+ }
+
+ @Override
+ public WxMpKefuMessage build() {
+ WxMpKefuMessage m = super.build();
+ m.setMpNewsMediaId(this.mediaId);
+ return m;
+ }
+}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/MusicBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/MusicBuilder.java
similarity index 85%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/MusicBuilder.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/MusicBuilder.java
index 7a9994ad..8d23bacd 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/MusicBuilder.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/MusicBuilder.java
@@ -1,12 +1,12 @@
-package me.chanjar.weixin.mp.bean.custombuilder;
+package me.chanjar.weixin.mp.builder.kefu;
import me.chanjar.weixin.common.api.WxConsts;
-import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
+import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
/**
* 音乐消息builder
*
- * 用法: WxMpCustomMessage m = WxMpCustomMessage.MUSIC()
+ * 用法: WxMpKefuMessage m = WxMpKefuMessage.MUSIC()
* .musicUrl(...)
* .hqMusicUrl(...)
* .title(...)
@@ -53,8 +53,8 @@ public final class MusicBuilder extends BaseBuilder {
}
@Override
- public WxMpCustomMessage build() {
- WxMpCustomMessage m = super.build();
+ public WxMpKefuMessage build() {
+ WxMpKefuMessage m = super.build();
m.setMusicUrl(this.musicUrl);
m.setHqMusicUrl(this.hqMusicUrl);
m.setTitle(this.title);
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/NewsBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/NewsBuilder.java
similarity index 51%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/NewsBuilder.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/NewsBuilder.java
index ad0efb23..900babb5 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/NewsBuilder.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/NewsBuilder.java
@@ -1,7 +1,7 @@
-package me.chanjar.weixin.mp.bean.custombuilder;
+package me.chanjar.weixin.mp.builder.kefu;
import me.chanjar.weixin.common.api.WxConsts;
-import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
+import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
import java.util.ArrayList;
import java.util.List;
@@ -10,27 +10,27 @@ import java.util.List;
* 图文消息builder
*
* 用法:
- * WxMpCustomMessage m = WxMpCustomMessage.NEWS().addArticle(article).toUser(...).build();
+ * WxMpKefuMessage m = WxMpKefuMessage.NEWS().addArticle(article).toUser(...).build();
*
* @author chanjarster
*
*/
public final class NewsBuilder extends BaseBuilder {
- private List articles = new ArrayList<>();
-
+ private List articles = new ArrayList<>();
+
public NewsBuilder() {
this.msgType = WxConsts.CUSTOM_MSG_NEWS;
}
- public NewsBuilder addArticle(WxMpCustomMessage.WxArticle article) {
+ public NewsBuilder addArticle(WxMpKefuMessage.WxArticle article) {
this.articles.add(article);
return this;
}
@Override
- public WxMpCustomMessage build() {
- WxMpCustomMessage m = super.build();
+ public WxMpKefuMessage build() {
+ WxMpKefuMessage m = super.build();
m.setArticles(this.articles);
return m;
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/TextBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/TextBuilder.java
similarity index 62%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/TextBuilder.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/TextBuilder.java
index 7f458457..9e5f9384 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/TextBuilder.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/TextBuilder.java
@@ -1,12 +1,12 @@
-package me.chanjar.weixin.mp.bean.custombuilder;
+package me.chanjar.weixin.mp.builder.kefu;
import me.chanjar.weixin.common.api.WxConsts;
-import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
+import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
/**
* 文本消息builder
*
- * 用法: WxMpCustomMessage m = WxMpCustomMessage.TEXT().content(...).toUser(...).build();
+ * 用法: WxMpKefuMessage m = WxMpKefuMessage.TEXT().content(...).toUser(...).build();
*
* @author chanjarster
*
@@ -24,8 +24,8 @@ public final class TextBuilder extends BaseBuilder {
}
@Override
- public WxMpCustomMessage build() {
- WxMpCustomMessage m = super.build();
+ public WxMpKefuMessage build() {
+ WxMpKefuMessage m = super.build();
m.setContent(this.content);
return m;
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/VideoBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/VideoBuilder.java
similarity index 84%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/VideoBuilder.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/VideoBuilder.java
index bda6ef7c..13ade68c 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/VideoBuilder.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/VideoBuilder.java
@@ -1,12 +1,12 @@
-package me.chanjar.weixin.mp.bean.custombuilder;
+package me.chanjar.weixin.mp.builder.kefu;
import me.chanjar.weixin.common.api.WxConsts;
-import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
+import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
/**
* 视频消息builder
*
- * 用法: WxMpCustomMessage m = WxMpCustomMessage.VOICE()
+ * 用法: WxMpKefuMessage m = WxMpKefuMessage.VOICE()
* .mediaId(...)
* .title(...)
* .thumbMediaId(..)
@@ -48,8 +48,8 @@ public final class VideoBuilder extends BaseBuilder {
}
@Override
- public WxMpCustomMessage build() {
- WxMpCustomMessage m = super.build();
+ public WxMpKefuMessage build() {
+ WxMpKefuMessage m = super.build();
m.setMediaId(this.mediaId);
m.setTitle(this.title);
m.setDescription(this.description);
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/VoiceBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/VoiceBuilder.java
similarity index 62%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/VoiceBuilder.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/VoiceBuilder.java
index 867c8aff..c9cb32b2 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/VoiceBuilder.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/VoiceBuilder.java
@@ -1,12 +1,12 @@
-package me.chanjar.weixin.mp.bean.custombuilder;
+package me.chanjar.weixin.mp.builder.kefu;
import me.chanjar.weixin.common.api.WxConsts;
-import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
+import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
/**
* 语音消息builder
*
- * 用法: WxMpCustomMessage m = WxMpCustomMessage.VOICE().mediaId(...).toUser(...).build();
+ * 用法: WxMpKefuMessage m = WxMpKefuMessage.VOICE().mediaId(...).toUser(...).build();
*
* @author chanjarster
*
@@ -24,8 +24,8 @@ public final class VoiceBuilder extends BaseBuilder {
}
@Override
- public WxMpCustomMessage build() {
- WxMpCustomMessage m = super.build();
+ public WxMpKefuMessage build() {
+ WxMpKefuMessage m = super.build();
m.setMediaId(this.mediaId);
return m;
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/WxCardBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/WxCardBuilder.java
similarity index 62%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/WxCardBuilder.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/WxCardBuilder.java
index 8620cd84..e600df6c 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/WxCardBuilder.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/kefu/WxCardBuilder.java
@@ -1,12 +1,12 @@
-package me.chanjar.weixin.mp.bean.custombuilder;
+package me.chanjar.weixin.mp.builder.kefu;
import me.chanjar.weixin.common.api.WxConsts;
-import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
+import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
/**
* 卡券消息builder
*
- * 用法: WxMpCustomMessage m = WxMpCustomMessage.WXCARD().cardId(...).toUser(...).build();
+ * 用法: WxMpKefuMessage m = WxMpKefuMessage.WXCARD().cardId(...).toUser(...).build();
*
* @author mgcnrx11
*
@@ -24,8 +24,8 @@ public final class WxCardBuilder extends BaseBuilder {
}
@Override
- public WxMpCustomMessage build() {
- WxMpCustomMessage m = super.build();
+ public WxMpKefuMessage build() {
+ WxMpKefuMessage m = super.build();
m.setCardId(this.cardId);
return m;
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/BaseBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/outxml/BaseBuilder.java
similarity index 83%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/BaseBuilder.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/outxml/BaseBuilder.java
index 77db2617..e594565c 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/BaseBuilder.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/outxml/BaseBuilder.java
@@ -1,29 +1,29 @@
-package me.chanjar.weixin.mp.bean.outxmlbuilder;
+package me.chanjar.weixin.mp.builder.outxml;
-import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
+import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
public abstract class BaseBuilder {
-
+
protected String toUserName;
-
+
protected String fromUserName;
-
+
public BuilderType toUser(String touser) {
this.toUserName = touser;
return (BuilderType) this;
}
-
+
public BuilderType fromUser(String fromusername) {
this.fromUserName = fromusername;
return (BuilderType) this;
}
public abstract ValueType build();
-
+
public void setCommon(WxMpXmlOutMessage m) {
m.setToUserName(this.toUserName);
m.setFromUserName(this.fromUserName);
m.setCreateTime(System.currentTimeMillis() / 1000l);
}
-
+
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/ImageBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/outxml/ImageBuilder.java
similarity index 80%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/ImageBuilder.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/outxml/ImageBuilder.java
index ee265bf3..0bf441bf 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/ImageBuilder.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/outxml/ImageBuilder.java
@@ -1,6 +1,6 @@
-package me.chanjar.weixin.mp.bean.outxmlbuilder;
+package me.chanjar.weixin.mp.builder.outxml;
-import me.chanjar.weixin.mp.bean.WxMpXmlOutImageMessage;
+import me.chanjar.weixin.mp.bean.message.WxMpXmlOutImageMessage;
/**
* 图片消息builder
@@ -22,5 +22,5 @@ public final class ImageBuilder extends BaseBuilder {
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/NewsBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/outxml/NewsBuilder.java
similarity index 84%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/NewsBuilder.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/outxml/NewsBuilder.java
index 1014c452..1936c5f5 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/NewsBuilder.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/outxml/NewsBuilder.java
@@ -1,6 +1,6 @@
-package me.chanjar.weixin.mp.bean.outxmlbuilder;
+package me.chanjar.weixin.mp.builder.outxml;
-import me.chanjar.weixin.mp.bean.WxMpXmlOutNewsMessage;
+import me.chanjar.weixin.mp.bean.message.WxMpXmlOutNewsMessage;
import java.util.ArrayList;
import java.util.List;
@@ -12,12 +12,12 @@ import java.util.List;
public final class NewsBuilder extends BaseBuilder {
protected final List articles = new ArrayList<>();
-
+
public NewsBuilder addArticle(WxMpXmlOutNewsMessage.Item item) {
this.articles.add(item);
return this;
}
-
+
@Override
public WxMpXmlOutNewsMessage build() {
WxMpXmlOutNewsMessage m = new WxMpXmlOutNewsMessage();
@@ -27,5 +27,5 @@ public final class NewsBuilder extends BaseBuilder
+ * 用法: WxMpKefuMessage m = WxMpXmlOutMessage.TRANSFER_CUSTOMER_SERVICE().content(...).toUser(...).build();
+ *
+ *
+ * @author chanjarster
+ */
+public final class TransferCustomerServiceBuilder extends BaseBuilder {
+ private String kfAccount;
+
+ public TransferCustomerServiceBuilder kfAccount(String kf) {
+ this.kfAccount = kf;
+ return this;
+ }
+
+ @Override
+ public WxMpXmlOutTransferKefuMessage build() {
+ WxMpXmlOutTransferKefuMessage m = new WxMpXmlOutTransferKefuMessage();
+ setCommon(m);
+ if(StringUtils.isNotBlank(this.kfAccount)){
+ WxMpXmlOutTransferKefuMessage.TransInfo transInfo = new WxMpXmlOutTransferKefuMessage.TransInfo();
+ transInfo.setKfAccount(this.kfAccount);
+ m.setTransInfo(transInfo);
+ }
+ return m;
+ }
+}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/VideoBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/outxml/VideoBuilder.java
similarity index 87%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/VideoBuilder.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/outxml/VideoBuilder.java
index 1690725c..d8ac721e 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/VideoBuilder.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/outxml/VideoBuilder.java
@@ -1,6 +1,6 @@
-package me.chanjar.weixin.mp.bean.outxmlbuilder;
+package me.chanjar.weixin.mp.builder.outxml;
-import me.chanjar.weixin.mp.bean.WxMpXmlOutVideoMessage;
+import me.chanjar.weixin.mp.bean.message.WxMpXmlOutVideoMessage;
/**
* 视频消息builder
@@ -25,7 +25,7 @@ public final class VideoBuilder extends BaseBuilder, JsonDeserializer {
+ implements JsonSerializer, JsonDeserializer {
@Override
- public JsonElement serialize(WxMpIndustry wxMpIndustry, Type type,
+ public JsonElement serialize(WxMpTemplateIndustry wxMpIndustry, Type type,
JsonSerializationContext jsonSerializationContext) {
JsonObject json = new JsonObject();
json.addProperty("industry_id1", wxMpIndustry.getPrimaryIndustry().getId());
@@ -29,10 +21,10 @@ public class WxMpIndustryGsonAdapter
}
@Override
- public WxMpIndustry deserialize(JsonElement jsonElement, Type type,
+ public WxMpTemplateIndustry deserialize(JsonElement jsonElement, Type type,
JsonDeserializationContext jsonDeserializationContext)
throws JsonParseException {
- WxMpIndustry wxMpIndustry = new WxMpIndustry();
+ WxMpTemplateIndustry wxMpIndustry = new WxMpTemplateIndustry();
JsonObject primaryIndustry = jsonElement.getAsJsonObject()
.get("primary_industry").getAsJsonObject();
wxMpIndustry.setPrimaryIndustry(convertFromJson(primaryIndustry));
@@ -42,8 +34,8 @@ public class WxMpIndustryGsonAdapter
return wxMpIndustry;
}
- private static Industry convertFromJson(JsonObject json) {
- Industry industry = new Industry();
+ private static WxMpTemplateIndustry.Industry convertFromJson(JsonObject json) {
+ WxMpTemplateIndustry.Industry industry = new WxMpTemplateIndustry.Industry();
industry.setFirstClass(GsonHelper.getString(json, "first_class"));
industry.setSecondClass(GsonHelper.getString(json, "second_class"));
return industry;
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpCustomMessageGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpKefuMessageGsonAdapter.java
similarity index 85%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpCustomMessageGsonAdapter.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpKefuMessageGsonAdapter.java
index 973966db..abab87a1 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpCustomMessageGsonAdapter.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpKefuMessageGsonAdapter.java
@@ -10,20 +10,19 @@ package me.chanjar.weixin.mp.util.json;
import com.google.gson.*;
import me.chanjar.weixin.common.api.WxConsts;
-import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
+import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
+import org.apache.commons.lang3.StringUtils;
import java.lang.reflect.Type;
-import org.apache.commons.lang3.StringUtils;
-
-public class WxMpCustomMessageGsonAdapter implements JsonSerializer {
+public class WxMpKefuMessageGsonAdapter implements JsonSerializer {
@Override
- public JsonElement serialize(WxMpCustomMessage message, Type typeOfSrc, JsonSerializationContext context) {
+ public JsonElement serialize(WxMpKefuMessage message, Type typeOfSrc, JsonSerializationContext context) {
JsonObject messageJson = new JsonObject();
messageJson.addProperty("touser", message.getToUser());
messageJson.addProperty("msgtype", message.getMsgType());
-
+
if (WxConsts.CUSTOM_MSG_TEXT.equals(message.getMsgType())) {
JsonObject text = new JsonObject();
text.addProperty("content", message.getContent());
@@ -60,11 +59,11 @@ public class WxMpCustomMessageGsonAdapter implements JsonSerializerHello World");
- this.wxService.getKefuService().customMessageSend(message);
+ this.wxService.getKefuService().sendKefuMessage(message);
}
- public void testSendCustomMessageWithKfAccount() throws WxErrorException {
+ public void testSendKefuMessageWithKfAccount() throws WxErrorException {
WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService
.getWxMpConfigStorage();
- WxMpCustomMessage message = new WxMpCustomMessage();
+ WxMpKefuMessage message = new WxMpKefuMessage();
message.setMsgType(WxConsts.CUSTOM_MSG_TEXT);
message.setToUser(configStorage.getOpenid());
message.setKfAccount(configStorage.getKfAccount());
message.setContent(
"欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World");
- this.wxService.getKefuService().customMessageSend(message);
+ this.wxService.getKefuService().sendKefuMessage(message);
}
public void testKfList() throws WxErrorException {
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImplTest.java
index 5cde8adc..043a49ec 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImplTest.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImplTest.java
@@ -6,10 +6,11 @@ import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.util.fs.FileUtils;
import me.chanjar.weixin.mp.api.ApiTestModule;
-import me.chanjar.weixin.mp.bean.WxMpMaterial;
-import me.chanjar.weixin.mp.bean.WxMpMaterialArticleUpdate;
-import me.chanjar.weixin.mp.bean.WxMpMaterialNews;
-import me.chanjar.weixin.mp.bean.result.*;
+import me.chanjar.weixin.mp.api.WxMpService;
+import me.chanjar.weixin.mp.bean.material.WxMpMaterial;
+import me.chanjar.weixin.mp.bean.material.WxMpMaterialArticleUpdate;
+import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews;
+import me.chanjar.weixin.mp.bean.material.*;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
@@ -32,7 +33,7 @@ import static org.junit.Assert.*;
@Guice(modules = ApiTestModule.class)
public class WxMpMaterialServiceImplTest {
@Inject
- protected WxMpServiceImpl wxService;
+ protected WxMpService wxService;
private Map> mediaIds = new LinkedHashMap<>();
// 缩略图的id,测试上传图文使用
@@ -98,41 +99,40 @@ public class WxMpMaterialServiceImplTest {
@Test(dependsOnMethods = {"testUploadMaterial"})
public void testAddNews() throws WxErrorException {
-
// 单图文消息
WxMpMaterialNews wxMpMaterialNewsSingle = new WxMpMaterialNews();
- WxMpMaterialNews.WxMpMaterialNewsArticle mpMaterialNewsArticleSingle = new WxMpMaterialNews.WxMpMaterialNewsArticle();
- mpMaterialNewsArticleSingle.setAuthor("author");
- mpMaterialNewsArticleSingle.setThumbMediaId(this.thumbMediaId);
- mpMaterialNewsArticleSingle.setTitle("single title");
- mpMaterialNewsArticleSingle.setContent("single content");
- mpMaterialNewsArticleSingle.setContentSourceUrl("content url");
- mpMaterialNewsArticleSingle.setShowCoverPic(true);
- mpMaterialNewsArticleSingle.setDigest("single news");
- wxMpMaterialNewsSingle.addArticle(mpMaterialNewsArticleSingle);
+ WxMpMaterialNews.WxMpMaterialNewsArticle article = new WxMpMaterialNews.WxMpMaterialNewsArticle();
+ article.setAuthor("author");
+ article.setThumbMediaId(this.thumbMediaId);
+ article.setTitle("single title");
+ article.setContent("single content");
+ article.setContentSourceUrl("content url");
+ article.setShowCoverPic(true);
+ article.setDigest("single news");
+ wxMpMaterialNewsSingle.addArticle(article);
// 多图文消息
WxMpMaterialNews wxMpMaterialNewsMultiple = new WxMpMaterialNews();
- WxMpMaterialNews.WxMpMaterialNewsArticle wxMpMaterialNewsArticleMultiple1 = new WxMpMaterialNews.WxMpMaterialNewsArticle();
- wxMpMaterialNewsArticleMultiple1.setAuthor("author1");
- wxMpMaterialNewsArticleMultiple1.setThumbMediaId(this.thumbMediaId);
- wxMpMaterialNewsArticleMultiple1.setTitle("multi title1");
- wxMpMaterialNewsArticleMultiple1.setContent("content 1");
- wxMpMaterialNewsArticleMultiple1.setContentSourceUrl("content url");
- wxMpMaterialNewsArticleMultiple1.setShowCoverPic(true);
- wxMpMaterialNewsArticleMultiple1.setDigest("");
-
- WxMpMaterialNews.WxMpMaterialNewsArticle wxMpMaterialNewsArticleMultiple2 = new WxMpMaterialNews.WxMpMaterialNewsArticle();
- wxMpMaterialNewsArticleMultiple2.setAuthor("author2");
- wxMpMaterialNewsArticleMultiple2.setThumbMediaId(this.thumbMediaId);
- wxMpMaterialNewsArticleMultiple2.setTitle("multi title2");
- wxMpMaterialNewsArticleMultiple2.setContent("content 2");
- wxMpMaterialNewsArticleMultiple2.setContentSourceUrl("content url");
- wxMpMaterialNewsArticleMultiple2.setShowCoverPic(true);
- wxMpMaterialNewsArticleMultiple2.setDigest("");
-
- wxMpMaterialNewsMultiple.addArticle(wxMpMaterialNewsArticleMultiple1);
- wxMpMaterialNewsMultiple.addArticle(wxMpMaterialNewsArticleMultiple2);
+ WxMpMaterialNews.WxMpMaterialNewsArticle article1 = new WxMpMaterialNews.WxMpMaterialNewsArticle();
+ article1.setAuthor("author1");
+ article1.setThumbMediaId(this.thumbMediaId);
+ article1.setTitle("multi title1");
+ article1.setContent("content 1");
+ article1.setContentSourceUrl("content url");
+ article1.setShowCoverPic(true);
+ article1.setDigest("");
+
+ WxMpMaterialNews.WxMpMaterialNewsArticle article2 = new WxMpMaterialNews.WxMpMaterialNewsArticle();
+ article2.setAuthor("author2");
+ article2.setThumbMediaId(this.thumbMediaId);
+ article2.setTitle("multi title2");
+ article2.setContent("content 2");
+ article2.setContentSourceUrl("content url");
+ article2.setShowCoverPic(true);
+ article2.setDigest("");
+
+ wxMpMaterialNewsMultiple.addArticle(article1);
+ wxMpMaterialNewsMultiple.addArticle(article2);
WxMpMaterialUploadResult resSingle = this.wxService.getMaterialService().materialNewsUpload(wxMpMaterialNewsSingle);
this.singleNewsMediaId = resSingle.getMediaId();
@@ -268,6 +268,7 @@ public class WxMpMaterialServiceImplTest {
// 以下为media接口的测试
private List mediaIdsToDownload = new ArrayList<>();
+
@Test(dataProvider="mediaFiles")
public void testUploadMedia(String mediaType, String fileType, String fileName) throws WxErrorException, IOException {
try(InputStream inputStream = ClassLoader.getSystemResourceAsStream(fileName)){
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java
index 1e0b60dd..f31a0e4b 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java
@@ -1,5 +1,6 @@
package me.chanjar.weixin.mp.api.impl;
+import me.chanjar.weixin.mp.api.WxMpService;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Guice;
@@ -24,8 +25,8 @@ import me.chanjar.weixin.mp.api.ApiTestModule;
public class WxMpMenuServiceImplTest {
@Inject
- protected WxMpServiceImpl wxService;
-
+ protected WxMpService wxService;
+
@Test(dataProvider = "menu")
public void testCreateMenu(WxMenu wxMenu) throws WxErrorException {
System.out.println(wxMenu.toJson());
@@ -82,12 +83,12 @@ public class WxMpMenuServiceImplTest {
Assert.assertNotNull(wxMenu);
System.out.println(wxMenu.toJson());
}
-
+
@Test(dependsOnMethods = { "testGetMenu"})
public void testDeleteMenu() throws WxErrorException {
this.wxService.getMenuService().menuDelete();
}
-
+
@DataProvider(name="menu")
public Object[][] getMenu() {
WxMenu menu = new WxMenu();
@@ -95,45 +96,45 @@ public class WxMpMenuServiceImplTest {
button1.setType(WxConsts.BUTTON_CLICK);
button1.setName("今日歌曲");
button1.setKey("V1001_TODAY_MUSIC");
-
+
WxMenuButton button2 = new WxMenuButton();
button2.setType(WxConsts.BUTTON_CLICK);
button2.setName("歌手简介");
button2.setKey("V1001_TODAY_SINGER");
-
+
WxMenuButton button3 = new WxMenuButton();
button3.setName("菜单");
-
+
menu.getButtons().add(button1);
menu.getButtons().add(button2);
menu.getButtons().add(button3);
-
+
WxMenuButton button31 = new WxMenuButton();
button31.setType(WxConsts.BUTTON_VIEW);
button31.setName("搜索");
button31.setUrl("http://www.soso.com/");
-
+
WxMenuButton button32 = new WxMenuButton();
button32.setType(WxConsts.BUTTON_VIEW);
button32.setName("视频");
button32.setUrl("http://v.qq.com/");
-
+
WxMenuButton button33 = new WxMenuButton();
button33.setType(WxConsts.BUTTON_CLICK);
button33.setName("赞一下我们");
button33.setKey("V1001_GOOD");
-
+
button3.getSubButtons().add(button31);
button3.getSubButtons().add(button32);
button3.getSubButtons().add(button33);
-
+
return new Object[][] {
new Object[] {
menu
}
};
-
+
}
-
-
+
+
}
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java
index 092be38a..b4e22f11 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java
@@ -1,17 +1,21 @@
package me.chanjar.weixin.mp.api.impl;
-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.mp.api.ApiTestModule;
+import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage;
-import me.chanjar.weixin.mp.bean.pay.WxRedpackResult;
-import me.chanjar.weixin.mp.bean.pay.WxSendRedpackRequest;
-import me.chanjar.weixin.mp.bean.pay.WxUnifiedOrderRequest;
-import me.chanjar.weixin.mp.bean.pay.WxUnifiedOrderResult;
+import me.chanjar.weixin.mp.bean.pay.request.WxEntPayRequest;
+import me.chanjar.weixin.mp.bean.pay.request.WxPayRefundRequest;
+import me.chanjar.weixin.mp.bean.pay.request.WxPaySendRedpackRequest;
+import me.chanjar.weixin.mp.bean.pay.request.WxPayUnifiedOrderRequest;
+import me.chanjar.weixin.mp.bean.pay.result.WxPayRefundResult;
+import me.chanjar.weixin.mp.bean.pay.result.WxPaySendRedpackResult;
+import me.chanjar.weixin.mp.bean.pay.result.WxPayUnifiedOrderResult;
+import org.testng.annotations.Guice;
+import org.testng.annotations.Test;
+
+import java.io.File;
/**
* 测试支付相关接口
@@ -23,7 +27,7 @@ import me.chanjar.weixin.mp.bean.pay.WxUnifiedOrderResult;
public class WxMpPayServiceImplTest {
@Inject
- protected WxMpServiceImpl wxService;
+ protected WxMpService wxService;
@Test
public void testGetPayInfo() throws Exception {
@@ -31,18 +35,15 @@ public class WxMpPayServiceImplTest {
}
@Test
- public void testGetJSSDKPayResult() throws Exception {
-
- }
-
- @Test
- public void testGetJSSDKCallbackData() throws Exception {
-
- }
-
- @Test
- public void testRefundPay() throws Exception {
-
+ public void testRefund() throws Exception {
+ WxPayRefundRequest request = new WxPayRefundRequest();
+ request.setOutRefundNo("aaa");
+ request.setOutTradeNo("1111");
+ request.setTotalFee(1222);
+ request.setRefundFee(111);
+ File keyFile = new File("E:\\dlt.p12");
+ WxPayRefundResult result = this.wxService.getPayService().refund(request, keyFile);
+ System.err.println(result);
}
@Test
@@ -52,26 +53,63 @@ public class WxMpPayServiceImplTest {
@Test
public void testSendRedpack() throws Exception {
- WxSendRedpackRequest request = new WxSendRedpackRequest();
+ WxPaySendRedpackRequest request = new WxPaySendRedpackRequest();
request.setActName("abc");
request.setClientIp("aaa");
request.setMchBillno("aaaa");
request
.setReOpenid(((WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid());
- WxRedpackResult redpackResult = this.wxService.getPayService().sendRedpack(request);
+ File keyFile = new File("E:\\dlt.p12");
+ WxPaySendRedpackResult redpackResult = this.wxService.getPayService().sendRedpack(request, keyFile);
System.err.println(redpackResult);
}
/**
- * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#unifiedOrder(me.chanjar.weixin.mp.bean.pay.WxUnifiedOrderRequest)}.
- * @throws WxErrorException
+ * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#unifiedOrder(WxPayUnifiedOrderRequest)}.
*/
@Test
public void testUnifiedOrder() throws WxErrorException {
- WxUnifiedOrderResult result = this.wxService.getPayService()
- .unifiedOrder(WxUnifiedOrderRequest.builder().body("1111111")
+ WxPayUnifiedOrderResult result = this.wxService.getPayService()
+ .unifiedOrder(WxPayUnifiedOrderRequest.builder().body("1111111")
.totalFee(1).spbillCreateIp("111111").notifyURL("111111")
.tradeType("JSAPI").openid("122").outTradeNo("111111").build());
System.err.println(result);
}
+
+ /**
+ * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#queryOrder(String, String)} .
+ */
+ @Test
+ public final void testQueryOrder() throws WxErrorException {
+ //System.err.println(this.wxService.getPayService().queryOrder(null, null));
+ System.err.println(this.wxService.getPayService().queryOrder("11212121", null));
+ System.err.println(this.wxService.getPayService().queryOrder(null, "11111"));
+ }
+
+ /**
+ * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#closeOrder(String)} .
+ */
+ @Test
+ public final void testCloseOrder() throws WxErrorException {
+ System.err.println(this.wxService.getPayService().closeOrder("11212121"));
+ }
+
+ /**
+ * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#entPay(WxEntPayRequest, File)}.
+ */
+ @Test
+ public final void testEntPay() throws WxErrorException {
+ File keyFile = new File("E:\\dlt.p12");
+ WxEntPayRequest request = new WxEntPayRequest();
+ System.err.println(this.wxService.getPayService().entPay(request, keyFile));
+ }
+
+ /**
+ * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#queryEntPay(String, File)}.
+ */
+ @Test
+ public final void testQueryEntPay() throws WxErrorException {
+ File keyFile = new File("E:\\dlt.p12");
+ System.err.println(this.wxService.getPayService().queryEntPay("11212121", keyFile));
+ }
}
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrCodeServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrCodeServiceImplTest.java
index d2ed01da..4c53ac17 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrCodeServiceImplTest.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrCodeServiceImplTest.java
@@ -3,6 +3,7 @@ package me.chanjar.weixin.mp.api.impl;
import com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.ApiTestModule;
+import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
import org.testng.Assert;
import org.testng.annotations.Guice;
@@ -12,7 +13,7 @@ import java.io.File;
/**
* 测试用户相关的接口
- *
+ *
* @author chanjarster
*/
@Test(groups = "qrCodeAPI")
@@ -20,7 +21,7 @@ import java.io.File;
public class WxMpQrCodeServiceImplTest {
@Inject
- protected WxMpServiceImpl wxService;
+ protected WxMpService wxService;
public void testQrCodeCreateTmpTicket() throws WxErrorException {
WxMpQrCodeTicket ticket = this.wxService.getQrcodeService().qrCodeCreateTmpTicket(1, null);
@@ -44,7 +45,7 @@ public class WxMpQrCodeServiceImplTest {
Assert.assertNotNull(file);
System.out.println(file.getAbsolutePath());
}
-
+
public void testQrCodePictureUrl() throws WxErrorException {
WxMpQrCodeTicket ticket = this.wxService.getQrcodeService().qrCodeCreateLastTicket(1);
String url = this.wxService.getQrcodeService().qrCodePictureUrl(ticket.getTicket());
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java
index c108d575..c6b8689f 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java
@@ -1,27 +1,20 @@
package me.chanjar.weixin.mp.api.impl;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-import org.testng.Assert;
-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.exception.WxErrorException;
import me.chanjar.weixin.mp.api.ApiTestModule;
+import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage;
-import me.chanjar.weixin.mp.bean.WxMpTemplateData;
-import me.chanjar.weixin.mp.bean.WxMpTemplateMessage;
+import org.testng.Assert;
+import org.testng.annotations.Guice;
+import org.testng.annotations.Test;
@Test
@Guice(modules = ApiTestModule.class)
public class WxMpServiceImplTest {
@Inject
- private WxMpServiceImpl wxService;
+ private WxMpService wxService;
@Test
public void testCheckSignature() {
@@ -88,20 +81,6 @@ public class WxMpServiceImplTest {
Assert.fail("Not yet implemented");
}
- @Test(invocationCount = 100, threadPoolSize = 30)
- public void testTemplateSend() throws WxErrorException {
- SimpleDateFormat dateFormat = new SimpleDateFormat(
- "yyyy-MM-dd HH:mm:ss.SSS");
- WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService
- .getWxMpConfigStorage();
- WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
- .toUser(configStorage.getOpenid())
- .templateId(configStorage.getTemplateId()).build();
- templateMessage.addWxMpTemplateData(
- new WxMpTemplateData("first", dateFormat.format(new Date())));
- this.wxService.templateSend(templateMessage);
- }
-
@Test
public void testSetIndustry() {
Assert.fail("Not yet implemented");
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java
index 76685470..63609293 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java
@@ -3,6 +3,7 @@ package me.chanjar.weixin.mp.api.impl;
import com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.ApiTestModule;
+import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo;
import me.chanjar.weixin.mp.bean.store.WxMpStoreInfo;
import me.chanjar.weixin.mp.bean.store.WxMpStoreListResult;
@@ -15,7 +16,7 @@ import java.util.List;
import static org.junit.Assert.assertNotNull;
/**
- * @author binarywang(https://github.com/binarywang)
+ * @author binarywang(Binary Wang)
* Created by Binary Wang on 2016-09-23.
*
*/
@@ -23,13 +24,14 @@ import static org.junit.Assert.assertNotNull;
@Guice(modules = ApiTestModule.class)
public class WxMpStoreServiceImplTest {
@Inject
- private WxMpServiceImpl wxMpService;
+ private WxMpService wxMpService;
/**
* Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpStoreServiceImpl#add(me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo)}.
* @throws WxErrorException
*/
public void testAdd() throws WxErrorException {
+ this.wxMpService.getStoreService().add(WxMpStoreBaseInfo.builder().build());
this.wxMpService.getStoreService()
.add(WxMpStoreBaseInfo.builder().businessName("haha").branchName("abc")
.province("aaa").district("aaa").telephone("122").address("abc").categories(new String[] { "美食,江浙菜" })
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImplTest.java
new file mode 100644
index 00000000..9b50d5df
--- /dev/null
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImplTest.java
@@ -0,0 +1,83 @@
+package me.chanjar.weixin.mp.api.impl;
+
+import com.google.inject.Inject;
+import me.chanjar.weixin.common.exception.WxErrorException;
+import me.chanjar.weixin.mp.api.ApiTestModule;
+import me.chanjar.weixin.mp.api.WxMpService;
+import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage;
+import me.chanjar.weixin.mp.bean.template.WxMpTemplate;
+import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
+import me.chanjar.weixin.mp.bean.template.WxMpTemplateIndustry;
+import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
+import org.testng.Assert;
+import org.testng.annotations.Guice;
+import org.testng.annotations.Test;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+
+/**
+ *
+ * Created by Binary Wang on 2016-10-14.
+ * @author binarywang(Binary Wang)
+ *
+ */
+@Guice(modules = ApiTestModule.class)
+public class WxMpTemplateMsgServiceImplTest {
+ @Inject
+ protected WxMpService wxService;
+
+ @Test(invocationCount = 10, threadPoolSize = 10)
+ public void testSendTemplateMsg() throws WxErrorException {
+ SimpleDateFormat dateFormat = new SimpleDateFormat(
+ "yyyy-MM-dd HH:mm:ss.SSS");
+ WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService
+ .getWxMpConfigStorage();
+ WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
+ .toUser(configStorage.getOpenid())
+ .templateId(configStorage.getTemplateId()).build();
+ templateMessage.addWxMpTemplateData(
+ new WxMpTemplateData("first", dateFormat.format(new Date())));
+ String msgId = this.wxService.getTemplateMsgService().sendTemplateMsg(templateMessage);
+ Assert.assertNotNull(msgId);
+ System.out.println(msgId);
+ }
+
+ @Test
+ public void testGetIndustry() throws Exception {
+ final WxMpTemplateIndustry industry = this.wxService.getTemplateMsgService().getIndustry();
+ Assert.assertNotNull(industry);
+ System.out.println(industry);
+ }
+
+ @Test
+ public void testSetIndustry() throws Exception {
+ WxMpTemplateIndustry industry = new WxMpTemplateIndustry(new WxMpTemplateIndustry.Industry("1"),
+ new WxMpTemplateIndustry.Industry("04"));
+ boolean result = this.wxService.getTemplateMsgService().setIndustry(industry);
+ Assert.assertTrue(result);
+ }
+
+ @Test
+ public void testAddTemplate() throws Exception {
+ String result = this.wxService.getTemplateMsgService().addTemplate("TM00015");
+ Assert.assertNotNull(result);
+ System.err.println(result);
+ }
+
+ @Test
+ public void testGetAllPrivateTemplate() throws Exception {
+ List result = this.wxService.getTemplateMsgService().getAllPrivateTemplate();
+ Assert.assertNotNull(result);
+ System.err.println(result);
+ }
+
+ @Test
+ public void testDelPrivateTemplate() throws Exception {
+ String templateId = "RPcTe7-4BkU5A2J3imC6W0b4JbjEERcJg0whOMKJKIc";
+ boolean result = this.wxService.getTemplateMsgService().delPrivateTemplate(templateId);
+ Assert.assertTrue(result);
+ }
+
+}
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImplTest.java
index aebf6926..2bcc3aea 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImplTest.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImplTest.java
@@ -1,6 +1,7 @@
package me.chanjar.weixin.mp.api.impl;
import me.chanjar.weixin.mp.api.ApiTestModule;
+import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.bean.result.WxMpUserBlacklistGetResult;
import org.testng.Assert;
@@ -18,7 +19,7 @@ import java.util.List;
@Guice(modules = ApiTestModule.class)
public class WxMpUserBlacklistServiceImplTest {
@Inject
- protected WxMpServiceImpl wxService;
+ protected WxMpService wxService;
@Test
public void testGetBlacklist() throws Exception {
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImplTest.java
index 4242df10..02252800 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImplTest.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImplTest.java
@@ -4,6 +4,7 @@ package me.chanjar.weixin.mp.api.impl;
import java.util.ArrayList;
import java.util.List;
+import me.chanjar.weixin.mp.api.WxMpService;
import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Guice;
@@ -29,7 +30,7 @@ import me.chanjar.weixin.mp.bean.result.WxMpUserList;
public class WxMpUserServiceImplTest {
@Inject
- private WxMpServiceImpl wxService;
+ private WxMpService wxService;
private WxXmlMpInMemoryConfigStorage configProvider;
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java
index 9fc579c9..bca04a06 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java
@@ -2,6 +2,7 @@ package me.chanjar.weixin.mp.api.impl;
import java.util.List;
+import me.chanjar.weixin.mp.api.WxMpService;
import org.testng.Assert;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
@@ -15,14 +16,14 @@ import me.chanjar.weixin.mp.bean.tag.WxUserTag;
/**
*
- * @author binarywang(https://github.com/binarywang)
+ * @author binarywang(Binary Wang)
* Created by Binary Wang on 2016/9/2.
*/
@Test
@Guice(modules = ApiTestModule.class)
public class WxMpUserTagServiceImplTest {
@Inject
- protected WxMpServiceImpl wxService;
+ protected WxMpService wxService;
private Long tagId = 2L;
@@ -64,6 +65,14 @@ public class WxMpUserTagServiceImplTest {
Assert.assertNotNull(res);
}
+ @Test
+ public void testBatchTagging() throws Exception {
+ String[] openids = new String[]{((WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()};
+ boolean res = this.wxService.getUserTagService().batchTagging(this.tagId, openids);
+ System.out.println(res);
+ Assert.assertTrue(res);
+ }
+
@Test
public void testBatchUntagging() throws Exception {
String[] openids = new String[]{((WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()};
@@ -74,7 +83,7 @@ public class WxMpUserTagServiceImplTest {
@Test
public void testUserTagList() throws Exception {
- List res = this.wxService.getUserTagService().userTagList(
+ List res = this.wxService.getUserTagService().userTagList(
((WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid());
System.out.println(res);
Assert.assertNotNull(res);
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxRedpackResultTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxRedpackResultTest.java
deleted file mode 100644
index 5a5275d4..00000000
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxRedpackResultTest.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package me.chanjar.weixin.mp.bean;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import com.thoughtworks.xstream.XStream;
-
-import me.chanjar.weixin.common.util.xml.XStreamInitializer;
-import me.chanjar.weixin.mp.bean.pay.WxRedpackResult;
-
-public class WxRedpackResultTest {
-
- private XStream xstream;
-
- @Before
- public void setup() {
- this.xstream = XStreamInitializer.getInstance();
- this.xstream.processAnnotations(WxRedpackResult.class);
- }
-
- @Test public void loadSuccessResult() {
- final String successSample = "\n" +
- "\n" +
- "\n" +
- "\n" +
- "\n" +
- "\n" +
- "\n" +
- "10010404\n" +
- "\n" +
- "\n" +
- "1\n" +
- "100000000020150520314766074200\n" +
- "20150520102602\n" +
- "";
- WxRedpackResult wxMpRedpackResult = (WxRedpackResult) this.xstream.fromXML(successSample);
- assertEquals("SUCCESS", wxMpRedpackResult.getReturnCode());
- assertEquals("SUCCESS", wxMpRedpackResult.getResultCode());
- assertEquals("20150520102602", wxMpRedpackResult.getSendTime());
- }
-
- @Test public void loadFailureResult() {
- final String failureSample = "\n" +
- "\n" +
- "\n" +
- "\n" +
- "\n" +
- "\n" +
- "\n" +
- "10010404\n" +
- "\n" +
- "\n" +
- "1\n" +
- "";
- WxRedpackResult wxMpRedpackResult = (WxRedpackResult) this.xstream.fromXML(failureSample);
- assertEquals("FAIL", wxMpRedpackResult.getReturnCode());
- assertEquals("FAIL", wxMpRedpackResult.getResultCode());
- assertEquals("onqOjjmM1tad-3ROpncN-yUfa6uI", wxMpRedpackResult.getReOpenid());
- assertEquals(1, wxMpRedpackResult.getTotalAmount());
- }
-}
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxMpCustomMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/WxMpKefuMessageTest.java
similarity index 80%
rename from weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxMpCustomMessageTest.java
rename to weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/WxMpKefuMessageTest.java
index aa8de0df..9f19029e 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxMpCustomMessageTest.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/WxMpKefuMessageTest.java
@@ -1,54 +1,54 @@
-package me.chanjar.weixin.mp.bean;
+package me.chanjar.weixin.mp.bean.kefu;
import me.chanjar.weixin.common.api.WxConsts;
-import me.chanjar.weixin.mp.bean.WxMpCustomMessage.WxArticle;
+import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage.WxArticle;
import org.testng.Assert;
import org.testng.annotations.Test;
@Test
-public class WxMpCustomMessageTest {
+public class WxMpKefuMessageTest {
public void testTextReply() {
- WxMpCustomMessage reply = new WxMpCustomMessage();
+ WxMpKefuMessage reply = new WxMpKefuMessage();
reply.setToUser("OPENID");
reply.setMsgType(WxConsts.CUSTOM_MSG_TEXT);
reply.setContent("sfsfdsdf");
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}");
}
-
+
public void testTextBuild() {
- WxMpCustomMessage reply = WxMpCustomMessage.TEXT().toUser("OPENID").content("sfsfdsdf").build();
+ WxMpKefuMessage reply = WxMpKefuMessage.TEXT().toUser("OPENID").content("sfsfdsdf").build();
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}");
}
-
+
public void testImageReply() {
- WxMpCustomMessage reply = new WxMpCustomMessage();
+ WxMpKefuMessage reply = new WxMpKefuMessage();
reply.setToUser("OPENID");
reply.setMsgType(WxConsts.CUSTOM_MSG_IMAGE);
reply.setMediaId("MEDIA_ID");
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}");
}
-
+
public void testImageBuild() {
- WxMpCustomMessage reply = WxMpCustomMessage.IMAGE().toUser("OPENID").mediaId("MEDIA_ID").build();
+ WxMpKefuMessage reply = WxMpKefuMessage.IMAGE().toUser("OPENID").mediaId("MEDIA_ID").build();
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}");
}
-
+
public void testVoiceReply() {
- WxMpCustomMessage reply = new WxMpCustomMessage();
+ WxMpKefuMessage reply = new WxMpKefuMessage();
reply.setToUser("OPENID");
reply.setMsgType(WxConsts.CUSTOM_MSG_VOICE);
reply.setMediaId("MEDIA_ID");
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"voice\",\"voice\":{\"media_id\":\"MEDIA_ID\"}}");
}
-
+
public void testVoiceBuild() {
- WxMpCustomMessage reply = WxMpCustomMessage.VOICE().toUser("OPENID").mediaId("MEDIA_ID").build();
+ WxMpKefuMessage reply = WxMpKefuMessage.VOICE().toUser("OPENID").mediaId("MEDIA_ID").build();
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"voice\",\"voice\":{\"media_id\":\"MEDIA_ID\"}}");
}
-
+
public void testVideoReply() {
- WxMpCustomMessage reply = new WxMpCustomMessage();
+ WxMpKefuMessage reply = new WxMpKefuMessage();
reply.setToUser("OPENID");
reply.setMsgType(WxConsts.CUSTOM_MSG_VIDEO);
reply.setMediaId("MEDIA_ID");
@@ -57,14 +57,14 @@ public class WxMpCustomMessageTest {
reply.setDescription("DESCRIPTION");
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"video\",\"video\":{\"media_id\":\"MEDIA_ID\",\"thumb_media_id\":\"MEDIA_ID\",\"title\":\"TITLE\",\"description\":\"DESCRIPTION\"}}");
}
-
+
public void testVideoBuild() {
- WxMpCustomMessage reply = WxMpCustomMessage.VIDEO().toUser("OPENID").title("TITLE").mediaId("MEDIA_ID").thumbMediaId("MEDIA_ID").description("DESCRIPTION").build();
+ WxMpKefuMessage reply = WxMpKefuMessage.VIDEO().toUser("OPENID").title("TITLE").mediaId("MEDIA_ID").thumbMediaId("MEDIA_ID").description("DESCRIPTION").build();
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"video\",\"video\":{\"media_id\":\"MEDIA_ID\",\"thumb_media_id\":\"MEDIA_ID\",\"title\":\"TITLE\",\"description\":\"DESCRIPTION\"}}");
}
-
+
public void testMusicReply() {
- WxMpCustomMessage reply = new WxMpCustomMessage();
+ WxMpKefuMessage reply = new WxMpKefuMessage();
reply.setToUser("OPENID");
reply.setMsgType(WxConsts.CUSTOM_MSG_MUSIC);
reply.setThumbMediaId("MEDIA_ID");
@@ -74,9 +74,9 @@ public class WxMpCustomMessageTest {
reply.setHqMusicUrl("HQ_MUSIC_URL");
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"music\",\"music\":{\"title\":\"TITLE\",\"description\":\"DESCRIPTION\",\"thumb_media_id\":\"MEDIA_ID\",\"musicurl\":\"MUSIC_URL\",\"hqmusicurl\":\"HQ_MUSIC_URL\"}}");
}
-
+
public void testMusicBuild() {
- WxMpCustomMessage reply = WxMpCustomMessage.MUSIC()
+ WxMpKefuMessage reply = WxMpKefuMessage.MUSIC()
.toUser("OPENID")
.title("TITLE")
.thumbMediaId("MEDIA_ID")
@@ -86,19 +86,19 @@ public class WxMpCustomMessageTest {
.build();
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"music\",\"music\":{\"title\":\"TITLE\",\"description\":\"DESCRIPTION\",\"thumb_media_id\":\"MEDIA_ID\",\"musicurl\":\"MUSIC_URL\",\"hqmusicurl\":\"HQ_MUSIC_URL\"}}");
}
-
+
public void testNewsReply() {
- WxMpCustomMessage reply = new WxMpCustomMessage();
+ WxMpKefuMessage reply = new WxMpKefuMessage();
reply.setToUser("OPENID");
reply.setMsgType(WxConsts.CUSTOM_MSG_NEWS);
-
+
WxArticle article1 = new WxArticle();
article1.setUrl("URL");
article1.setPicUrl("PIC_URL");
article1.setDescription("Is Really A Happy Day");
article1.setTitle("Happy Day");
reply.getArticles().add(article1);
-
+
WxArticle article2 = new WxArticle();
article2.setUrl("URL");
article2.setPicUrl("PIC_URL");
@@ -106,26 +106,26 @@ public class WxMpCustomMessageTest {
article2.setTitle("Happy Day");
reply.getArticles().add(article2);
-
+
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"news\",\"news\":{\"articles\":[{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"},{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"}]}}");
}
-
+
public void testNewsBuild() {
WxArticle article1 = new WxArticle();
article1.setUrl("URL");
article1.setPicUrl("PIC_URL");
article1.setDescription("Is Really A Happy Day");
article1.setTitle("Happy Day");
-
+
WxArticle article2 = new WxArticle();
article2.setUrl("URL");
article2.setPicUrl("PIC_URL");
article2.setDescription("Is Really A Happy Day");
article2.setTitle("Happy Day");
- WxMpCustomMessage reply = WxMpCustomMessage.NEWS().toUser("OPENID").addArticle(article1).addArticle(article2).build();
+ WxMpKefuMessage reply = WxMpKefuMessage.NEWS().toUser("OPENID").addArticle(article1).addArticle(article2).build();
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"news\",\"news\":{\"articles\":[{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"},{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"}]}}");
}
-
+
}
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxMpXmlMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessageTest.java
similarity index 99%
rename from weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxMpXmlMessageTest.java
rename to weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessageTest.java
index 87d8428b..8f49ce99 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxMpXmlMessageTest.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessageTest.java
@@ -1,4 +1,4 @@
-package me.chanjar.weixin.mp.bean;
+package me.chanjar.weixin.mp.bean.message;
import me.chanjar.weixin.common.api.WxConsts;
import org.testng.Assert;
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxMpXmlOutImageMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutImageMessageTest.java
similarity index 96%
rename from weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxMpXmlOutImageMessageTest.java
rename to weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutImageMessageTest.java
index 9c92cab8..3addedb5 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxMpXmlOutImageMessageTest.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutImageMessageTest.java
@@ -1,4 +1,4 @@
-package me.chanjar.weixin.mp.bean;
+package me.chanjar.weixin.mp.bean.message;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -12,7 +12,7 @@ public class WxMpXmlOutImageMessageTest {
m.setCreateTime(1122l);
m.setFromUserName("from");
m.setToUserName("to");
-
+
String expected = ""
+ ""
+ ""
@@ -23,7 +23,7 @@ public class WxMpXmlOutImageMessageTest {
System.out.println(m.toXml());
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", ""));
}
-
+
public void testBuild() {
WxMpXmlOutImageMessage m = WxMpXmlOutMessage.IMAGE().mediaId("ddfefesfsdfef").fromUser("from").toUser("to").build();
String expected = ""
@@ -38,11 +38,11 @@ public class WxMpXmlOutImageMessageTest {
m
.toXml()
.replaceAll("\\s", "")
- .replaceAll(".*?", ""),
+ .replaceAll(".*?", ""),
expected
.replaceAll("\\s", "")
.replaceAll(".*?", "")
);
-
+
}
}
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutMusicMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMusicMessageTest.java
similarity index 94%
rename from weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutMusicMessageTest.java
rename to weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMusicMessageTest.java
index 4397a677..3e7a96f0 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutMusicMessageTest.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMusicMessageTest.java
@@ -1,10 +1,10 @@
-package me.chanjar.weixin.mp.bean;
+package me.chanjar.weixin.mp.bean.message;
import org.testng.Assert;
import org.testng.annotations.Test;
@Test
-public class WxXmlOutMusicMessageTest {
+public class WxMpXmlOutMusicMessageTest {
public void test() {
WxMpXmlOutMusicMessage m = new WxMpXmlOutMusicMessage();
@@ -16,7 +16,7 @@ public class WxXmlOutMusicMessageTest {
m.setCreateTime(1122l);
m.setFromUserName("fromUser");
m.setToUserName("toUser");
-
+
String expected = ""
+ ""
+ ""
@@ -33,7 +33,7 @@ public class WxXmlOutMusicMessageTest {
System.out.println(m.toXml());
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", ""));
}
-
+
public void testBuild() {
WxMpXmlOutMusicMessage m = WxMpXmlOutMessage.MUSIC()
.fromUser("fromUser")
@@ -62,11 +62,11 @@ public class WxXmlOutMusicMessageTest {
m
.toXml()
.replaceAll("\\s", "")
- .replaceAll(".*?", ""),
+ .replaceAll(".*?", ""),
expected
.replaceAll("\\s", "")
.replaceAll(".*?", "")
);
}
-
+
}
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutNewsMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutNewsMessageTest.java
similarity index 95%
rename from weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutNewsMessageTest.java
rename to weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutNewsMessageTest.java
index 5e2da0b0..60d8571a 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutNewsMessageTest.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutNewsMessageTest.java
@@ -1,17 +1,17 @@
-package me.chanjar.weixin.mp.bean;
+package me.chanjar.weixin.mp.bean.message;
import org.testng.Assert;
import org.testng.annotations.Test;
@Test
-public class WxXmlOutNewsMessageTest {
+public class WxMpXmlOutNewsMessageTest {
public void test() {
WxMpXmlOutNewsMessage m = new WxMpXmlOutNewsMessage();
m.setCreateTime(1122l);
m.setFromUserName("fromUser");
m.setToUserName("toUser");
-
+
WxMpXmlOutNewsMessage.Item item = new WxMpXmlOutNewsMessage.Item();
item.setDescription("description");
item.setPicUrl("picUrl");
@@ -43,14 +43,14 @@ public class WxXmlOutNewsMessageTest {
System.out.println(m.toXml());
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", ""));
}
-
+
public void testBuild() {
WxMpXmlOutNewsMessage.Item item = new WxMpXmlOutNewsMessage.Item();
item.setDescription("description");
item.setPicUrl("picUrl");
item.setTitle("title");
item.setUrl("url");
-
+
WxMpXmlOutNewsMessage m = WxMpXmlOutMessage.NEWS()
.fromUser("fromUser")
.toUser("toUser")
@@ -83,11 +83,11 @@ public class WxXmlOutNewsMessageTest {
m
.toXml()
.replaceAll("\\s", "")
- .replaceAll(".*?", ""),
+ .replaceAll(".*?", ""),
expected
.replaceAll("\\s", "")
.replaceAll(".*?", "")
);
}
-
+
}
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutTextMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTextMessageTest.java
similarity index 90%
rename from weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutTextMessageTest.java
rename to weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTextMessageTest.java
index 2a752051..56658967 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutTextMessageTest.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTextMessageTest.java
@@ -1,10 +1,10 @@
-package me.chanjar.weixin.mp.bean;
+package me.chanjar.weixin.mp.bean.message;
import org.testng.Assert;
import org.testng.annotations.Test;
@Test
-public class WxXmlOutTextMessageTest {
+public class WxMpXmlOutTextMessageTest {
public void test() {
WxMpXmlOutTextMessage m = new WxMpXmlOutTextMessage();
@@ -12,7 +12,7 @@ public class WxXmlOutTextMessageTest {
m.setCreateTime(1122l);
m.setFromUserName("from");
m.setToUserName("to");
-
+
String expected = ""
+ ""
+ ""
@@ -23,7 +23,7 @@ public class WxXmlOutTextMessageTest {
System.out.println(m.toXml());
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", ""));
}
-
+
public void testBuild() {
WxMpXmlOutTextMessage m = WxMpXmlOutMessage.TEXT().content("content").fromUser("from").toUser("to").build();
String expected = ""
@@ -38,13 +38,13 @@ public class WxXmlOutTextMessageTest {
m
.toXml()
.replaceAll("\\s", "")
- .replaceAll(".*?", ""),
+ .replaceAll(".*?", ""),
expected
.replaceAll("\\s", "")
.replaceAll(".*?", "")
);
-
+
}
-
+
}
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxMpXmlOutTransferCustomerServiceMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTransferKefuMessageTest.java
similarity index 83%
rename from weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxMpXmlOutTransferCustomerServiceMessageTest.java
rename to weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTransferKefuMessageTest.java
index 012a0986..222f563f 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxMpXmlOutTransferCustomerServiceMessageTest.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutTransferKefuMessageTest.java
@@ -1,4 +1,4 @@
-package me.chanjar.weixin.mp.bean;
+package me.chanjar.weixin.mp.bean.message;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -6,10 +6,10 @@ import org.testng.annotations.Test;
/**
* Created by ben on 2015/12/29.
*/
-public class WxMpXmlOutTransferCustomerServiceMessageTest {
+public class WxMpXmlOutTransferKefuMessageTest {
@Test
public void test() {
- WxMpXmlOutTransferCustomerServiceMessage m = new WxMpXmlOutTransferCustomerServiceMessage();
+ WxMpXmlOutTransferKefuMessage m = new WxMpXmlOutTransferKefuMessage();
m.setCreateTime(1399197672L);
m.setFromUserName("fromuser");
m.setToUserName("touser");
@@ -32,7 +32,7 @@ public class WxMpXmlOutTransferCustomerServiceMessageTest {
"" +
"" +
"";
- WxMpXmlOutTransferCustomerServiceMessage.TransInfo transInfo = new WxMpXmlOutTransferCustomerServiceMessage.TransInfo();
+ WxMpXmlOutTransferKefuMessage.TransInfo transInfo = new WxMpXmlOutTransferKefuMessage.TransInfo();
transInfo.setKfAccount("test1@test");
m.setTransInfo(transInfo);
System.out.println(m.toXml());
@@ -41,7 +41,7 @@ public class WxMpXmlOutTransferCustomerServiceMessageTest {
@Test
public void testBuild() {
- WxMpXmlOutTransferCustomerServiceMessage m = WxMpXmlOutMessage.TRANSFER_CUSTOMER_SERVICE().fromUser("fromuser").toUser("touser").build();
+ WxMpXmlOutTransferKefuMessage m = WxMpXmlOutMessage.TRANSFER_CUSTOMER_SERVICE().fromUser("fromuser").toUser("touser").build();
m.setCreateTime(1399197672L);
String expected = "" +
"" +
@@ -67,4 +67,4 @@ public class WxMpXmlOutTransferCustomerServiceMessageTest {
System.out.println(m.toXml());
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", ""));
}
-}
\ No newline at end of file
+}
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutVideoMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVideoMessageTest.java
similarity index 92%
rename from weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutVideoMessageTest.java
rename to weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVideoMessageTest.java
index 19fbe62a..0c53b28a 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutVideoMessageTest.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVideoMessageTest.java
@@ -1,10 +1,10 @@
-package me.chanjar.weixin.mp.bean;
+package me.chanjar.weixin.mp.bean.message;
import org.testng.Assert;
import org.testng.annotations.Test;
@Test
-public class WxXmlOutVideoMessageTest {
+public class WxMpXmlOutVideoMessageTest {
public void test() {
WxMpXmlOutVideoMessage m = new WxMpXmlOutVideoMessage();
@@ -14,7 +14,7 @@ public class WxXmlOutVideoMessageTest {
m.setCreateTime(1122l);
m.setFromUserName("fromUser");
m.setToUserName("toUser");
-
+
String expected = ""
+ ""
+ ""
@@ -29,7 +29,7 @@ public class WxXmlOutVideoMessageTest {
System.out.println(m.toXml());
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", ""));
}
-
+
public void testBuild() {
WxMpXmlOutVideoMessage m = WxMpXmlOutMessage.VIDEO()
.mediaId("media_id")
@@ -54,11 +54,11 @@ public class WxXmlOutVideoMessageTest {
m
.toXml()
.replaceAll("\\s", "")
- .replaceAll(".*?", ""),
+ .replaceAll(".*?", ""),
expected
.replaceAll("\\s", "")
.replaceAll(".*?", "")
);
}
-
+
}
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutVoiceMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVoiceMessageTest.java
similarity index 90%
rename from weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutVoiceMessageTest.java
rename to weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVoiceMessageTest.java
index 0eb848cd..34314390 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutVoiceMessageTest.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutVoiceMessageTest.java
@@ -1,10 +1,10 @@
-package me.chanjar.weixin.mp.bean;
+package me.chanjar.weixin.mp.bean.message;
import org.testng.Assert;
import org.testng.annotations.Test;
@Test
-public class WxXmlOutVoiceMessageTest {
+public class WxMpXmlOutVoiceMessageTest {
public void test() {
WxMpXmlOutVoiceMessage m = new WxMpXmlOutVoiceMessage();
@@ -12,7 +12,7 @@ public class WxXmlOutVoiceMessageTest {
m.setCreateTime(1122l);
m.setFromUserName("from");
m.setToUserName("to");
-
+
String expected = ""
+ ""
+ ""
@@ -23,7 +23,7 @@ public class WxXmlOutVoiceMessageTest {
System.out.println(m.toXml());
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", ""));
}
-
+
public void testBuild() {
WxMpXmlOutVoiceMessage m = WxMpXmlOutMessage.VOICE().mediaId("ddfefesfsdfef").fromUser("from").toUser("to").build();
String expected = ""
@@ -38,11 +38,11 @@ public class WxXmlOutVoiceMessageTest {
m
.toXml()
.replaceAll("\\s", "")
- .replaceAll(".*?", ""),
+ .replaceAll(".*?", ""),
expected
.replaceAll("\\s", "")
.replaceAll(".*?", "")
);
}
-
+
}
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/WxSendRedpackRequestTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/WxSendRedpackRequestTest.java
deleted file mode 100644
index feb50c5a..00000000
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/WxSendRedpackRequestTest.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package me.chanjar.weixin.mp.bean.pay;
-
-import java.lang.reflect.Field;
-import java.util.Map.Entry;
-
-import org.joor.Reflect;
-import org.testng.annotations.Test;
-
-import com.thoughtworks.xstream.annotations.XStreamAlias;
-
-@Test
-public class WxSendRedpackRequestTest {
-
- public void test() throws NoSuchFieldException, SecurityException {
-
- WxSendRedpackRequest request = new WxSendRedpackRequest();
- request.setMchBillno("123");
- request.setActName("ab");
- for (Entry entry : Reflect.on(request).fields().entrySet()) {
- Reflect reflect = entry.getValue();
- if (reflect.get() == null) {
- continue;
- }
-
- Field field = WxSendRedpackRequest.class.getDeclaredField(entry.getKey());
- if (field.isAnnotationPresent(XStreamAlias.class)) {
- System.err.println(reflect.get() + " = " + field.getAnnotation(XStreamAlias.class).value());
- }
- }
-
- }
-
-}
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPaySendRedpackResultTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPaySendRedpackResultTest.java
new file mode 100644
index 00000000..a07ec972
--- /dev/null
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/pay/result/WxPaySendRedpackResultTest.java
@@ -0,0 +1,61 @@
+package me.chanjar.weixin.mp.bean.pay.result;
+
+import com.thoughtworks.xstream.XStream;
+import me.chanjar.weixin.common.util.xml.XStreamInitializer;
+import org.testng.Assert;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+public class WxPaySendRedpackResultTest {
+
+ private XStream xstream;
+
+ @BeforeTest
+ public void setup() {
+ this.xstream = XStreamInitializer.getInstance();
+ this.xstream.processAnnotations(WxPaySendRedpackResult.class);
+ }
+
+ @Test
+ public void loadSuccessResult() {
+ final String successSample = "\n" +
+ "\n" +
+ "\n" +
+ "\n" +
+ "\n" +
+ "\n" +
+ "\n" +
+ "10010404\n" +
+ "\n" +
+ "\n" +
+ "1\n" +
+ "100000000020150520314766074200\n" +
+ "20150520102602\n" +
+ "";
+ WxPaySendRedpackResult wxMpRedpackResult = (WxPaySendRedpackResult) this.xstream.fromXML(successSample);
+ Assert.assertEquals("SUCCESS", wxMpRedpackResult.getReturnCode());
+ Assert.assertEquals("SUCCESS", wxMpRedpackResult.getResultCode());
+ Assert.assertEquals("20150520102602", wxMpRedpackResult.getSendTime());
+ }
+
+ @Test
+ public void loadFailureResult() {
+ final String failureSample = "\n" +
+ "\n" +
+ "\n" +
+ "\n" +
+ "\n" +
+ "\n" +
+ "\n" +
+ "10010404\n" +
+ "\n" +
+ "\n" +
+ "1\n" +
+ "";
+ WxPaySendRedpackResult wxMpRedpackResult = (WxPaySendRedpackResult) this.xstream.fromXML(failureSample);
+ Assert.assertEquals("FAIL", wxMpRedpackResult.getReturnCode());
+ Assert.assertEquals("FAIL", wxMpRedpackResult.getResultCode());
+ Assert.assertEquals("onqOjjmM1tad-3ROpncN-yUfa6uI", wxMpRedpackResult.getReOpenid());
+ Assert.assertEquals(1, wxMpRedpackResult.getTotalAmount());
+ }
+}
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoGuessNumberHandler.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoGuessNumberHandler.java
index f35b3b87..69636d0b 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoGuessNumberHandler.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoGuessNumberHandler.java
@@ -10,9 +10,9 @@ import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
import me.chanjar.weixin.mp.api.WxMpMessageMatcher;
import me.chanjar.weixin.mp.api.WxMpService;
-import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
-import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
-import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
+import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
+import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
+import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
public class DemoGuessNumberHandler implements WxMpMessageHandler, WxMpMessageMatcher {
@@ -52,19 +52,19 @@ public class DemoGuessNumberHandler implements WxMpMessageHandler, WxMpMessageMa
protected void letsGo(WxMpXmlMessage wxMessage, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
WxSession session = sessionManager.getSession(wxMessage.getFromUser());
if (session.getAttribute("guessing") == null) {
- WxMpCustomMessage m = WxMpCustomMessage
+ WxMpKefuMessage m = WxMpKefuMessage
.TEXT()
.toUser(wxMessage.getFromUser())
.content("请猜一个100以内的数字")
.build();
- wxMpService.getKefuService().customMessageSend(m);
+ wxMpService.getKefuService().sendKefuMessage(m);
} else {
- WxMpCustomMessage m = WxMpCustomMessage
+ WxMpKefuMessage m = WxMpKefuMessage
.TEXT()
.toUser(wxMessage.getFromUser())
.content("放弃了吗?那请重新猜一个100以内的数字")
.build();
- wxMpService.getKefuService().customMessageSend(m);
+ wxMpService.getKefuService().sendKefuMessage(m);
}
session.setAttribute("guessing", Boolean.TRUE);
@@ -87,28 +87,28 @@ public class DemoGuessNumberHandler implements WxMpMessageHandler, WxMpMessageMa
int answer = (Integer) session.getAttribute("number");
int guessNumber = Integer.valueOf(wxMessage.getContent());
if (guessNumber < answer) {
- WxMpCustomMessage m = WxMpCustomMessage
+ WxMpKefuMessage m = WxMpKefuMessage
.TEXT()
.toUser(wxMessage.getFromUser())
.content("小了")
.build();
- wxMpService.getKefuService().customMessageSend(m);
+ wxMpService.getKefuService().sendKefuMessage(m);
} else if (guessNumber > answer) {
- WxMpCustomMessage m = WxMpCustomMessage
+ WxMpKefuMessage m = WxMpKefuMessage
.TEXT()
.toUser(wxMessage.getFromUser())
.content("大了")
.build();
- wxMpService.getKefuService().customMessageSend(m);
+ wxMpService.getKefuService().sendKefuMessage(m);
} else {
- WxMpCustomMessage m = WxMpCustomMessage
+ WxMpKefuMessage m = WxMpKefuMessage
.TEXT()
.toUser(wxMessage.getFromUser())
.content("Bingo!")
.build();
session.removeAttribute("guessing");
- wxMpService.getKefuService().customMessageSend(m);
+ wxMpService.getKefuService().sendKefuMessage(m);
}
}
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoImageHandler.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoImageHandler.java
index cd733210..145a0130 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoImageHandler.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoImageHandler.java
@@ -6,11 +6,10 @@ import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
import me.chanjar.weixin.mp.api.WxMpService;
-import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
-import me.chanjar.weixin.mp.bean.WxMpXmlOutImageMessage;
-import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
+import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
+import me.chanjar.weixin.mp.bean.message.WxMpXmlOutImageMessage;
+import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
-import java.io.IOException;
import java.util.Map;
public class DemoImageHandler implements WxMpMessageHandler {
@@ -30,9 +29,8 @@ public class DemoImageHandler implements WxMpMessageHandler {
return m;
} catch (WxErrorException e) {
e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
}
+
return null;
}
}
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoLogHandler.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoLogHandler.java
index 5245bc03..8e38b3f7 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoLogHandler.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoLogHandler.java
@@ -3,8 +3,8 @@ package me.chanjar.weixin.mp.demo;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
import me.chanjar.weixin.mp.api.WxMpService;
-import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
-import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
+import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
+import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import java.util.Map;
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoOAuth2Handler.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoOAuth2Handler.java
index 5dc5437d..82046452 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoOAuth2Handler.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoOAuth2Handler.java
@@ -4,8 +4,8 @@ import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
import me.chanjar.weixin.mp.api.WxMpService;
-import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
-import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
+import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
+import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import java.util.Map;
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoTextHandler.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoTextHandler.java
index 9ee15a28..5934eff2 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoTextHandler.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoTextHandler.java
@@ -3,9 +3,9 @@ package me.chanjar.weixin.mp.demo;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
import me.chanjar.weixin.mp.api.WxMpService;
-import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
-import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
-import me.chanjar.weixin.mp.bean.WxMpXmlOutTextMessage;
+import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
+import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
+import me.chanjar.weixin.mp.bean.message.WxMpXmlOutTextMessage;
import java.util.Map;
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpEndpointServlet.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpEndpointServlet.java
index d052af6c..4a6fd85b 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpEndpointServlet.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpEndpointServlet.java
@@ -1,18 +1,16 @@
package me.chanjar.weixin.mp.demo;
-import java.io.IOException;
+import me.chanjar.weixin.mp.api.WxMpConfigStorage;
+import me.chanjar.weixin.mp.api.WxMpMessageRouter;
+import me.chanjar.weixin.mp.api.WxMpService;
+import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
+import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
+import org.apache.commons.lang3.StringUtils;
-import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-
-import me.chanjar.weixin.common.util.StringUtils;
-import me.chanjar.weixin.mp.api.WxMpConfigStorage;
-import me.chanjar.weixin.mp.api.WxMpMessageRouter;
-import me.chanjar.weixin.mp.api.WxMpService;
-import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
-import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
+import java.io.IOException;
/**
* @author Daniel Qian
@@ -33,7 +31,7 @@ public class WxMpEndpointServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
+ throws IOException {
response.setContentType("text/html;charset=utf-8");
response.setStatus(HttpServletResponse.SC_OK);
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpOAuth2Servlet.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpOAuth2Servlet.java
index 4008e1fb..8eeb9052 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpOAuth2Servlet.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpOAuth2Servlet.java
@@ -2,7 +2,6 @@ package me.chanjar.weixin.mp.demo;
import java.io.IOException;
-import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -23,7 +22,7 @@ public class WxMpOAuth2Servlet extends HttpServlet {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
+ throws IOException {
response.setContentType("text/html;charset=utf-8");
response.setStatus(HttpServletResponse.SC_OK);
diff --git a/weixin-java-mp/src/test/resources/test-config.sample.xml b/weixin-java-mp/src/test/resources/test-config.sample.xml
index ad46a19e..2bbc8d8e 100644
--- a/weixin-java-mp/src/test/resources/test-config.sample.xml
+++ b/weixin-java-mp/src/test/resources/test-config.sample.xml
@@ -6,6 +6,8 @@
可以不填写
可以不填写
某个加你公众号的用户的openId
+ 微信商户平台ID
+ 商户平台设置的API密钥
模版消息的模版ID
网页授权获取用户信息回调地址
网页应用授权登陆回调地址
diff --git a/weixin-java-mp/src/test/resources/testng.xml b/weixin-java-mp/src/test/resources/testng.xml
index 6d5310ce..d1499983 100644
--- a/weixin-java-mp/src/test/resources/testng.xml
+++ b/weixin-java-mp/src/test/resources/testng.xml
@@ -17,14 +17,14 @@
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
diff --git a/weixin-java-osgi/pom.xml b/weixin-java-osgi/pom.xml
new file mode 100644
index 00000000..7f4a5973
--- /dev/null
+++ b/weixin-java-osgi/pom.xml
@@ -0,0 +1,136 @@
+
+
+ 4.0.0
+
+ com.github.binarywang
+ weixin-java-parent
+ 2.3.0
+
+
+ weixin-java-osgi
+ bundle
+ WeiXin Java Tools - OSGI
+ 微信公众号Java SDK OSGI
+
+
+
+ org.apache.servicemix.bundles
+ org.apache.servicemix.bundles.xmlpull
+ 1.1.3.1_2
+
+
+ org.apache.servicemix.bundles
+ org.apache.servicemix.bundles.xpp3
+ 1.1.4c_7
+
+
+ com.thoughtworks.xstream
+ xstream
+ 1.4.7
+ provided
+
+
+ xmlpull
+ xmlpull
+
+
+ xpp3
+ xpp3_min
+
+
+
+
+ org.apache.httpcomponents
+ httpcore
+ 4.4.1
+ provided
+
+
+ org.apache.httpcomponents
+ httpclient
+ ${httpclient.version}
+ provided
+
+
+ org.apache.httpcomponents
+ httpmime
+ ${httpclient.version}
+ provided
+
+
+ com.github.binarywang
+ weixin-java-common
+ ${project.version}
+ provided
+
+
+ com.github.binarywang
+ weixin-java-cp
+ ${project.version}
+ provided
+
+
+ com.github.binarywang
+ weixin-java-mp
+ ${project.version}
+ provided
+
+
+
+
+
+
+ org.apache.felix
+ maven-bundle-plugin
+ 3.2.0
+ true
+
+
+
+ weixin-java-common;inline=true
+ ,weixin-java-cp;inline=true
+ ,weixin-java-mp;inline=true
+ ,httpcore;inline=true
+ ,httpclient;inline=true
+ ,httpmime;inline=true
+ ,xstream;inline=true
+
+ me.chanjar.weixin.*
+
+ !org.apache.commons.logging
+ ,com.bea.xml.stream;resolution:=optional
+ ,com.ctc.wstx.stax;resolution:=optional
+ ,javax.xml.namespace;resolution:=optional
+ ,javax.xml.stream;resolution:=optional,
+ ,net.sf.cglib.proxy;resolution:=optional
+ ,nu.xom;resolution:=optional
+ ,org.codehaus.jettison;version="[1.2,2)";resolution:=optional
+ ,org.codehaus.jettison.mapped;version="[1.2,2)";resolution:=optional
+ ,org.dom4j;resolution:=optional
+ ,org.dom4j.io;resolution:=optional
+ ,org.dom4j.tree;resolution:=op
+ tional,org.jdom;resolution:=optional
+ ,org.jdom.input;resolution:=optional
+ ,org.jdom2;resolution:=optional
+ ,org.jdom2.input;resolution:=optional
+ ,org.joda.time;version="[1.6,2)";resolution:=optional
+ ,org.joda.time.format;version="[1.6,2)";resolution:=optional
+ ,org.kxml2.io;resolution:=optional
+ ,org.w3c.dom;resolution:=optional
+ ,*
+
+
+
+
+ org.apache.felix
+ org.apache.felix.dependencymanager.annotation
+ 4.1.0
+
+
+
+
+
+
+