Skip to content

Commit 18e7f7e

Browse files
committed
Merge branch 'develop' into store
2 parents e9a21b2 + dae8e40 commit 18e7f7e

File tree

23 files changed

+1749
-436
lines changed

23 files changed

+1749
-436
lines changed

README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,39 @@
2020
===========
2121

2222
## 版本说明
23-
* 本项目定为每月发布一次正式版,版本号格式为X.X.0(如2.0.0,2.1.0等),月初或月底发布新版本,遇到重大问题需修复会及时提交新版本,欢迎大家随时提交Pull Request。
24-
* BUG修复和新特性一般会先发布成小版本作为临时版本(如2.0.1,2.0.2等,即尾号不为0,以区别于正式版)。
25-
* 目前最新版本号为 ![Maven Central](https://img.shields.io/maven-central/v/com.github.binarywang/weixin-java-parent.svg) ,也可以通过访问如下地址查看所有最新的版本:
26-
- [【公众号】](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.github.binarywang%22%20AND%20a%3A%22weixin-java-mp%22)
27-
- [【企业号】](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.github.binarywang%22%20AND%20a%3A%22weixin-java-cp%22)
28-
23+
* 本项目定为每月发布一次正式版,版本号格式为X.X.0(如2.0.0,2.1.0等),月初或月底发布新版本,遇到重大问题需修复会及时提交新版本,欢迎大家随时提交Pull Request;
24+
* BUG修复和新特性一般会先发布成小版本作为临时版本(如2.0.1,2.0.2等,即尾号不为0,以区别于正式版);
25+
* 目前最新版本号为 ![Maven Central](https://img.shields.io/maven-central/v/com.github.binarywang/weixin-java-parent.svg) ,也可以通过访问链接[【公众号】](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.github.binarywang%22%20AND%20a%3A%22weixin-java-mp%22) [【企业号】](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.github.binarywang%22%20AND%20a%3A%22weixin-java-cp%22)
26+
分别查看所有最新的版本。
2927

3028
## Maven & Gradle
3129

3230
* 公众号(订阅号、服务号):
31+
32+
maven:
3333
```xml
3434
<dependency>
3535
<groupId>com.github.binarywang</groupId>
3636
<artifactId>weixin-java-mp</artifactId>
3737
<version>2.1.0</version>
3838
</dependency>
3939
```
40-
40+
gradle:
4141
```groovy
4242
compile 'com.github.binarywang:weixin-java-mp:2.1.0'
4343
```
4444

4545
* 企业号:
46+
47+
maven:
4648
```xml
4749
<dependency>
4850
<groupId>com.github.binarywang</groupId>
4951
<artifactId>weixin-java-cp</artifactId>
5052
<version>2.1.0</version>
5153
</dependency>
5254
```
53-
55+
gradle:
5456
```groovy
5557
compile 'com.github.binarywang:weixin-java-cp:2.1.0'
5658
```
@@ -63,16 +65,14 @@ compile 'com.github.binarywang:weixin-java-cp:2.1.0'
6365
* https://git.coding.net/binarywang/weixin-java-tools.git
6466

6567

66-
## 目前可参考的Demo项目:
67-
* https://github.com/wechat-group/weixin-java-tools-springmvc
68-
* https://github.com/wechat-group/weixin-mp-demo
69-
* ===========以下为备份仓库,会保持跟主仓库同步
70-
* http://git.oschina.net/binary/weixin-mp-demo
71-
* https://bitbucket.org/binarywang/weixin-mp-demo
68+
## 目前可参考的Demo项目有两个:
69+
1. https://github.com/wechat-group/weixin-mp-demo
70+
1. https://github.com/wechat-group/weixin-java-tools-springmvc
7271

7372
## 关于代码贡献
73+
* 非常欢迎和感谢对本项目发起Pull Request的同学,本项目代码风格为使用2个空格代表一个Tab,因此在提交代码时请注意一下,否则很容易在IDE格式化代码后与原代码产生大量diff,这样会给其他人阅读代码带来极大的困扰。
74+
* 为了便于设置,本项目引入editorconfig插件,请使用eclipse的同学在贡献代码前安装相关插件,IntelliJ IDEA则自带支持,无需额外安装插件。
75+
* 本项目可以采用两种方式接受代码贡献:
7476

75-
* 非常欢迎和感谢对本项目发起Pull Request的同学,本项目可以采用两种方式接受代码贡献:
76-
* 第一种就是基于[Git Flow](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow)开发流程,因此在发起Pull Request的时候请选择develop分支。
77-
* 另外一种贡献代码的方式就是加入SDK Developers开发组,如果对自己的代码足够自信,可以随时提交代码,注意要随时进行单元测试,保证提交代码没有明显问题,具体加入方式,请咨询管理员。
78-
* 本项目代码风格为使用2个空格代表一个Tab,因此在提交代码时请注意一下,否则很容易在IDE格式化代码后与原代码产生大量diff,这样会给其他人阅读代码带来极大的困扰。
77+
1. 第一种就是基于[Git Flow](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow)开发流程,因此在发起Pull Request的时候请选择develop分支。
78+
1. 另外一种贡献代码的方式就是加入SDK Developers开发组,如果对自己的代码足够自信,可以随时提交代码,注意要随时进行单元测试,保证提交代码没有明显问题,具体加入方式,请咨询管理员。

build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ subprojects {
1313

1414
repositories {
1515
mavenLocal()
16-
17-
maven { url "http://maven.aliyun.com/nexus/content/groups/public" }
16+
maven { url "http://central.maven.org/maven2" }
17+
//maven { url "http://maven.aliyun.com/nexus/content/groups/public" }
1818
}
1919

2020

@@ -24,6 +24,8 @@ subprojects {
2424
compile group: 'org.apache.httpcomponents', name: 'httpmime', version:'4.5'
2525
compile group: 'org.jodd', name: 'jodd-http', version:'3.6.7'
2626
compile group: 'com.google.code.gson', name: 'gson', version:'2.7'
27+
compile group: 'com.google.guava', name: 'guava', version:'19.0'
28+
compile group: 'org.jooq', name: 'joor', version:'0.9.6'
2729
compile group: 'commons-codec', name: 'commons-codec', version:'1.10'
2830
compile group: 'commons-io', name: 'commons-io', version:'2.5'
2931
compile group: 'org.apache.commons', name: 'commons-lang3', version:'3.4'

pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
<jodd-http.version>3.6.7</jodd-http.version>
5252
<jedis.version>2.9.0</jedis.version>
5353
<gson.version>2.7</gson.version>
54+
<guava.version>19.0</guava.version>
55+
<joor.version>0.9.6</joor.version>
5456
<commons-lang3.version>3.4</commons-lang3.version>
5557
<commons-io.version>2.5</commons-io.version>
5658
<commons-codec.version>1.10</commons-codec.version>
@@ -111,6 +113,14 @@
111113
<version>${jedis.version}</version>
112114
<scope>provided</scope>
113115
</dependency>
116+
<dependency>
117+
<groupId>com.google.guava</groupId>
118+
<artifactId>guava</artifactId>
119+
</dependency>
120+
<dependency>
121+
<groupId>org.jooq</groupId>
122+
<artifactId>joor</artifactId>
123+
</dependency>
114124
</dependencies>
115125

116126
<dependencyManagement>
@@ -151,6 +161,16 @@
151161
<version>${jetty.version}</version>
152162
<scope>test</scope>
153163
</dependency>
164+
<dependency>
165+
<groupId>com.google.guava</groupId>
166+
<artifactId>guava</artifactId>
167+
<version>${guava.version}</version>
168+
</dependency>
169+
<dependency>
170+
<groupId>org.jooq</groupId>
171+
<artifactId>joor</artifactId>
172+
<version>${joor.version}</version>
173+
</dependency>
154174
</dependencies>
155175
</dependencyManagement>
156176

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package me.chanjar.weixin.common.annotation;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
/**
9+
* 标识某个字段是否是必填的
10+
*
11+
* Created by Binary Wang on 2016/9/25.
12+
* @author binarywang (https://github.com/binarywang)
13+
*
14+
*/
15+
@Retention(RetentionPolicy.RUNTIME)
16+
@Target(ElementType.FIELD)
17+
public @interface Required {
18+
19+
}

weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/WxCryptUtil.java

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,8 @@
1919

2020
import java.io.StringReader;
2121
import java.nio.charset.Charset;
22-
import java.util.ArrayList;
2322
import java.util.Arrays;
24-
import java.util.Collections;
25-
import java.util.List;
26-
import java.util.Map;
2723
import java.util.Random;
28-
import java.util.SortedMap;
29-
import java.util.TreeMap;
3024

3125
import javax.crypto.Cipher;
3226
import javax.crypto.spec.IvParameterSpec;
@@ -36,7 +30,6 @@
3630
import javax.xml.parsers.ParserConfigurationException;
3731

3832
import org.apache.commons.codec.binary.Base64;
39-
import org.apache.commons.codec.digest.DigestUtils;
4033
import org.w3c.dom.Document;
4134
import org.w3c.dom.Element;
4235
import org.xml.sax.InputSource;
@@ -79,33 +72,6 @@ public WxCryptUtil(String token, String encodingAesKey,
7972
this.aesKey = Base64.decodeBase64(encodingAesKey + "=");
8073
}
8174

82-
/**
83-
* 微信公众号支付签名算法(详见:http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=4_3)
84-
* @param packageParams 原始参数
85-
* @param signKey 加密Key(即 商户Key)
86-
* @return 签名字符串
87-
*/
88-
public static String createSign(Map<String, String> packageParams,
89-
String signKey) {
90-
SortedMap<String, String> sortedMap = new TreeMap<>();
91-
sortedMap.putAll(packageParams);
92-
93-
List<String> keys = new ArrayList<>(packageParams.keySet());
94-
Collections.sort(keys);
95-
96-
StringBuffer toSign = new StringBuffer();
97-
for (String key : keys) {
98-
String value = packageParams.get(key);
99-
if (null != value && !"".equals(value) && !"sign".equals(key)
100-
&& !"key".equals(key)) {
101-
toSign.append(key + "=" + value + "&");
102-
}
103-
}
104-
toSign.append("key=" + signKey);
105-
String sign = DigestUtils.md5Hex(toSign.toString()).toUpperCase();
106-
return sign;
107-
}
108-
10975
static String extractEncryptPart(String xml) {
11076
try {
11177
DocumentBuilder db = builderLocal.get();

weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/SimplePostRequestExecutor.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package me.chanjar.weixin.common.util.http;
22

3-
import me.chanjar.weixin.common.bean.result.WxError;
4-
import me.chanjar.weixin.common.exception.WxErrorException;
3+
import java.io.IOException;
4+
55
import org.apache.http.Consts;
66
import org.apache.http.HttpHost;
77
import org.apache.http.client.config.RequestConfig;
@@ -10,7 +10,8 @@
1010
import org.apache.http.entity.StringEntity;
1111
import org.apache.http.impl.client.CloseableHttpClient;
1212

13-
import java.io.IOException;
13+
import me.chanjar.weixin.common.bean.result.WxError;
14+
import me.chanjar.weixin.common.exception.WxErrorException;
1415

1516
/**
1617
* 简单的POST请求执行器,请求的参数是String, 返回的结果也是String
@@ -34,6 +35,17 @@ public String execute(CloseableHttpClient httpclient, HttpHost httpProxy, String
3435

3536
try (CloseableHttpResponse response = httpclient.execute(httpPost)) {
3637
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
38+
if (responseContent.isEmpty()) {
39+
throw new WxErrorException(
40+
WxError.newBuilder().setErrorCode(9999).setErrorMsg("无响应内容")
41+
.build());
42+
}
43+
44+
if (responseContent.startsWith("<xml>")) {
45+
//xml格式输出直接返回
46+
return responseContent;
47+
}
48+
3749
WxError error = WxError.fromJson(responseContent);
3850
if (error.getErrorCode() != 0) {
3951
throw new WxErrorException(error);

weixin-java-common/src/main/java/me/chanjar/weixin/common/util/xml/XStreamInitializer.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package me.chanjar.weixin.common.util.xml;
22

3+
import java.io.Writer;
4+
35
import com.thoughtworks.xstream.XStream;
46
import com.thoughtworks.xstream.core.util.QuickWriter;
57
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
@@ -8,8 +10,6 @@
810
import com.thoughtworks.xstream.security.NullPermission;
911
import com.thoughtworks.xstream.security.PrimitiveTypePermission;
1012

11-
import java.io.Writer;
12-
1313
public class XStreamInitializer {
1414

1515
public static XStream getInstance() {
@@ -34,6 +34,11 @@ protected void writeText(QuickWriter writer, String text) {
3434
}
3535

3636
}
37+
38+
@Override
39+
public String encodeNode(String name) {
40+
return name;//防止将_转换成__
41+
}
3742
};
3843
}
3944
});

weixin-java-mp/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<project
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
4-
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
4+
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
55
<modelVersion>4.0.0</modelVersion>
66
<parent>
77
<groupId>com.github.binarywang</groupId>

0 commit comments

Comments
 (0)