Browse Source

整理及重构

master
Daniel Qian 10 years ago
parent
commit
a8f5d07ff3
100 changed files with 729 additions and 532 deletions
  1. +62
    -54
      pom.xml
  2. +68
    -0
      weixin-java-common/pom.xml
  3. +3
    -3
      weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxAccessToken.java
  4. +4
    -4
      weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxMenu.java
  5. +10
    -3
      weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxError.java
  6. +6
    -6
      weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxMediaUploadResult.java
  7. +1
    -1
      weixin-java-common/src/main/java/me/chanjar/weixin/common/exception/WxErrorException.java
  8. +5
    -5
      weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/ByteGroup.java
  9. +5
    -5
      weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/PKCS7Encoder.java
  10. +1
    -1
      weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/SHA1.java
  11. +22
    -41
      weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/WxCryptUtil.java
  12. +1
    -1
      weixin-java-common/src/main/java/me/chanjar/weixin/common/util/fs/FileUtils.java
  13. +1
    -1
      weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/InputStreamResponseHandler.java
  14. +12
    -10
      weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MediaDownloadRequestExecutor.java
  15. +3
    -3
      weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MediaUploadRequestExecutor.java
  16. +2
    -2
      weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/RequestExecutor.java
  17. +2
    -2
      weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/SimpleGetRequestExecutor.java
  18. +2
    -2
      weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/SimplePostRequestExecutor.java
  19. +1
    -1
      weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/Utf8ResponseHandler.java
  20. +1
    -1
      weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/GsonHelper.java
  21. +2
    -2
      weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxAccessTokenAdapter.java
  22. +2
    -2
      weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxErrorAdapter.java
  23. +26
    -0
      weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxGsonBuilder.java
  24. +2
    -2
      weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMediaUploadResultAdapter.java
  25. +3
    -3
      weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java
  26. +1
    -1
      weixin-java-common/src/main/java/me/chanjar/weixin/common/util/xml/AdapterCDATA.java
  27. +1
    -1
      weixin-java-common/src/main/java/me/chanjar/weixin/common/util/xml/MediaIdMarshaller.java
  28. +0
    -1
      weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxAccessTokenTest.java
  29. +2
    -3
      weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxErrorTest.java
  30. +2
    -4
      weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxMenuTest.java
  31. +3
    -3
      weixin-java-common/src/test/java/me/chanjar/weixin/common/util/crypto/WxCryptUtilTest.java
  32. +12
    -0
      weixin-java-common/src/test/resources/testng.xml
  33. +0
    -0
      weixin-java-cp/LICENSE
  34. +46
    -0
      weixin-java-cp/README.md
  35. +73
    -0
      weixin-java-cp/pom.xml
  36. +2
    -2
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpConfigStorage.java
  37. +1
    -4
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpConsts.java
  38. +4
    -4
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpInMemoryConfigStorage.java
  39. +3
    -3
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageHandler.java
  40. +2
    -2
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageInterceptor.java
  41. +55
    -41
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageRouter.java
  42. +10
    -9
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java
  43. +20
    -19
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java
  44. +2
    -2
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpDepart.java
  45. +9
    -9
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMessage.java
  46. +2
    -9
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTag.java
  47. +2
    -3
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java
  48. +18
    -19
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlMessage.java
  49. +3
    -3
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutImageMessage.java
  50. +8
    -12
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutMessage.java
  51. +3
    -3
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutMewsMessage.java
  52. +3
    -3
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutTextMessage.java
  53. +3
    -3
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVideoMessage.java
  54. +3
    -3
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVoiceMessage.java
  55. +2
    -2
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/BaseBuilder.java
  56. +3
    -3
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/FileBuilder.java
  57. +3
    -3
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/ImageBuilder.java
  58. +3
    -3
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/NewsBuilder.java
  59. +3
    -3
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/TextBuilder.java
  60. +3
    -3
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/VideoBuilder.java
  61. +3
    -3
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/VoiceBuilder.java
  62. +2
    -2
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/BaseBuilder.java
  63. +2
    -2
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/ImageBuilder.java
  64. +3
    -3
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/NewsBuilder.java
  65. +2
    -2
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/TextBuilder.java
  66. +2
    -2
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/VideoBuilder.java
  67. +2
    -2
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/VoiceBuilder.java
  68. +43
    -0
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/crypto/WxCpCryptUtil.java
  69. +3
    -3
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpDepartGsonAdapter.java
  70. +5
    -7
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpGsonBuilder.java
  71. +5
    -5
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpMessageGsonAdapter.java
  72. +3
    -7
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpTagGsonAdapter.java
  73. +3
    -3
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java
  74. +2
    -2
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/xml/XmlTransformer.java
  75. +3
    -3
      weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/ApiTestModule.java
  76. +2
    -2
      weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBaseAPITest.java
  77. +3
    -3
      weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpDepartAPITest.java
  78. +3
    -3
      weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMediaAPITest.java
  79. +4
    -4
      weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageAPITest.java
  80. +3
    -3
      weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageRouterTest.java
  81. +5
    -5
      weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpTagAPITest.java
  82. +4
    -4
      weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpUserAPITest.java
  83. +8
    -8
      weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxMenuAPITest.java
  84. +3
    -3
      weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpMessageTest.java
  85. +2
    -2
      weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlMessageTest.java
  86. +1
    -1
      weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlOutImageMessageTest.java
  87. +1
    -1
      weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlOutNewsMessageTest.java
  88. +1
    -1
      weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlOutTextMessageTest.java
  89. +1
    -1
      weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVideoMessageTest.java
  90. +1
    -1
      weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVoiceMessageTest.java
  91. +7
    -7
      weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpDemoInMemoryConfigStorage.java
  92. +3
    -3
      weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpDemoServer.java
  93. +9
    -9
      weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpDemoServlet.java
  94. +0
    -0
      weixin-java-cp/src/test/resources/mm.jpeg
  95. +0
    -0
      weixin-java-cp/src/test/resources/mm.mp3
  96. +0
    -0
      weixin-java-cp/src/test/resources/mm.mp4
  97. +0
    -0
      weixin-java-cp/src/test/resources/test-config.sample.xml
  98. +28
    -0
      weixin-java-cp/src/test/resources/testng.xml
  99. +0
    -56
      weixin-java-enterprise/README.md
  100. +0
    -31
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/bean/result/WxAccessToken.java

weixin-java-enterprise/pom.xml → pom.xml View File

@@ -4,10 +4,11 @@
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>me.chanjar</groupId>
<artifactId>weixin-java-enterprise-tools</artifactId>
<artifactId>weixin-java-parent</artifactId>
<version>1.0.3-SNAPSHOT</version>
<name>WeiXin Java Enterprise Tools</name>
<description>微信企业号Java SDK</description>
<packaging>pom</packaging>
<name>WeiXin Java Tools - Parent</name>
<description>微信公众号、企业号上级POM</description>
<url>https://github.com/chanjarster/weixin-java-tools</url>

<licenses>
@@ -30,19 +31,20 @@
<url>https://github.com/chanjarster/weixin-java-tools</url>
</scm>

<modules>
<module>weixin-java-common</module>
<module>weixin-java-cp</module>
<module>weixin-java-mp</module>
</modules>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<downloadJavadocs>true</downloadJavadocs>
<downloadSources>true</downloadSources>
<httpclient.version>4.3.5</httpclient.version>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>fluent-hc</artifactId>
@@ -63,34 +65,11 @@
<artifactId>jaxb-impl</artifactId>
<version>2.2.7</version>
</dependency>
<dependency>
<groupId>org.apache.oltu.oauth2</groupId>
<artifactId>org.apache.oltu.oauth2.client</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
@@ -106,20 +85,49 @@
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.3.0.M0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.3.0.M0</version>
<scope>test</scope>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.3.0.M0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.3.0.M0</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
@@ -186,17 +194,17 @@
</profiles>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
</plugin>
</plugins>
</pluginManagement>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>

+ 68
- 0
weixin-java-common/pom.xml View File

@@ -0,0 +1,68 @@
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>me.chanjar</groupId>
<artifactId>weixin-java-parent</artifactId>
<version>1.0.3-SNAPSHOT</version>
</parent>

<artifactId>weixin-java-common</artifactId>
<name>WeiXin Java Tools - Common</name>
<description>微信公众号、企业号Java SDK Common</description>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.3.0.M0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.3.0.M0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>

</project>

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxAccessToken.java → weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxAccessToken.java View File

@@ -1,12 +1,12 @@
package me.chanjar.weixin.mp.bean;
package me.chanjar.weixin.common.bean;

import me.chanjar.weixin.mp.util.json.WxGsonBuilder;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;

public class WxAccessToken {

private String accessToken;
private int expiresIn;
private int expiresIn = -1;

public String getAccessToken() {
return accessToken;

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMenu.java → weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxMenu.java View File

@@ -1,15 +1,15 @@
package me.chanjar.weixin.mp.bean;
package me.chanjar.weixin.common.bean;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import me.chanjar.weixin.mp.util.json.WxGsonBuilder;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;

/**
* 公众号菜单
* @author chanjarster
* 企业号菜单
* @author Daniel Qian
*
*/
public class WxMenu {

weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/bean/result/WxError.java → weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxError.java View File

@@ -1,6 +1,6 @@
package me.chanjar.weixin.common.bean.result;

import me.chanjar.weixin.enterprise.util.json.WxCpGsonBuilder;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;

/**
* 微信错误码说明
@@ -32,9 +32,16 @@ public class WxError {
this.errorMsg = errorMsg;
}

public String getJson() {
return json;
}

public void setJson(String json) {
this.json = json;
}

public static WxError fromJson(String json) {
WxError error = WxCpGsonBuilder.create().fromJson(json, WxError.class);
error.json = json;
WxError error = WxGsonBuilder.create().fromJson(json, WxError.class);
return error;
}


weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMediaUploadResult.java → weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxMediaUploadResult.java View File

@@ -1,6 +1,6 @@
package me.chanjar.weixin.mp.bean.result;
package me.chanjar.weixin.common.bean.result;

import me.chanjar.weixin.mp.util.json.WxGsonBuilder;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;

public class WxMediaUploadResult {

@@ -33,10 +33,6 @@ public class WxMediaUploadResult {
this.createdAt = createdAt;
}

public static WxMediaUploadResult fromJson(String json) {
return WxGsonBuilder.create().fromJson(json, WxMediaUploadResult.class);
}

public String getThumbMediaId() {
return thumbMediaId;
}
@@ -45,6 +41,10 @@ public class WxMediaUploadResult {
this.thumbMediaId = thumbMediaId;
}

public static WxMediaUploadResult fromJson(String json) {
return WxGsonBuilder.create().fromJson(json, WxMediaUploadResult.class);
}

@Override
public String toString() {
return "WxUploadResult [type=" + type + ", media_id=" + mediaId + ", thumb_media_id=" + thumbMediaId

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/exception/WxErrorException.java → weixin-java-common/src/main/java/me/chanjar/weixin/common/exception/WxErrorException.java View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.enterprise.exception;
package me.chanjar.weixin.common.exception;

import me.chanjar.weixin.common.bean.result.WxError;


weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/crypto/ByteGroup.java → weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/ByteGroup.java View File

@@ -1,11 +1,11 @@
package me.chanjar.weixin.enterprise.util.crypto;
package me.chanjar.weixin.common.util.crypto;
import java.util.ArrayList;
class ByteGroup {
public class ByteGroup {
ArrayList<Byte> byteContainer = new ArrayList<Byte>();
byte[] toBytes() {
public byte[] toBytes() {
byte[] bytes = new byte[byteContainer.size()];
for (int i = 0; i < byteContainer.size(); i++) {
bytes[i] = byteContainer.get(i);
@@ -13,14 +13,14 @@ class ByteGroup {
return bytes;
}
ByteGroup addBytes(byte[] bytes) {
public ByteGroup addBytes(byte[] bytes) {
for (byte b : bytes) {
byteContainer.add(b);
}
return this;
}
int size() {
public int size() {
return byteContainer.size();
}
}

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/crypto/PKCS7Encoder.java → weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/PKCS7Encoder.java View File

@@ -6,7 +6,7 @@
// ------------------------------------------------------------------------
package me.chanjar.weixin.mp.util.crypto;
package me.chanjar.weixin.common.util.crypto;
import java.nio.charset.Charset;
import java.util.Arrays;
@@ -14,7 +14,7 @@ import java.util.Arrays;
/**
* 提供基于PKCS7算法的加解
*/
class PKCS7Encoder {
public class PKCS7Encoder {
private static final Charset CHARSET = Charset.forName("utf-8");
private static final int BLOCK_SIZE = 32;
@@ -25,7 +25,7 @@ class PKCS7Encoder {
* @param count 需要进行填充补位操作的明文字节个数
* @return 补齐用的字节数组
*/
static byte[] encode(int count) {
public static byte[] encode(int count) {
// 计算需要填充的位数
int amountToPad = BLOCK_SIZE - (count % BLOCK_SIZE);
if (amountToPad == 0) {
@@ -46,7 +46,7 @@ class PKCS7Encoder {
* @param decrypted 解密后的明文
* @return 删除补位字符后的明文
*/
static byte[] decode(byte[] decrypted) {
public static byte[] decode(byte[] decrypted) {
int pad = (int) decrypted[decrypted.length - 1];
if (pad < 1 || pad > 32) {
pad = 0;
@@ -60,7 +60,7 @@ class PKCS7Encoder {
* @param a 需要转化的数字
* @return 转化得到的字符
*/
static char chr(int a) {
public static char chr(int a) {
byte target = (byte) (a & 0xFF);
return (char) target;
}

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/crypto/SHA1.java → weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/SHA1.java View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.enterprise.util.crypto;
package me.chanjar.weixin.common.util.crypto;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/crypto/WxCryptUtil.java → weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/WxCryptUtil.java View File

@@ -11,13 +11,12 @@
* 需要导入架包commons-codec-1.9(或commons-codec-1.8等其他版本)
* 官方下载地址:http://commons.apache.org/proper/commons-codec/download_codec.cgi
*/
package me.chanjar.weixin.enterprise.util.crypto;
package me.chanjar.weixin.common.util.crypto;
import java.io.StringReader;
import java.nio.charset.Charset;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Random;
import org.apache.commons.codec.binary.Base64;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
@@ -25,12 +24,11 @@ import javax.crypto.spec.SecretKeySpec;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import me.chanjar.weixin.enterprise.api.WxCpConfigStorage;
import org.apache.commons.codec.binary.Base64;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
import java.io.StringReader;
import java.nio.charset.Charset;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Random;
public class WxCryptUtil {
@@ -48,41 +46,24 @@ public class WxCryptUtil {
}
};
private byte[] aesKey;
private String token;
private String corpId;
/**
* 构造函数
*
* @param wxCpConfigStorage
*/
public WxCryptUtil(WxCpConfigStorage wxCpConfigStorage) {
/*
* @param token 公众平台上,开发者设置的token
* @param encodingAesKey 公众平台上,开发者设置的EncodingAESKey
* @param corpId 公众平台appid
*/
String encodingAesKey = wxCpConfigStorage.getAesKey();
String token = wxCpConfigStorage.getToken();
String corpId = wxCpConfigStorage.getCorpId();
this.token = token;
this.corpId = corpId;
this.aesKey = Base64.decodeBase64(encodingAesKey + "=");
protected byte[] aesKey;
protected String token;
protected String appidOrCorpid;
public WxCryptUtil() {
super();
}
/**
* 构造函数
*
* @param token 公众平台上,开发者设置的token
* @param encodingAesKey 公众平台上,开发者设置的EncodingAESKey
* @param corpId 公众平台appid
* @param token 公众平台上,开发者设置的token
* @param encodingAesKey 公众平台上,开发者设置的EncodingAESKey
* @param appidOrCorpid 公众平台appid/corpid
*/
public WxCryptUtil(String token, String encodingAesKey, String corpId) {
public WxCryptUtil(String token, String encodingAesKey, String appidOrCorpid) {
this.token = token;
this.corpId = corpId;
this.appidOrCorpid = appidOrCorpid;
this.aesKey = Base64.decodeBase64(encodingAesKey + "=");
}
@@ -125,7 +106,7 @@ public class WxCryptUtil {
byte[] randomStringBytes = randomStr.getBytes(CHARSET);
byte[] plainTextBytes = plainText.getBytes(CHARSET);
byte[] bytesOfSizeInNetworkOrder = number2BytesInNetworkOrder(plainTextBytes.length);
byte[] appIdBytes = corpId.getBytes(CHARSET);
byte[] appIdBytes = appidOrCorpid.getBytes(CHARSET);
// randomStr + networkBytesOrder + text + appid
byteCollector.addBytes(randomStringBytes);
@@ -235,7 +216,7 @@ public class WxCryptUtil {
}
// appid不相同的情况
if (!from_appid.equals(corpId)) {
if (!from_appid.equals(appidOrCorpid)) {
throw new RuntimeException("AppID不正确");
}

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/fs/FileUtils.java → weixin-java-common/src/main/java/me/chanjar/weixin/common/util/fs/FileUtils.java View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.mp.util.fs;
package me.chanjar.weixin.common.util.fs;

import java.io.File;
import java.io.FileOutputStream;

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/InputStreamResponseHandler.java → weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/InputStreamResponseHandler.java View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.mp.util.http;
package me.chanjar.weixin.common.util.http;

import java.io.IOException;
import java.io.InputStream;

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/MediaDownloadRequestExecutor.java → weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MediaDownloadRequestExecutor.java View File

@@ -1,11 +1,11 @@
package me.chanjar.weixin.enterprise.util.http;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
package me.chanjar.weixin.common.util.http;

import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.util.fs.FileUtils;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.util.http.InputStreamResponseHandler;
import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.common.util.http.Utf8ResponseHandler;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.Header;
import org.apache.http.client.ClientProtocolException;
@@ -13,9 +13,11 @@ import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.entity.ContentType;

import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.enterprise.exception.WxErrorException;
import me.chanjar.weixin.common.util.FileUtils;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* 下载媒体文件请求执行器,请求的参数是String, 返回的结果是File

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/MediaUploadRequestExecutor.java → weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MediaUploadRequestExecutor.java View File

@@ -1,8 +1,9 @@
package me.chanjar.weixin.enterprise.util.http;
package me.chanjar.weixin.common.util.http;

import java.io.File;
import java.io.IOException;

import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
@@ -11,8 +12,7 @@ import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.MultipartEntityBuilder;

import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.enterprise.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.enterprise.exception.WxErrorException;
import me.chanjar.weixin.common.exception.WxErrorException;

/**
* 上传媒体文件请求执行器,请求的参数是File, 返回的结果是String

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/RequestExecutor.java → weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/RequestExecutor.java View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.enterprise.util.http;
package me.chanjar.weixin.common.util.http;

import java.io.IOException;

@@ -6,7 +6,7 @@ import org.apache.http.client.ClientProtocolException;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

import me.chanjar.weixin.enterprise.exception.WxErrorException;
import me.chanjar.weixin.common.exception.WxErrorException;

/**
* http请求执行器

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/SimpleGetRequestExecutor.java → weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/SimpleGetRequestExecutor.java View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.enterprise.util.http;
package me.chanjar.weixin.common.util.http;

import java.io.IOException;

@@ -7,7 +7,7 @@ import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;

import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.enterprise.exception.WxErrorException;
import me.chanjar.weixin.common.exception.WxErrorException;

/**
* 简单的GET请求执行器,请求的参数是String, 返回的结果也是String

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/SimplePostRequestExecutor.java → weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/SimplePostRequestExecutor.java View File

@@ -1,9 +1,9 @@
package me.chanjar.weixin.enterprise.util.http;
package me.chanjar.weixin.common.util.http;

import java.io.IOException;

import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.enterprise.exception.WxErrorException;
import me.chanjar.weixin.common.exception.WxErrorException;
import org.apache.http.Consts;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/Utf8ResponseHandler.java → weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/Utf8ResponseHandler.java View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.enterprise.util.http;
package me.chanjar.weixin.common.util.http;

import java.io.IOException;


weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/util/GsonHelper.java → weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/GsonHelper.java View File

@@ -6,7 +6,7 @@
* arose from modification of the original source, or other redistribution of this source
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD.
*/
package me.chanjar.weixin.common.util;
package me.chanjar.weixin.common.util.json;


import com.google.gson.JsonElement;

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxAccessTokenAdapter.java → weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxAccessTokenAdapter.java View File

@@ -6,10 +6,10 @@
* arose from modification of the original source, or other redistribution of this source
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD.
*/
package me.chanjar.weixin.mp.util.json;
package me.chanjar.weixin.common.util.json;

import com.google.gson.*;
import me.chanjar.weixin.mp.bean.WxAccessToken;
import me.chanjar.weixin.common.bean.WxAccessToken;

import java.lang.reflect.Type;


weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxErrorAdapter.java → weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxErrorAdapter.java View File

@@ -6,10 +6,9 @@
* arose from modification of the original source, or other redistribution of this source
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD.
*/
package me.chanjar.weixin.enterprise.util.json;
package me.chanjar.weixin.common.util.json;

import com.google.gson.*;
import me.chanjar.weixin.common.util.GsonHelper;
import me.chanjar.weixin.common.bean.result.WxError;

import java.lang.reflect.Type;
@@ -31,6 +30,7 @@ public class WxErrorAdapter implements JsonDeserializer<WxError> {
if (wxErrorJsonObject.get("errmsg") != null && !wxErrorJsonObject.get("errmsg").isJsonNull()) {
wxError.setErrorMsg(GsonHelper.getAsString(wxErrorJsonObject.get("errmsg")));
}
wxError.setJson(json.toString());
return wxError;
}

+ 26
- 0
weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxGsonBuilder.java View File

@@ -0,0 +1,26 @@
package me.chanjar.weixin.common.util.json;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import me.chanjar.weixin.common.bean.WxMenu;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;

public class WxGsonBuilder {

public static final GsonBuilder INSTANCE = new GsonBuilder();

static {
INSTANCE.disableHtmlEscaping();
INSTANCE.registerTypeAdapter(WxAccessToken.class, new WxAccessTokenAdapter());
INSTANCE.registerTypeAdapter(WxError.class, new WxErrorAdapter());
INSTANCE.registerTypeAdapter(WxMenu.class, new WxMenuGsonAdapter());
INSTANCE.registerTypeAdapter(WxMediaUploadResult.class, new WxMediaUploadResultAdapter());
}

public static Gson create() {
return INSTANCE.create();
}

}

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMediaUploadResultAdapter.java → weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMediaUploadResultAdapter.java View File

@@ -6,10 +6,10 @@
* arose from modification of the original source, or other redistribution of this source
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD.
*/
package me.chanjar.weixin.mp.util.json;
package me.chanjar.weixin.common.util.json;

import com.google.gson.*;
import me.chanjar.weixin.mp.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;

import java.lang.reflect.Type;


weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMenuGsonAdapter.java → weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java View File

@@ -6,11 +6,11 @@
* arose from modification of the original source, or other redistribution of this source
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD.
*/
package me.chanjar.weixin.mp.util.json;
package me.chanjar.weixin.common.util.json;

import java.lang.reflect.Type;

import me.chanjar.weixin.mp.bean.WxMenu;
import me.chanjar.weixin.common.bean.WxMenu;

import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
@@ -23,7 +23,7 @@ import com.google.gson.JsonSerializer;

/**
*
* @author qianjia
* @author Daniel Qian
*
*/
public class WxMenuGsonAdapter implements JsonSerializer<WxMenu>, JsonDeserializer<WxMenu> {

weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/util/AdapterCDATA.java → weixin-java-common/src/main/java/me/chanjar/weixin/common/util/xml/AdapterCDATA.java View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.common.util;
package me.chanjar.weixin.common.util.xml;

import javax.xml.bind.annotation.adapters.XmlAdapter;


weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/util/MediaIdMarshaller.java → weixin-java-common/src/main/java/me/chanjar/weixin/common/util/xml/MediaIdMarshaller.java View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.common.util;
package me.chanjar.weixin.common.util.xml;

import javax.xml.bind.annotation.adapters.XmlAdapter;


weixin-java-enterprise/src/test/java/me/chanjar/weixin/common/bean/WxAccessTokenTest.java → weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxAccessTokenTest.java View File

@@ -1,6 +1,5 @@
package me.chanjar.weixin.common.bean;

import me.chanjar.weixin.common.bean.result.WxAccessToken;
import org.testng.Assert;
import org.testng.annotations.Test;


weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxErrorTest.java → weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxErrorTest.java View File

@@ -1,10 +1,9 @@
package me.chanjar.weixin.enterprise.bean;
package me.chanjar.weixin.common.bean;

import me.chanjar.weixin.common.bean.result.WxError;
import org.testng.Assert;
import org.testng.annotations.Test;

import me.chanjar.weixin.common.bean.result.WxError;

@Test
public class WxErrorTest {


weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxMenuTest.java → weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxMenuTest.java View File

@@ -1,12 +1,10 @@
package me.chanjar.weixin.mp.bean;
package me.chanjar.weixin.common.bean;

import me.chanjar.weixin.mp.bean.WxMenu;
import me.chanjar.weixin.common.bean.WxMenu.WxMenuButton;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import me.chanjar.weixin.mp.bean.WxMenu.WxMenuButton;

@Test
public class WxMenuTest {


weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/util/crypto/WxCryptUtilTest.java → weixin-java-common/src/test/java/me/chanjar/weixin/common/util/crypto/WxCryptUtilTest.java View File

@@ -1,6 +1,5 @@
package me.chanjar.weixin.enterprise.util.crypto;
package me.chanjar.weixin.common.util.crypto;
import me.chanjar.weixin.enterprise.util.crypto.WxCryptUtil;
import org.testng.annotations.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -14,7 +13,8 @@ import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.io.StringReader;
import static org.testng.Assert.*;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.fail;
@Test
public class WxCryptUtilTest {

+ 12
- 0
weixin-java-common/src/test/resources/testng.xml View File

@@ -0,0 +1,12 @@
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Weixin-java-tool-suite" verbose="1">
<test name="Bean_Test">
<classes>
<class name="me.chanjar.weixin.common.bean.WxAccessTokenTest" />
<class name="me.chanjar.weixin.common.bean.WxErrorTest" />
<class name="me.chanjar.weixin.common.bean.WxMenuTest" />
<class name="me.chanjar.weixin.common.util.crypto.WxCryptUtilTest" />
</classes>
</test>
</suite>

weixin-java-enterprise/LICENSE → weixin-java-cp/LICENSE View File


+ 46
- 0
weixin-java-cp/README.md View File

@@ -0,0 +1,46 @@
weixin-java-cp
===========

微信企业号Java SDK开发工具集,本项目主要分为两大块:微信消息路由器、微信Java API

详细文档请看 [wiki](https://github.com/chanjarster/weixin-java-tools/wiki)

# Quickstart

在你的maven项目中添加:
```xml
<dependency>
<groupId>me.chanjar</groupId>
<artifactId>weixin-java-cp-tools</artifactId>
<version>1.0.3</version>
</dependency>
```

如果要使用``*-SNAPSHOT``版,则需要在你的``pom.xml``中添加这段:

```xml
<repositories>
<repository>
<snapshots />
<id>sonatype snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
</repositories>
```

## Hello World
```java
WxCpInMemoryConfigStorage config = new WxCpInMemoryConfigStorage();
config.getCorpId(...); // 设置微信企业号的appid
config.getCorpSecret(...); // 设置微信企业号的app corpSecret
config.setAgentId(...); // 设置微信企业号应用ID
config.setToken(...); // 设置微信企业号应用的token
config.setAesKey(...); // 设置微信企业号应用的EncodingAESKey

WxCpServiceImpl wxCpService = new WxCpServiceImpl();
wxCpService.setWxCpConfigStorage(config);

String userId = ...;
WxCpMessage message = WxCpMessage.TEXT().agentId(...).toUser(userId).content("Hello World").build();
wxService.messageSend(message);
```

+ 73
- 0
weixin-java-cp/pom.xml View File

@@ -0,0 +1,73 @@
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>me.chanjar</groupId>
<artifactId>weixin-java-parent</artifactId>
<version>1.0.3-SNAPSHOT</version>
</parent>

<artifactId>weixin-java-cp</artifactId>
<name>WeiXin Java Tools - CP</name>
<description>微信企业号Java SDK</description>

<dependencies>
<dependency>
<groupId>me.chanjar</groupId>
<artifactId>weixin-java-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.3.0.M0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.3.0.M0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>

</project>

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpConfigStorage.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpConfigStorage.java View File

@@ -1,6 +1,6 @@
package me.chanjar.weixin.enterprise.api;
package me.chanjar.weixin.cp.api;

import me.chanjar.weixin.common.bean.result.WxAccessToken;
import me.chanjar.weixin.common.bean.WxAccessToken;

/**
* 微信客户端配置存储

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpConsts.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpConsts.java View File

@@ -1,7 +1,4 @@
package me.chanjar.weixin.enterprise.api;

import java.util.HashMap;
import java.util.Map;
package me.chanjar.weixin.cp.api;

public class WxCpConsts {


weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxInMemoryCpConfigStorage.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpInMemoryConfigStorage.java View File

@@ -1,13 +1,13 @@
package me.chanjar.weixin.enterprise.api;
package me.chanjar.weixin.cp.api;

import me.chanjar.weixin.common.bean.result.WxAccessToken;
import me.chanjar.weixin.common.bean.WxAccessToken;

/**
* 基于内存的微信配置provider,在实际生产环境中应该将这些配置持久化
* @author Daniel Qian
*
*/
public class WxInMemoryCpConfigStorage implements WxCpConfigStorage {
public class WxCpInMemoryConfigStorage implements WxCpConfigStorage {

protected String corpId;
protected String corpSecret;
@@ -86,7 +86,7 @@ public class WxInMemoryCpConfigStorage implements WxCpConfigStorage {
@Override
public String toString() {
return "WxInMemoryCpConfigStorage{" +
"corpId='" + corpId + '\'' +
"appidOrCorpid='" + corpId + '\'' +
", corpSecret='" + corpSecret + '\'' +
", token='" + token + '\'' +
", accessToken='" + accessToken + '\'' +

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpMessageHandler.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageHandler.java View File

@@ -1,9 +1,9 @@
package me.chanjar.weixin.enterprise.api;
package me.chanjar.weixin.cp.api;

import java.util.Map;

import me.chanjar.weixin.enterprise.bean.WxCpXmlMessage;
import me.chanjar.weixin.enterprise.bean.WxCpXmlOutMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage;

/**
* 处理微信推送消息的处理器接口

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpMessageInterceptor.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageInterceptor.java View File

@@ -1,8 +1,8 @@
package me.chanjar.weixin.enterprise.api;
package me.chanjar.weixin.cp.api;

import java.util.Map;

import me.chanjar.weixin.enterprise.bean.WxCpXmlMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlMessage;

/**
* 微信消息拦截器,可以用来做验证

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpMessageRouter.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageRouter.java View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.enterprise.api;
package me.chanjar.weixin.cp.api;

import java.util.ArrayList;
import java.util.HashMap;
@@ -8,20 +8,20 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.regex.Pattern;

import me.chanjar.weixin.enterprise.bean.WxCpXmlMessage;
import me.chanjar.weixin.enterprise.bean.WxCpXmlOutMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage;

/**
* <pre>
* 微信消息路由器,通过代码化的配置,把来自微信的消息交给handler处理
*
*
* 说明:
* 1. 配置路由规则时要按照从细到粗的原则,否则可能消息可能会被提前处理
* 2. 默认情况下消息只会被处理一次,除非使用 {@link Rule#next()}
* 3. 规则的结束必须用{@link Rule#end()}或者{@link Rule#next()},否则不会生效
*
*
* 使用方法:
* WxMessageRouter router = new WxMessageRouter();
* WxCpMessageRouter router = new WxCpMessageRouter();
* router
* .rule()
* .msgType("MSG_TYPE").event("EVENT").eventKey("EVENT_KEY").content("CONTENT")
@@ -31,20 +31,20 @@ import me.chanjar.weixin.enterprise.bean.WxCpXmlOutMessage;
* // 另外一个匹配规则
* .end()
* ;
*
*
* // 将WxXmlMessage交给消息路由器
* router.route(message);
*
*
* </pre>
* @author Daniel Qian
*
*/
public class WxCpMessageRouter {
private final List<Rule> rules = new ArrayList<Rule>();

private final ExecutorService es = Executors.newCachedThreadPool();
/**
* 开始一个新的Route规则
* @return
@@ -65,11 +65,11 @@ public class WxCpMessageRouter {
matchRules.add(rule);
}
}
if (matchRules.size() == 0) {
return null;
}
if (matchRules.get(0).async) {
// 只要第一个是异步的,那就异步执行
// 在另一个线程里执行
@@ -85,7 +85,7 @@ public class WxCpMessageRouter {
});
return null;
}
WxCpXmlOutMessage res = null;
for (final Rule rule : matchRules) {
// 返回最后一个匹配规则的结果
@@ -96,33 +96,35 @@ public class WxCpMessageRouter {
}
return res;
}
public static class Rule {
private final WxCpMessageRouter routerBuilder;

private boolean async = true;
private String msgType;

private String event;
private String eventKey;
private String content;
private String rContent;
private boolean reEnter = false;

private Integer agentId;

private List<WxCpMessageHandler> handlers = new ArrayList<WxCpMessageHandler>();
private List<WxCpMessageInterceptor> interceptors = new ArrayList<WxCpMessageInterceptor>();
protected Rule(WxCpMessageRouter routerBuilder) {
this.routerBuilder = routerBuilder;
}
/**
* 设置是否异步执行,默认是true
* @param async
@@ -132,7 +134,17 @@ public class WxCpMessageRouter {
this.async = async;
return this;
}

/**
* 如果agentId匹配
* @param agentId
* @return
*/
public Rule agentId(Integer agentId) {
this.agentId = agentId;
return this;
}

/**
* 如果msgType等于某值
* @param msgType
@@ -142,7 +154,7 @@ public class WxCpMessageRouter {
this.msgType = msgType;
return this;
}
/**
* 如果event等于某值
* @param event
@@ -152,7 +164,7 @@ public class WxCpMessageRouter {
this.event = event;
return this;
}
/**
* 如果eventKey等于某值
* @param eventKey
@@ -162,7 +174,7 @@ public class WxCpMessageRouter {
this.eventKey = eventKey;
return this;
}
/**
* 如果content等于某值
* @param content
@@ -172,7 +184,7 @@ public class WxCpMessageRouter {
this.content = content;
return this;
}
/**
* 如果content匹配该正则表达式
* @param regex
@@ -182,7 +194,7 @@ public class WxCpMessageRouter {
this.rContent = regex;
return this;
}
/**
* 设置微信消息拦截器
* @param interceptor
@@ -191,7 +203,7 @@ public class WxCpMessageRouter {
public Rule interceptor(WxCpMessageInterceptor interceptor) {
return interceptor(interceptor, (WxCpMessageInterceptor[]) null);
}
/**
* 设置微信消息拦截器
* @param interceptor
@@ -207,7 +219,7 @@ public class WxCpMessageRouter {
}
return this;
}
/**
* 设置微信消息处理器
* @param handler
@@ -216,7 +228,7 @@ public class WxCpMessageRouter {
public Rule handler(WxCpMessageHandler handler) {
return handler(handler, (WxCpMessageHandler[]) null);
}
/**
* 设置微信消息处理器
* @param handler
@@ -232,7 +244,7 @@ public class WxCpMessageRouter {
}
return this;
}
/**
* 规则结束,代表如果一个消息匹配该规则,那么它将不再会进入其他规则
* @return
@@ -241,7 +253,7 @@ public class WxCpMessageRouter {
this.routerBuilder.rules.add(this);
return this.routerBuilder;
}
/**
* 规则结束,但是消息还会进入其他规则
* @return
@@ -250,9 +262,11 @@ public class WxCpMessageRouter {
this.reEnter = true;
return end();
}
protected boolean test(WxCpXmlMessage wxMessage) {
return
return
(this.agentId == null || this.agentId.equals(wxMessage.getAgentId()))
&&
(this.msgType == null || this.msgType.equals(wxMessage.getMsgType()))
&&
(this.event == null || this.event.equals(wxMessage.getEvent()))
@@ -264,7 +278,7 @@ public class WxCpMessageRouter {
(this.rContent == null || Pattern.matches(this.rContent, wxMessage.getContent() == null ? "" : wxMessage.getContent().trim()))
;
}
/**
* 处理微信推送过来的消息
* @param wxMessage
@@ -278,7 +292,7 @@ public class WxCpMessageRouter {
return null;
}
}
// 交给handler处理
WxCpXmlOutMessage res = null;
for (WxCpMessageHandler handler : this.handlers) {
@@ -287,7 +301,7 @@ public class WxCpMessageRouter {
}
return res;
}
}
}

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpService.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java View File

@@ -1,15 +1,16 @@
package me.chanjar.weixin.enterprise.api;
package me.chanjar.weixin.cp.api;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import me.chanjar.weixin.enterprise.bean.*;
import me.chanjar.weixin.enterprise.bean.WxCpDepart;
import me.chanjar.weixin.enterprise.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.enterprise.bean.WxCpUser;
import me.chanjar.weixin.enterprise.exception.WxErrorException;
import me.chanjar.weixin.common.bean.WxMenu;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.cp.bean.*;
import me.chanjar.weixin.cp.bean.WxCpDepart;
import me.chanjar.weixin.cp.bean.WxCpUser;
import me.chanjar.weixin.common.exception.WxErrorException;

/**
* 微信API的Service
@@ -49,7 +50,7 @@ public interface WxCpService {
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=获取access_token
* </pre>
*
* @throws me.chanjar.weixin.enterprise.exception.WxErrorException
* @throws me.chanjar.weixin.common.exception.WxErrorException
*/
public void accessTokenRefresh() throws WxErrorException;

@@ -113,7 +114,7 @@ public interface WxCpService {
* @param menu
* @throws WxErrorException
*/
public void menuCreate(WxCpMenu menu) throws WxErrorException;
public void menuCreate(WxMenu menu) throws WxErrorException;

/**
* <pre>
@@ -134,7 +135,7 @@ public interface WxCpService {
* @return
* @throws WxErrorException
*/
public WxCpMenu menuGet() throws WxErrorException;
public WxMenu menuGet() throws WxErrorException;

/**
* <pre>

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpServiceImpl.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.enterprise.api;
package me.chanjar.weixin.cp.api;

import java.io.File;
import java.io.IOException;
@@ -11,12 +11,14 @@ import java.util.concurrent.atomic.AtomicBoolean;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import me.chanjar.weixin.common.bean.result.WxAccessToken;
import me.chanjar.weixin.common.util.GsonHelper;
import me.chanjar.weixin.enterprise.bean.*;
import me.chanjar.weixin.enterprise.util.http.SimpleGetRequestExecutor;
import me.chanjar.weixin.enterprise.util.crypto.SHA1;
import me.chanjar.weixin.enterprise.util.json.WxCpGsonBuilder;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.bean.WxMenu;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.cp.bean.*;
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
import me.chanjar.weixin.common.util.crypto.SHA1;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
@@ -25,16 +27,15 @@ import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

import me.chanjar.weixin.enterprise.bean.WxCpDepart;
import me.chanjar.weixin.cp.bean.WxCpDepart;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.enterprise.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.enterprise.bean.WxCpUser;
import me.chanjar.weixin.enterprise.exception.WxErrorException;
import me.chanjar.weixin.common.util.FileUtils;
import me.chanjar.weixin.enterprise.util.http.MediaDownloadRequestExecutor;
import me.chanjar.weixin.enterprise.util.http.MediaUploadRequestExecutor;
import me.chanjar.weixin.enterprise.util.http.RequestExecutor;
import me.chanjar.weixin.enterprise.util.http.SimplePostRequestExecutor;
import me.chanjar.weixin.cp.bean.WxCpUser;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.util.fs.FileUtils;
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.SimplePostRequestExecutor;

import com.google.gson.JsonElement;
import com.google.gson.internal.Streams;
@@ -110,7 +111,7 @@ public class WxCpServiceImpl implements WxCpService {
execute(new SimplePostRequestExecutor(), url, message.toJson());
}

public void menuCreate(WxCpMenu menu) throws WxErrorException {
public void menuCreate(WxMenu menu) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/menu/create?agentid=" + wxCpConfigStorage.getAgentId();
execute(new SimplePostRequestExecutor(), url, menu.toJson());
}
@@ -120,11 +121,11 @@ public class WxCpServiceImpl implements WxCpService {
execute(new SimpleGetRequestExecutor(), url, null);
}

public WxCpMenu menuGet() throws WxErrorException {
public WxMenu menuGet() throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/menu/get?agentid=" + wxCpConfigStorage.getAgentId();
try {
String resultContent = execute(new SimpleGetRequestExecutor(), url, null);
return WxCpMenu.fromJson(resultContent);
return WxMenu.fromJson(resultContent);
} catch (WxErrorException e) {
// 46003 不存在的菜单数据
if (e.getError().getErrorCode() == 46003) {

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpDepart.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpDepart.java View File

@@ -1,6 +1,6 @@
package me.chanjar.weixin.enterprise.bean;
package me.chanjar.weixin.cp.bean;

import me.chanjar.weixin.enterprise.util.json.WxCpGsonBuilder;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

/**
* 微信部门

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpMessage.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMessage.java View File

@@ -1,10 +1,10 @@
package me.chanjar.weixin.enterprise.bean;
package me.chanjar.weixin.cp.bean;

import java.util.ArrayList;
import java.util.List;

import me.chanjar.weixin.enterprise.bean.messagebuilder.*;
import me.chanjar.weixin.enterprise.util.json.WxCpGsonBuilder;
import me.chanjar.weixin.cp.bean.messagebuilder.*;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

/**
* 消息
@@ -65,12 +65,12 @@ public class WxCpMessage {
/**
* <pre>
* 请使用
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#CUSTOM_MSG_TEXT}
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#CUSTOM_MSG_IMAGE}
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#CUSTOM_MSG_VOICE}
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#CUSTOM_MSG_MUSIC}
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#CUSTOM_MSG_VIDEO}
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#CUSTOM_MSG_NEWS}
* {@link me.chanjar.weixin.cp.api.WxCpConsts#CUSTOM_MSG_TEXT}
* {@link me.chanjar.weixin.cp.api.WxCpConsts#CUSTOM_MSG_IMAGE}
* {@link me.chanjar.weixin.cp.api.WxCpConsts#CUSTOM_MSG_VOICE}
* {@link me.chanjar.weixin.cp.api.WxCpConsts#CUSTOM_MSG_MUSIC}
* {@link me.chanjar.weixin.cp.api.WxCpConsts#CUSTOM_MSG_VIDEO}
* {@link me.chanjar.weixin.cp.api.WxCpConsts#CUSTOM_MSG_NEWS}
* </pre>
* @param msgType
*/

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpTag.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTag.java View File

@@ -1,13 +1,6 @@
package me.chanjar.weixin.enterprise.bean;
package me.chanjar.weixin.cp.bean;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.internal.Streams;
import com.google.gson.stream.JsonReader;
import me.chanjar.weixin.common.util.GsonHelper;
import me.chanjar.weixin.enterprise.util.json.WxCpGsonBuilder;

import java.io.StringReader;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

/**
* Created by Daniel Qian

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpUser.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java View File

@@ -1,8 +1,7 @@
package me.chanjar.weixin.enterprise.bean;
package me.chanjar.weixin.cp.bean;

import me.chanjar.weixin.enterprise.util.json.WxCpGsonBuilder;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

import java.sql.PseudoColumnUsage;
import java.util.ArrayList;
import java.util.List;


weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlMessage.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlMessage.java View File

@@ -1,9 +1,9 @@
package me.chanjar.weixin.enterprise.bean;
package me.chanjar.weixin.cp.bean;

import me.chanjar.weixin.enterprise.api.WxCpConfigStorage;
import me.chanjar.weixin.common.util.AdapterCDATA;
import me.chanjar.weixin.common.util.XmlTransformer;
import me.chanjar.weixin.enterprise.util.crypto.WxCryptUtil;
import me.chanjar.weixin.common.util.xml.AdapterCDATA;
import me.chanjar.weixin.cp.api.WxCpConfigStorage;
import me.chanjar.weixin.cp.util.crypto.WxCpCryptUtil;
import me.chanjar.weixin.cp.util.xml.XmlTransformer;
import org.apache.commons.io.IOUtils;

import javax.xml.bind.JAXBException;
@@ -190,13 +190,13 @@ public class WxCpXmlMessage {
/**
* <pre>
* 当接受用户消息时,可能会获得以下值:
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_TEXT}
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_IMAGE}
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_VOICE}
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_VIDEO}
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_LOCATION}
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_LINK}
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_EVENT}
* {@link me.chanjar.weixin.cp.api.WxCpConsts#XML_MSG_TEXT}
* {@link me.chanjar.weixin.cp.api.WxCpConsts#XML_MSG_IMAGE}
* {@link me.chanjar.weixin.cp.api.WxCpConsts#XML_MSG_VOICE}
* {@link me.chanjar.weixin.cp.api.WxCpConsts#XML_MSG_VIDEO}
* {@link me.chanjar.weixin.cp.api.WxCpConsts#XML_MSG_LOCATION}
* {@link me.chanjar.weixin.cp.api.WxCpConsts#XML_MSG_LINK}
* {@link me.chanjar.weixin.cp.api.WxCpConsts#XML_MSG_EVENT}
* </pre>
*
* @return
@@ -208,12 +208,11 @@ public class WxCpXmlMessage {
/**
* <pre>
* 当发送消息的时候使用:
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_TEXT}
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_IMAGE}
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_VOICE}
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_VIDEO}
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_NEWS}
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_MUSIC}
* {@link me.chanjar.weixin.cp.api.WxCpConsts#XML_MSG_TEXT}
* {@link me.chanjar.weixin.cp.api.WxCpConsts#XML_MSG_IMAGE}
* {@link me.chanjar.weixin.cp.api.WxCpConsts#XML_MSG_VOICE}
* {@link me.chanjar.weixin.cp.api.WxCpConsts#XML_MSG_VIDEO}
* {@link me.chanjar.weixin.cp.api.WxCpConsts#XML_MSG_NEWS}
* </pre>
*
* @param msgType
@@ -420,7 +419,7 @@ public class WxCpXmlMessage {
String encryptedXml,
WxCpConfigStorage wxCpConfigStorage,
String timestamp, String nonce, String msgSignature) {
WxCryptUtil cryptUtil = new WxCryptUtil(wxCpConfigStorage);
WxCpCryptUtil cryptUtil = new WxCpCryptUtil(wxCpConfigStorage);
String plainText = cryptUtil.decrypt(msgSignature, timestamp, nonce, encryptedXml);
return fromXml(plainText);
}

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutImageMessage.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutImageMessage.java View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.enterprise.bean;
package me.chanjar.weixin.cp.bean;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
@@ -6,8 +6,8 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import me.chanjar.weixin.enterprise.api.WxCpConsts;
import me.chanjar.weixin.common.util.MediaIdMarshaller;
import me.chanjar.weixin.cp.api.WxCpConsts;
import me.chanjar.weixin.common.util.xml.MediaIdMarshaller;

@XmlRootElement(name = "xml")
@XmlAccessorType(XmlAccessType.FIELD)

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutMessage.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutMessage.java View File

@@ -1,4 +1,10 @@
package me.chanjar.weixin.enterprise.bean;
package me.chanjar.weixin.cp.bean;

import me.chanjar.weixin.common.util.xml.AdapterCDATA;
import me.chanjar.weixin.cp.api.WxCpConfigStorage;
import me.chanjar.weixin.cp.bean.outxmlbuilder.*;
import me.chanjar.weixin.cp.util.crypto.WxCpCryptUtil;
import me.chanjar.weixin.cp.util.xml.XmlTransformer;

import javax.xml.bind.JAXBException;
import javax.xml.bind.annotation.XmlAccessType;
@@ -7,16 +13,6 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import me.chanjar.weixin.enterprise.api.WxCpConfigStorage;
import me.chanjar.weixin.enterprise.bean.outxmlbuilder.ImageBuilder;
import me.chanjar.weixin.enterprise.bean.outxmlbuilder.NewsBuilder;
import me.chanjar.weixin.enterprise.bean.outxmlbuilder.TextBuilder;
import me.chanjar.weixin.enterprise.bean.outxmlbuilder.VideoBuilder;
import me.chanjar.weixin.enterprise.bean.outxmlbuilder.VoiceBuilder;
import me.chanjar.weixin.enterprise.util.crypto.WxCryptUtil;
import me.chanjar.weixin.common.util.AdapterCDATA;
import me.chanjar.weixin.common.util.XmlTransformer;

@XmlRootElement(name = "xml")
@XmlAccessorType(XmlAccessType.FIELD)
public class WxCpXmlOutMessage {
@@ -82,7 +78,7 @@ public class WxCpXmlOutMessage {
*/
public String toEncryptedXml(WxCpConfigStorage wxCpConfigStorage) {
String plainXml = toXml();
WxCryptUtil pc = new WxCryptUtil(wxCpConfigStorage);
WxCpCryptUtil pc = new WxCpCryptUtil(wxCpConfigStorage);
return pc.encrypt(plainXml);
}


weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutMewsMessage.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutMewsMessage.java View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.enterprise.bean;
package me.chanjar.weixin.cp.bean;

import java.util.ArrayList;
import java.util.List;
@@ -10,8 +10,8 @@ import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import me.chanjar.weixin.enterprise.api.WxCpConsts;
import me.chanjar.weixin.common.util.AdapterCDATA;
import me.chanjar.weixin.cp.api.WxCpConsts;
import me.chanjar.weixin.common.util.xml.AdapterCDATA;

@XmlRootElement(name = "xml")
@XmlAccessorType(XmlAccessType.FIELD)

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutTextMessage.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutTextMessage.java View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.enterprise.bean;
package me.chanjar.weixin.cp.bean;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
@@ -6,8 +6,8 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import me.chanjar.weixin.enterprise.api.WxCpConsts;
import me.chanjar.weixin.common.util.AdapterCDATA;
import me.chanjar.weixin.cp.api.WxCpConsts;
import me.chanjar.weixin.common.util.xml.AdapterCDATA;

@XmlRootElement(name = "xml")
@XmlAccessorType(XmlAccessType.FIELD)

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutVideoMessage.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVideoMessage.java View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.enterprise.bean;
package me.chanjar.weixin.cp.bean;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
@@ -6,8 +6,8 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import me.chanjar.weixin.enterprise.api.WxCpConsts;
import me.chanjar.weixin.common.util.AdapterCDATA;
import me.chanjar.weixin.cp.api.WxCpConsts;
import me.chanjar.weixin.common.util.xml.AdapterCDATA;

@XmlRootElement(name = "xml")
@XmlAccessorType(XmlAccessType.FIELD)

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutVoiceMessage.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVoiceMessage.java View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.enterprise.bean;
package me.chanjar.weixin.cp.bean;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
@@ -6,8 +6,8 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import me.chanjar.weixin.enterprise.api.WxCpConsts;
import me.chanjar.weixin.common.util.MediaIdMarshaller;
import me.chanjar.weixin.cp.api.WxCpConsts;
import me.chanjar.weixin.common.util.xml.MediaIdMarshaller;

@XmlRootElement(name = "xml")
@XmlAccessorType(XmlAccessType.FIELD)

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/messagebuilder/BaseBuilder.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/BaseBuilder.java View File

@@ -1,6 +1,6 @@
package me.chanjar.weixin.enterprise.bean.messagebuilder;
package me.chanjar.weixin.cp.bean.messagebuilder;

import me.chanjar.weixin.enterprise.bean.WxCpMessage;
import me.chanjar.weixin.cp.bean.WxCpMessage;

public class BaseBuilder<T> {
protected String msgType;

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/messagebuilder/FileBuilder.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/FileBuilder.java View File

@@ -1,7 +1,7 @@
package me.chanjar.weixin.enterprise.bean.messagebuilder;
package me.chanjar.weixin.cp.bean.messagebuilder;

import me.chanjar.weixin.enterprise.api.WxCpConsts;
import me.chanjar.weixin.enterprise.bean.WxCpMessage;
import me.chanjar.weixin.cp.api.WxCpConsts;
import me.chanjar.weixin.cp.bean.WxCpMessage;

/**
* 获得消息builder

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/messagebuilder/ImageBuilder.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/ImageBuilder.java View File

@@ -1,7 +1,7 @@
package me.chanjar.weixin.enterprise.bean.messagebuilder;
package me.chanjar.weixin.cp.bean.messagebuilder;

import me.chanjar.weixin.enterprise.api.WxCpConsts;
import me.chanjar.weixin.enterprise.bean.WxCpMessage;
import me.chanjar.weixin.cp.api.WxCpConsts;
import me.chanjar.weixin.cp.bean.WxCpMessage;

/**
* 获得消息builder

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/messagebuilder/NewsBuilder.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/NewsBuilder.java View File

@@ -1,10 +1,10 @@
package me.chanjar.weixin.enterprise.bean.messagebuilder;
package me.chanjar.weixin.cp.bean.messagebuilder;

import java.util.ArrayList;
import java.util.List;

import me.chanjar.weixin.enterprise.api.WxCpConsts;
import me.chanjar.weixin.enterprise.bean.WxCpMessage;
import me.chanjar.weixin.cp.api.WxCpConsts;
import me.chanjar.weixin.cp.bean.WxCpMessage;

/**
* 图文消息builder

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/messagebuilder/TextBuilder.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/TextBuilder.java View File

@@ -1,7 +1,7 @@
package me.chanjar.weixin.enterprise.bean.messagebuilder;
package me.chanjar.weixin.cp.bean.messagebuilder;

import me.chanjar.weixin.enterprise.api.WxCpConsts;
import me.chanjar.weixin.enterprise.bean.WxCpMessage;
import me.chanjar.weixin.cp.api.WxCpConsts;
import me.chanjar.weixin.cp.bean.WxCpMessage;

/**
* 文本消息builder

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/messagebuilder/VideoBuilder.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/VideoBuilder.java View File

@@ -1,7 +1,7 @@
package me.chanjar.weixin.enterprise.bean.messagebuilder;
package me.chanjar.weixin.cp.bean.messagebuilder;

import me.chanjar.weixin.enterprise.api.WxCpConsts;
import me.chanjar.weixin.enterprise.bean.WxCpMessage;
import me.chanjar.weixin.cp.api.WxCpConsts;
import me.chanjar.weixin.cp.bean.WxCpMessage;

/**
* 视频消息builder

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/messagebuilder/VoiceBuilder.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/VoiceBuilder.java View File

@@ -1,7 +1,7 @@
package me.chanjar.weixin.enterprise.bean.messagebuilder;
package me.chanjar.weixin.cp.bean.messagebuilder;

import me.chanjar.weixin.enterprise.api.WxCpConsts;
import me.chanjar.weixin.enterprise.bean.WxCpMessage;
import me.chanjar.weixin.cp.api.WxCpConsts;
import me.chanjar.weixin.cp.bean.WxCpMessage;

/**
* 语音消息builder

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/outxmlbuilder/BaseBuilder.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/BaseBuilder.java View File

@@ -1,6 +1,6 @@
package me.chanjar.weixin.enterprise.bean.outxmlbuilder;
package me.chanjar.weixin.cp.bean.outxmlbuilder;

import me.chanjar.weixin.enterprise.bean.WxCpXmlOutMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage;

public abstract class BaseBuilder<BuilderType, ValueType> {

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/outxmlbuilder/ImageBuilder.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/ImageBuilder.java View File

@@ -1,6 +1,6 @@
package me.chanjar.weixin.enterprise.bean.outxmlbuilder;
package me.chanjar.weixin.cp.bean.outxmlbuilder;

import me.chanjar.weixin.enterprise.bean.WxCpXmlOutImageMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlOutImageMessage;

/**
* 图片消息builder

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/outxmlbuilder/NewsBuilder.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/NewsBuilder.java View File

@@ -1,10 +1,10 @@
package me.chanjar.weixin.enterprise.bean.outxmlbuilder;
package me.chanjar.weixin.cp.bean.outxmlbuilder;

import java.util.ArrayList;
import java.util.List;

import me.chanjar.weixin.enterprise.bean.WxCpXmlOutMewsMessage;
import me.chanjar.weixin.enterprise.bean.WxCpXmlOutMewsMessage.Item;
import me.chanjar.weixin.cp.bean.WxCpXmlOutMewsMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlOutMewsMessage.Item;

/**
* 图文消息builder

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/outxmlbuilder/TextBuilder.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/TextBuilder.java View File

@@ -1,6 +1,6 @@
package me.chanjar.weixin.enterprise.bean.outxmlbuilder;
package me.chanjar.weixin.cp.bean.outxmlbuilder;

import me.chanjar.weixin.enterprise.bean.WxCpXmlOutTextMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlOutTextMessage;

/**
* 文本消息builder

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/outxmlbuilder/VideoBuilder.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/VideoBuilder.java View File

@@ -1,6 +1,6 @@
package me.chanjar.weixin.enterprise.bean.outxmlbuilder;
package me.chanjar.weixin.cp.bean.outxmlbuilder;

import me.chanjar.weixin.enterprise.bean.WxCpXmlOutVideoMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlOutVideoMessage;

/**
* 视频消息builder

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/outxmlbuilder/VoiceBuilder.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/VoiceBuilder.java View File

@@ -1,6 +1,6 @@
package me.chanjar.weixin.enterprise.bean.outxmlbuilder;
package me.chanjar.weixin.cp.bean.outxmlbuilder;

import me.chanjar.weixin.enterprise.bean.WxCpXmlOutVoiceMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlOutVoiceMessage;

/**
* 语音消息builder

+ 43
- 0
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/crypto/WxCpCryptUtil.java View File

@@ -0,0 +1,43 @@
/**
* 对公众平台发送给公众账号的消息加解密示例代码.
*
* @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
*/
package me.chanjar.weixin.cp.util.crypto;
import me.chanjar.weixin.common.util.crypto.WxCryptUtil;
import me.chanjar.weixin.cp.api.WxCpConfigStorage;
import org.apache.commons.codec.binary.Base64;
public class WxCpCryptUtil extends WxCryptUtil {
/**
* 构造函数
*
* @param wxCpConfigStorage
*/
public WxCpCryptUtil(WxCpConfigStorage wxCpConfigStorage) {
/*
* @param token 公众平台上,开发者设置的token
* @param encodingAesKey 公众平台上,开发者设置的EncodingAESKey
* @param appidOrCorpid 公众平台appid
*/
String encodingAesKey = wxCpConfigStorage.getAesKey();
String token = wxCpConfigStorage.getToken();
String corpId = wxCpConfigStorage.getCorpId();
this.token = token;
this.appidOrCorpid = corpId;
this.aesKey = Base64.decodeBase64(encodingAesKey + "=");
}
}

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpDepartGsonAdapter.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpDepartGsonAdapter.java View File

@@ -6,12 +6,12 @@
* arose from modification of the original source, or other redistribution of this source
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD.
*/
package me.chanjar.weixin.enterprise.util.json;
package me.chanjar.weixin.cp.util.json;

import java.lang.reflect.Type;

import me.chanjar.weixin.common.util.GsonHelper;
import me.chanjar.weixin.enterprise.bean.WxCpDepart;
import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.cp.bean.WxCpDepart;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpGsonBuilder.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpGsonBuilder.java View File

@@ -1,11 +1,12 @@
package me.chanjar.weixin.enterprise.util.json;
package me.chanjar.weixin.cp.util.json;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import me.chanjar.weixin.common.bean.result.WxAccessToken;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.enterprise.bean.*;
import me.chanjar.weixin.enterprise.bean.result.*;
import me.chanjar.weixin.common.util.json.WxMediaUploadResultAdapter;
import me.chanjar.weixin.common.util.json.WxErrorAdapter;
import me.chanjar.weixin.cp.bean.*;

public class WxCpGsonBuilder {

@@ -14,12 +15,9 @@ public class WxCpGsonBuilder {
static {
INSTANCE.disableHtmlEscaping();
INSTANCE.registerTypeAdapter(WxCpMessage.class, new WxCpMessageGsonAdapter());
INSTANCE.registerTypeAdapter(WxCpMenu.class, new WxCpMenuGsonAdapter());
INSTANCE.registerTypeAdapter(WxCpDepart.class, new WxCpDepartGsonAdapter());
INSTANCE.registerTypeAdapter(WxCpUser.class, new WxCpUserGsonAdapter());
INSTANCE.registerTypeAdapter(WxAccessToken.class, new WxCpAccessTokenAdapter());
INSTANCE.registerTypeAdapter(WxError.class, new WxErrorAdapter());
INSTANCE.registerTypeAdapter(WxMediaUploadResult.class, new WxCpMediaUploadResultAdapter());
INSTANCE.registerTypeAdapter(WxCpTag.class, new WxCpTagGsonAdapter());
}


weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpMessageGsonAdapter.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpMessageGsonAdapter.java View File

@@ -6,12 +6,12 @@
* arose from modification of the original source, or other redistribution of this source
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD.
*/
package me.chanjar.weixin.enterprise.util.json;
package me.chanjar.weixin.cp.util.json;

import java.lang.reflect.Type;

import me.chanjar.weixin.enterprise.api.WxCpConsts;
import me.chanjar.weixin.enterprise.bean.WxCpMessage;
import me.chanjar.weixin.cp.api.WxCpConsts;
import me.chanjar.weixin.cp.bean.WxCpMessage;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
@@ -30,11 +30,11 @@ public class WxCpMessageGsonAdapter implements JsonSerializer<WxCpMessage> {
public JsonElement serialize(WxCpMessage message, Type typeOfSrc, JsonSerializationContext context) {
JsonObject messageJson = new JsonObject();
messageJson.addProperty("agentid", message.getAgentId());
messageJson.addProperty("msgtype", message.getMsgType());

if (StringUtils.isNotBlank(message.getToUser())) {
messageJson.addProperty("touser", message.getToUser());
}
messageJson.addProperty("msgtype", message.getMsgType());

if (StringUtils.isNotBlank(message.getToParty())) {
messageJson.addProperty("toparty", message.getToUser());
}

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpTagGsonAdapter.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpTagGsonAdapter.java View File

@@ -6,16 +6,12 @@
* arose from modification of the original source, or other redistribution of this source
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD.
*/
package me.chanjar.weixin.enterprise.util.json;
package me.chanjar.weixin.cp.util.json;

import com.google.gson.*;
import com.google.gson.internal.Streams;
import com.google.gson.stream.JsonReader;
import me.chanjar.weixin.common.util.GsonHelper;
import me.chanjar.weixin.enterprise.bean.WxCpDepart;
import me.chanjar.weixin.enterprise.bean.WxCpTag;
import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.cp.bean.WxCpTag;

import java.io.StringReader;
import java.lang.reflect.Type;

/**

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpUserGsonAdapter.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java View File

@@ -6,13 +6,13 @@
* arose from modification of the original source, or other redistribution of this source
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD.
*/
package me.chanjar.weixin.enterprise.util.json;
package me.chanjar.weixin.cp.util.json;

import java.lang.reflect.Type;

import com.google.gson.*;
import me.chanjar.weixin.common.util.GsonHelper;
import me.chanjar.weixin.enterprise.bean.WxCpUser;
import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.cp.bean.WxCpUser;

/**
* @author Daniel Qian

weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/util/XmlTransformer.java → weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/xml/XmlTransformer.java View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.common.util;
package me.chanjar.weixin.cp.util.xml;

import java.io.IOException;
import java.io.InputStream;
@@ -8,7 +8,7 @@ import java.io.Writer;

import javax.xml.bind.*;

import me.chanjar.weixin.enterprise.bean.*;
import me.chanjar.weixin.cp.bean.*;
import org.xml.sax.InputSource;

import com.sun.xml.bind.marshaller.CharacterEscapeHandler;

weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/ApiTestModule.java → weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/ApiTestModule.java View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.enterprise.api;
package me.chanjar.weixin.cp.api;

import java.io.InputStream;

@@ -19,7 +19,7 @@ public class ApiTestModule implements Module {
public void configure(Binder binder) {
try {
InputStream is1 = ClassLoader.getSystemResourceAsStream("test-config.xml");
WxXmlCpConfigStorage config = fromXml(WxXmlCpConfigStorage.class, is1);
WxXmlCpInMemoryConfigStorage config = fromXml(WxXmlCpInMemoryConfigStorage.class, is1);
WxCpServiceImpl wxService = new WxCpServiceImpl();
wxService.setWxCpConfigStorage(config);

@@ -40,7 +40,7 @@ public class ApiTestModule implements Module {

@XmlRootElement(name = "xml")
@XmlAccessorType(XmlAccessType.FIELD)
public static class WxXmlCpConfigStorage extends WxInMemoryCpConfigStorage {
public static class WxXmlCpInMemoryConfigStorage extends WxCpInMemoryConfigStorage {
protected String userId;


weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpBaseAPITest.java → weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBaseAPITest.java View File

@@ -1,11 +1,11 @@
package me.chanjar.weixin.enterprise.api;
package me.chanjar.weixin.cp.api;

import org.apache.commons.lang3.StringUtils;
import org.testng.Assert;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;

import me.chanjar.weixin.enterprise.exception.WxErrorException;
import me.chanjar.weixin.common.exception.WxErrorException;

import com.google.inject.Inject;


weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpDepartAPITest.java → weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpDepartAPITest.java View File

@@ -1,13 +1,13 @@
package me.chanjar.weixin.enterprise.api;
package me.chanjar.weixin.cp.api;

import java.util.List;

import me.chanjar.weixin.enterprise.bean.WxCpDepart;
import me.chanjar.weixin.cp.bean.WxCpDepart;
import org.testng.Assert;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;

import me.chanjar.weixin.enterprise.exception.WxErrorException;
import me.chanjar.weixin.common.exception.WxErrorException;

import com.google.inject.Inject;


weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpMediaAPITest.java → weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMediaAPITest.java View File

@@ -1,17 +1,17 @@
package me.chanjar.weixin.enterprise.api;
package me.chanjar.weixin.cp.api;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;

import me.chanjar.weixin.enterprise.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.enterprise.exception.WxErrorException;
import me.chanjar.weixin.common.exception.WxErrorException;

import com.google.inject.Inject;


weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpMessageAPITest.java → weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageAPITest.java View File

@@ -1,10 +1,10 @@
package me.chanjar.weixin.enterprise.api;
package me.chanjar.weixin.cp.api;

import me.chanjar.weixin.enterprise.bean.WxCpMessage;
import me.chanjar.weixin.cp.bean.WxCpMessage;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;

import me.chanjar.weixin.enterprise.exception.WxErrorException;
import me.chanjar.weixin.common.exception.WxErrorException;

import com.google.inject.Inject;

@@ -21,7 +21,7 @@ public class WxCpMessageAPITest {
protected WxCpServiceImpl wxService;

public void testSendCustomMessage() throws WxErrorException {
ApiTestModule.WxXmlCpConfigStorage configStorage = (ApiTestModule.WxXmlCpConfigStorage) wxService.wxCpConfigStorage;
ApiTestModule.WxXmlCpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlCpInMemoryConfigStorage) wxService.wxCpConfigStorage;
WxCpMessage message1 = new WxCpMessage();
message1.setAgentId(configStorage.getAgentId());
message1.setMsgType(WxCpConsts.CUSTOM_MSG_TEXT);

weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpMessageRouterTest.java → weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageRouterTest.java View File

@@ -1,9 +1,9 @@
package me.chanjar.weixin.enterprise.api;
package me.chanjar.weixin.cp.api;

import java.util.Map;

import me.chanjar.weixin.enterprise.bean.WxCpXmlMessage;
import me.chanjar.weixin.enterprise.bean.WxCpXmlOutMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpTagAPITest.java → weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpTagAPITest.java View File

@@ -1,8 +1,8 @@
package me.chanjar.weixin.enterprise.api;
package me.chanjar.weixin.cp.api;

import com.google.inject.Inject;
import me.chanjar.weixin.enterprise.bean.WxCpTag;
import me.chanjar.weixin.enterprise.bean.WxCpUser;
import me.chanjar.weixin.cp.bean.WxCpTag;
import me.chanjar.weixin.cp.bean.WxCpUser;
import org.testng.Assert;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
@@ -41,7 +41,7 @@ public class WxCpTagAPITest {
@Test(dependsOnMethods = "testTagGet")
public void testTagAddUsers() throws Exception {
List<String> userIds = new ArrayList<String>();
userIds.add(((ApiTestModule.WxXmlCpConfigStorage)configStorage).getUserId());
userIds.add(((ApiTestModule.WxXmlCpInMemoryConfigStorage)configStorage).getUserId());
wxService.tagAddUsers(tagId, userIds);
}

@@ -54,7 +54,7 @@ public class WxCpTagAPITest {
@Test(dependsOnMethods = "testTagGetUsers")
public void testTagRemoveUsers() throws Exception {
List<String> userIds = new ArrayList<String>();
userIds.add(((ApiTestModule.WxXmlCpConfigStorage)configStorage).getUserId());
userIds.add(((ApiTestModule.WxXmlCpInMemoryConfigStorage)configStorage).getUserId());
wxService.tagRemoveUsers(tagId, userIds);
}


weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpUserAPITest.java → weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpUserAPITest.java View File

@@ -1,9 +1,9 @@
package me.chanjar.weixin.enterprise.api;
package me.chanjar.weixin.cp.api;

import com.google.inject.Inject;
import me.chanjar.weixin.enterprise.bean.WxCpDepart;
import me.chanjar.weixin.enterprise.bean.WxCpUser;
import me.chanjar.weixin.enterprise.exception.WxErrorException;
import me.chanjar.weixin.cp.bean.WxCpDepart;
import me.chanjar.weixin.cp.bean.WxCpUser;
import me.chanjar.weixin.common.exception.WxErrorException;
import org.testng.Assert;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;

weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpMenuAPITest.java → weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxMenuAPITest.java View File

@@ -1,8 +1,8 @@
package me.chanjar.weixin.enterprise.api;
package me.chanjar.weixin.cp.api;

import javax.xml.bind.JAXBException;

import me.chanjar.weixin.enterprise.bean.WxCpMenu;
import me.chanjar.weixin.common.bean.WxMenu;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Guice;
@@ -10,8 +10,8 @@ import org.testng.annotations.Test;

import com.google.inject.Inject;

import me.chanjar.weixin.enterprise.bean.WxCpMenu.WxMenuButton;
import me.chanjar.weixin.enterprise.exception.WxErrorException;
import me.chanjar.weixin.common.bean.WxMenu.WxMenuButton;
import me.chanjar.weixin.common.exception.WxErrorException;

/**
* 测试菜单
@@ -20,14 +20,14 @@ import me.chanjar.weixin.enterprise.exception.WxErrorException;
*/
@Test(groups="menuAPI", dependsOnGroups="baseAPI")
@Guice(modules = ApiTestModule.class)
public class WxCpMenuAPITest {
public class WxMenuAPITest {

@Inject
protected WxCpServiceImpl wxService;
@Test(dataProvider = "menu")
public void testCreateMenu(WxCpMenu wxCpMenu) throws WxErrorException {
wxService.menuCreate(wxCpMenu);
public void testCreateMenu(WxMenu wxMenu) throws WxErrorException {
wxService.menuCreate(wxMenu);
}
@Test(dependsOnMethods = { "testCreateMenu"})
@@ -42,7 +42,7 @@ public class WxCpMenuAPITest {
@DataProvider(name="menu")
public Object[][] getMenu() throws JAXBException {
WxCpMenu menu = new WxCpMenu();
WxMenu menu = new WxMenu();
WxMenuButton button1 = new WxMenuButton();
button1.setType(WxCpConsts.BUTTON_CLICK);
button1.setName("今日歌曲");

weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpMessageTest.java → weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpMessageTest.java View File

@@ -1,10 +1,10 @@
package me.chanjar.weixin.enterprise.bean;
package me.chanjar.weixin.cp.bean;

import me.chanjar.weixin.enterprise.api.WxCpConsts;
import me.chanjar.weixin.cp.api.WxCpConsts;
import org.testng.Assert;
import org.testng.annotations.Test;

import me.chanjar.weixin.enterprise.bean.WxCpMessage.WxArticle;
import me.chanjar.weixin.cp.bean.WxCpMessage.WxArticle;

@Test
public class WxCpMessageTest {

weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpXmlMessageTest.java → weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlMessageTest.java View File

@@ -1,6 +1,6 @@
package me.chanjar.weixin.enterprise.bean;
package me.chanjar.weixin.cp.bean;

import me.chanjar.weixin.enterprise.api.WxCpConsts;
import me.chanjar.weixin.cp.api.WxCpConsts;
import org.testng.Assert;
import org.testng.annotations.Test;


weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutImageMessageTest.java → weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlOutImageMessageTest.java View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.enterprise.bean;
package me.chanjar.weixin.cp.bean;

import org.testng.Assert;
import org.testng.annotations.Test;

weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutNewsMessageTest.java → weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlOutNewsMessageTest.java View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.enterprise.bean;
package me.chanjar.weixin.cp.bean;

import org.testng.Assert;
import org.testng.annotations.Test;

weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutTextMessageTest.java → weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlOutTextMessageTest.java View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.enterprise.bean;
package me.chanjar.weixin.cp.bean;

import org.testng.Assert;
import org.testng.annotations.Test;

weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutVideoMessageTest.java → weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVideoMessageTest.java View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.enterprise.bean;
package me.chanjar.weixin.cp.bean;

import org.testng.Assert;
import org.testng.annotations.Test;

weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutVoiceMessageTest.java → weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVoiceMessageTest.java View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.enterprise.bean;
package me.chanjar.weixin.cp.bean;

import org.testng.Assert;
import org.testng.annotations.Test;

weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/demo/WxTestCpConfigStorage.java → weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpDemoInMemoryConfigStorage.java View File

@@ -1,6 +1,6 @@
package me.chanjar.weixin.enterprise.demo;
package me.chanjar.weixin.cp.demo;

import me.chanjar.weixin.enterprise.api.WxInMemoryCpConfigStorage;
import me.chanjar.weixin.cp.api.WxCpInMemoryConfigStorage;
import org.xml.sax.InputSource;

import javax.xml.bind.JAXBContext;
@@ -16,20 +16,20 @@ import java.io.InputStream;
*/
@XmlRootElement(name = "xml")
@XmlAccessorType(XmlAccessType.FIELD)
class WxTestCpConfigStorage extends WxInMemoryCpConfigStorage {
class WxCpDemoInMemoryConfigStorage extends WxCpInMemoryConfigStorage {

@Override
public String toString() {
return "SimpleWxConfigProvider [corpId=" + corpId + ", corpSecret=" + corpSecret + ", accessToken=" + accessToken
return "SimpleWxConfigProvider [appidOrCorpid=" + corpId + ", corpSecret=" + corpSecret + ", accessToken=" + accessToken
+ ", expiresIn=" + expiresIn + ", token=" + token + ", aesKey=" + aesKey + "]";
}


public static WxTestCpConfigStorage fromXml(InputStream is) throws JAXBException {
Unmarshaller um = JAXBContext.newInstance(WxTestCpConfigStorage.class).createUnmarshaller();
public static WxCpDemoInMemoryConfigStorage fromXml(InputStream is) throws JAXBException {
Unmarshaller um = JAXBContext.newInstance(WxCpDemoInMemoryConfigStorage.class).createUnmarshaller();
InputSource inputSource = new InputSource(is);
inputSource.setEncoding("utf-8");
return (WxTestCpConfigStorage) um.unmarshal(inputSource);
return (WxCpDemoInMemoryConfigStorage) um.unmarshal(inputSource);
}

}

weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/demo/WxCpTestServer.java → weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpDemoServer.java View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.enterprise.demo;
package me.chanjar.weixin.cp.demo;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletHandler;
@@ -6,14 +6,14 @@ import org.eclipse.jetty.servlet.ServletHandler;
/**
* @author Daniel Qian
*/
public class WxCpTestServer {
public class WxCpDemoServer {
public static void main(String[] args) throws Exception {
Server server = new Server(8080);

ServletHandler handler = new ServletHandler();
server.setHandler(handler);

handler.addServletWithMapping(WxCpTestServlet.class, "/*");
handler.addServletWithMapping(WxCpDemoServlet.class, "/*");
server.start();
server.join();
}

weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/demo/WxCpTestServlet.java → weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpDemoServlet.java View File

@@ -1,10 +1,10 @@
package me.chanjar.weixin.enterprise.demo;
package me.chanjar.weixin.cp.demo;

import me.chanjar.weixin.enterprise.api.*;
import me.chanjar.weixin.enterprise.bean.WxCpXmlMessage;
import me.chanjar.weixin.enterprise.bean.WxCpXmlOutMessage;
import me.chanjar.weixin.enterprise.bean.WxCpXmlOutTextMessage;
import me.chanjar.weixin.enterprise.util.crypto.WxCryptUtil;
import me.chanjar.weixin.cp.api.*;
import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlOutTextMessage;
import me.chanjar.weixin.cp.util.crypto.WxCpCryptUtil;
import org.apache.commons.lang3.StringUtils;

import javax.servlet.ServletException;
@@ -19,7 +19,7 @@ import java.util.Map;
/**
* @author Daniel Qian
*/
public class WxCpTestServlet extends HttpServlet {
public class WxCpDemoServlet extends HttpServlet {

protected WxCpService wxCpService;
protected WxCpConfigStorage wxCpConfigStorage;
@@ -30,7 +30,7 @@ public class WxCpTestServlet extends HttpServlet {
super.init();
try {
InputStream is1 = ClassLoader.getSystemResourceAsStream("test-config.xml");
WxTestCpConfigStorage config = WxTestCpConfigStorage.fromXml(is1);
WxCpDemoInMemoryConfigStorage config = WxCpDemoInMemoryConfigStorage.fromXml(is1);

wxCpConfigStorage = config;
wxCpService = new WxCpServiceImpl();
@@ -77,7 +77,7 @@ public class WxCpTestServlet extends HttpServlet {
response.getWriter().println("非法请求");
return;
}
WxCryptUtil cryptUtil = new WxCryptUtil(wxCpConfigStorage);
WxCpCryptUtil cryptUtil = new WxCpCryptUtil(wxCpConfigStorage);
String plainText = cryptUtil.decrypt(echostr);
// 说明是一个仅仅用来验证的请求,回显echostr
response.getWriter().println(plainText);

weixin-java-enterprise/src/test/resources/mm.jpeg → weixin-java-cp/src/test/resources/mm.jpeg View File


weixin-java-enterprise/src/test/resources/mm.mp3 → weixin-java-cp/src/test/resources/mm.mp3 View File


weixin-java-enterprise/src/test/resources/mm.mp4 → weixin-java-cp/src/test/resources/mm.mp4 View File


weixin-java-enterprise/src/test/resources/test-config.sample.xml → weixin-java-cp/src/test/resources/test-config.sample.xml View File


+ 28
- 0
weixin-java-cp/src/test/resources/testng.xml View File

@@ -0,0 +1,28 @@
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Weixin-java-tool-suite" verbose="1">
<test name="API_Test">
<classes>
<class name="me.chanjar.weixin.cp.api.WxCpBaseAPITest" />
<class name="me.chanjar.weixin.cp.api.WxCpMessageAPITest" />
<class name="me.chanjar.weixin.cp.api.WxMenuAPITest" />
<class name="me.chanjar.weixin.cp.api.WxCpDepartAPITest" />
<class name="me.chanjar.weixin.cp.api.WxCpMediaAPITest" />
<class name="me.chanjar.weixin.cp.api.WxCpMessageRouterTest" />
<class name="me.chanjar.weixin.cp.api.WxCpTagAPITest" />
<class name="me.chanjar.weixin.cp.api.WxCpUserAPITest" />
</classes>
</test>

<test name="Bean_Test">
<classes>
<class name="me.chanjar.weixin.cp.bean.WxCpMessageTest" />
<class name="me.chanjar.weixin.cp.bean.WxCpXmlMessageTest" />
<class name="me.chanjar.weixin.cp.bean.WxCpXmlOutImageMessageTest" />
<class name="me.chanjar.weixin.cp.bean.WxCpXmlOutNewsMessageTest" />
<class name="me.chanjar.weixin.cp.bean.WxCpXmlOutVideoMessageTest" />
<class name="me.chanjar.weixin.cp.bean.WxCpXmlOutVoiceMessageTest" />
<class name="me.chanjar.weixin.cp.bean.WxCpXmlOutTextMessageTest" />
</classes>
</test>
</suite>

+ 0
- 56
weixin-java-enterprise/README.md View File

@@ -1,56 +0,0 @@
weixin-java-tools
===========

微信java开发工具集,本项目主要分为两大块:微信消息路由器、微信Java API

特性列表:

1. 不基于Servlet、和其他MVC框架,仅作为工具使用,提供更多的灵活性
2. 详尽的单元测试代码,可以拿来当example用
3. 详尽的javadoc
4. access token过期自动刷新的功能
5. 微信服务端繁忙自动重试的功能
6. 提供微信错误信息的异常处理机制


详细文档请看 [wiki](https://github.com/chanjarster/weixin-java-tools/wiki)

# Quickstart

在你的maven项目中添加:
```xml
<dependency>
<groupId>me.chanjar</groupId>
<artifactId>weixin-java-tools</artifactId>
<version>1.0.2</version>
</dependency>
```

如果要使用``*-SNAPSHOT``版,则需要在你的``pom.xml``中添加这段:

```xml
<repositories>
<repository>
<snapshots />
<id>sonatype snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
</repositories>
```

## Hello World
```java
WxConfigStorage config = new WxInMemoryConfigStorage();
config.setAppId(...); // 设置微信企业号的appid
config.setSecret(...); // 设置微信企业号的app corpSecret
config.setToken(...); // 设置微信企业号的token

WxServiceImpl wxService = new WxServiceImpl();
wxService.setWxConfigStorage(config);

// 用户的openid在下面地址获得
// https://mp.weixin.qq.com/debug/cgi-bin/apiinfo?t=index&type=用户管理&form=获取关注者列表接口%20/user/get
String userId = ...;
WxCustomMessage message = WxCustomMessage.TEXT().toUser(userId).content("Hello World").build();
wxService.customMessageSend(message);
```

+ 0
- 31
weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/bean/result/WxAccessToken.java View File

@@ -1,31 +0,0 @@
package me.chanjar.weixin.common.bean.result;

import me.chanjar.weixin.enterprise.util.json.WxCpGsonBuilder;

public class WxAccessToken {

private String accessToken;
private int expiresIn = -1;

public String getAccessToken() {
return accessToken;
}

public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}

public int getExpiresIn() {
return expiresIn;
}

public void setExpiresIn(int expiresIn) {
this.expiresIn = expiresIn;
}

public static WxAccessToken fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxAccessToken.class);
}
}

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save