Skip to content

Commit a370309

Browse files
authored
Merge pull request #30 from wechat-group/develop
merge Develop
2 parents 2fdfe78 + 8bca9e7 commit a370309

File tree

241 files changed

+5342
-2900
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

241 files changed

+5342
-2900
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ test-output
1313
hs_err_pid*
1414

1515
target
16+
bin
1617
.project
1718
.classpath
1819
.settings
@@ -21,3 +22,7 @@ sw-pom.xml
2122
*.iml
2223
test-config.xml
2324
.idea
25+
/.gradle/
26+
/gradle/
27+
*.bat
28+
/gradlew

README.md

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,7 @@
88
#### 由于本次更新涉及接口调整比较大,主要是公众号的调整,企业号无过多调整,主要是为了解决主接口类过于庞大不方便管理的问题,将接口实现代码按模块进行拆分。因此版本号直接从1.X.X直接升级到2.0.0,所以如果习惯于1.X.X版本的同学不想做过多更改的话,请慎重考虑升级到最新版本。
99
---
1010

11-
#### 本项目主要存放在github上,地址为 :
12-
* https://github.com/wechat-group/weixin-java-tools
13-
* ===========但同时会在其他几个网站同步更新,地址分别是:
14-
* https://bitbucket.org/binarywang/weixin-java-tools
15-
* http://git.oschina.net/binary/weixin-java-tools
16-
* https://git.coding.net/binarywang/weixin-java-tools.git
17-
1811
### 详细开发文档请看 [wiki](https://github.com/chanjarster/weixin-java-tools/wiki)
19-
20-
## 目前可参考的Demo项目:
21-
* https://github.com/wechat-group/weixin-java-tools-springmvc
22-
* https://github.com/wechat-group/weixin-mp-demo
23-
* ===========以下为备份仓库,会保持跟主仓库同步
24-
* http://git.oschina.net/binary/weixin-mp-demo
25-
* https://bitbucket.org/binarywang/weixin-mp-demo
26-
2712
===========
2813
## 开发交流工具:
2914
* QQ群:343954419 [![Join QQ Group](http://pub.idqqimg.com/wpa/images/group.png)](http://shang.qq.com/wpa/qunwpa?idkey=078f7a153d243853e24cf2b542e7a6ccbf2a592bc138080f84d11297f736ec46)
@@ -40,10 +25,9 @@
4025
- [【企业号】](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.github.binarywang%22%20AND%20a%3A%22weixin-java-cp%22)
4126

4227

43-
## Quick Start
44-
45-
* 如果要开发公众号(订阅号、服务号)应用,在你的maven项目中添加:
28+
## Maven & Gradle
4629

30+
* 公众号(订阅号、服务号):
4731
```xml
4832
<dependency>
4933
<groupId>com.github.binarywang</groupId>
@@ -52,8 +36,11 @@
5236
</dependency>
5337
```
5438

55-
* 如果要开发企业号应用,在你的maven项目中添加:
39+
```groovy
40+
compile 'com.github.binarywang:weixin-java-mp:2.0.0'
41+
```
5642

43+
* 企业号:
5744
```xml
5845
<dependency>
5946
<groupId>com.github.binarywang</groupId>
@@ -62,6 +49,25 @@
6249
</dependency>
6350
```
6451

52+
```groovy
53+
compile 'com.github.binarywang:weixin-java-cp:2.0.0'
54+
```
55+
56+
#### 本项目主要存放在github上,地址为 :
57+
* https://github.com/wechat-group/weixin-java-tools
58+
* ===========但同时会在其他几个网站同步更新,地址分别是:
59+
* https://bitbucket.org/binarywang/weixin-java-tools
60+
* http://git.oschina.net/binary/weixin-java-tools
61+
* https://git.coding.net/binarywang/weixin-java-tools.git
62+
63+
64+
## 目前可参考的Demo项目:
65+
* https://github.com/wechat-group/weixin-java-tools-springmvc
66+
* https://github.com/wechat-group/weixin-mp-demo
67+
* ===========以下为备份仓库,会保持跟主仓库同步
68+
* http://git.oschina.net/binary/weixin-mp-demo
69+
* https://bitbucket.org/binarywang/weixin-mp-demo
70+
6571
## 关于代码贡献
6672

6773
* 非常欢迎和感谢对本项目发起Pull Request的同学,本项目可以采用两种方式接受代码贡献:

build.gradle

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
allprojects {
2+
apply plugin: 'maven'
3+
4+
group = 'com.github.binarywang'
5+
version = '2.1.0-SNAPSHOT'
6+
}
7+
8+
subprojects {
9+
apply plugin: 'java'
10+
sourceCompatibility = 1.7
11+
targetCompatibility = 1.7
12+
13+
14+
repositories {
15+
mavenLocal()
16+
17+
maven { url "http://maven.aliyun.com/nexus/content/groups/public" }
18+
}
19+
20+
21+
dependencies {
22+
compile group: 'org.slf4j', name: 'slf4j-api', version:'1.7.10'
23+
compile group: 'org.apache.httpcomponents', name: 'fluent-hc', version:'4.5'
24+
compile group: 'org.apache.httpcomponents', name: 'httpmime', version:'4.5'
25+
compile group: 'org.jodd', name: 'jodd-http', version:'3.6.7'
26+
compile group: 'com.google.code.gson', name: 'gson', version:'2.7'
27+
compile group: 'commons-codec', name: 'commons-codec', version:'1.10'
28+
compile group: 'commons-io', name: 'commons-io', version:'2.5'
29+
compile group: 'org.apache.commons', name: 'commons-lang3', version:'3.4'
30+
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version:'2.8.0'
31+
compile group: 'redis.clients', name: 'jedis', version:'2.9.0'
32+
testCompile group: 'ch.qos.logback', name: 'logback-classic', version:'1.1.2'
33+
}
34+
}

pom.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>com.github.binarywang</groupId>
77
<artifactId>weixin-java-parent</artifactId>
8-
<version>2.0.0</version>
8+
<version>2.1.0</version>
99
<packaging>pom</packaging>
1010
<name>WeiXin Java Tools - Parent</name>
1111
<description>微信公众号、企业号上级POM</description>
@@ -50,6 +50,7 @@
5050
<logback.version>1.1.2</logback.version>
5151
<jodd-http.version>3.6.7</jodd-http.version>
5252
<jackson.version>2.8.0</jackson.version>
53+
<jedis.version>2.9.0</jedis.version>
5354
<gson.version>2.7</gson.version>
5455
<commons-lang3.version>3.4</commons-lang3.version>
5556
<commons-io.version>2.5</commons-io.version>
@@ -110,8 +111,13 @@
110111
<artifactId>jackson-databind</artifactId>
111112
<version>${jackson.version}</version>
112113
</dependency>
114+
<dependency>
115+
<groupId>redis.clients</groupId>
116+
<artifactId>jedis</artifactId>
117+
<version>${jedis.version}</version>
118+
</dependency>
113119
</dependencies>
114-
120+
115121
<dependencyManagement>
116122
<dependencies>
117123
<dependency>

settings.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
rootProject.name = 'weixin-java-parent'
2+
include ':weixin-java-common'
3+
include ':weixin-java-cp'
4+
include ':weixin-java-mp'
5+
6+
project(':weixin-java-common').projectDir = "$rootDir/weixin-java-common" as File
7+
project(':weixin-java-cp').projectDir = "$rootDir/weixin-java-cp" as File
8+
project(':weixin-java-mp').projectDir = "$rootDir/weixin-java-mp" as File

weixin-java-common/build.gradle

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
description = 'WeiXin Java Tools - Common'
3+
dependencies {
4+
compile group: 'com.thoughtworks.xstream', name: 'xstream', version:'1.4.7'
5+
testCompile group: 'junit', name: 'junit', version:'4.11'
6+
testCompile group: 'org.testng', name: 'testng', version:'6.8.7'
7+
testCompile group: 'org.mockito', name: 'mockito-all', version:'1.9.5'
8+
testCompile group: 'com.google.inject', name: 'guice', version:'3.0'
9+
testCompile group: 'org.eclipse.jetty', name: 'jetty-server', version:'9.3.0.M0'
10+
testCompile group: 'org.eclipse.jetty', name: 'jetty-servlet', version:'9.3.0.M0'
11+
}
12+
test.useTestNG()

weixin-java-common/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.github.binarywang</groupId>
88
<artifactId>weixin-java-parent</artifactId>
9-
<version>2.0.0</version>
9+
<version>2.1.0</version>
1010
</parent>
1111

1212
<artifactId>weixin-java-common</artifactId>

weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxConsts.java

Lines changed: 56 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class WxConsts {
1919
public static final String XML_MSG_LINK = "link";
2020
public static final String XML_MSG_EVENT = "event";
2121
public static final String XML_TRANSFER_CUSTOMER_SERVICE = "transfer_customer_service";
22-
22+
2323
///////////////////////
2424
// 主动发送消息(即客服消息)的消息类型
2525
///////////////////////
@@ -33,7 +33,7 @@ public class WxConsts {
3333
public static final String CUSTOM_MSG_TRANSFER_CUSTOMER_SERVICE = "transfer_customer_service";
3434
public static final String CUSTOM_MSG_SAFE_NO = "0";
3535
public static final String CUSTOM_MSG_SAFE_YES = "1";
36-
36+
3737
///////////////////////
3838
// 群发消息的消息类型
3939
///////////////////////
@@ -42,7 +42,7 @@ public class WxConsts {
4242
public static final String MASS_MSG_VOICE = "voice";
4343
public static final String MASS_MSG_IMAGE = "image";
4444
public static final String MASS_MSG_VIDEO = "mpvideo";
45-
45+
4646
///////////////////////
4747
// 群发消息后微信端推送给服务器的反馈消息
4848
///////////////////////
@@ -57,25 +57,11 @@ public class WxConsts {
5757
public static final String MASS_ST_涉嫌版权 = "err(20013)";
5858
public static final String MASS_ST_涉嫌互推_互相宣传 = "err(22000)";
5959
public static final String MASS_ST_涉嫌其他 = "err(21000)";
60-
60+
6161
/**
6262
* 群发反馈消息代码所对应的文字描述
6363
*/
6464
public static final Map<String, String> MASS_ST_2_DESC = new HashMap<String, String>();
65-
static {
66-
MASS_ST_2_DESC.put(MASS_ST_SUCCESS, "发送成功");
67-
MASS_ST_2_DESC.put(MASS_ST_FAIL, "发送失败");
68-
MASS_ST_2_DESC.put(MASS_ST_涉嫌广告, "涉嫌广告");
69-
MASS_ST_2_DESC.put(MASS_ST_涉嫌政治, "涉嫌政治");
70-
MASS_ST_2_DESC.put(MASS_ST_涉嫌社会, "涉嫌社会");
71-
MASS_ST_2_DESC.put(MASS_ST_涉嫌色情, "涉嫌色情");
72-
MASS_ST_2_DESC.put(MASS_ST_涉嫌违法犯罪, "涉嫌违法犯罪");
73-
MASS_ST_2_DESC.put(MASS_ST_涉嫌欺诈, "涉嫌欺诈");
74-
MASS_ST_2_DESC.put(MASS_ST_涉嫌版权, "涉嫌版权");
75-
MASS_ST_2_DESC.put(MASS_ST_涉嫌互推_互相宣传, "涉嫌互推_互相宣传");
76-
MASS_ST_2_DESC.put(MASS_ST_涉嫌其他, "涉嫌其他");
77-
}
78-
7965
///////////////////////
8066
// 微信端推送过来的事件类型
8167
///////////////////////
@@ -103,11 +89,9 @@ public class WxConsts {
10389
public static final String EVT_USER_VIEW_CARD = "user_view_card";
10490
public static final String EVT_USER_ENTER_SESSION_FROM_CARD = "user_enter_session_from_card";
10591
public static final String EVT_CARD_SKU_REMIND = "card_sku_remind"; // 库存报警
106-
10792
public static final String EVT_KF_CREATE_SESSION = "kf_create_session"; // 客服接入会话
10893
public static final String EVT_KF_CLOSE_SESSION = "kf_close_session"; // 客服关闭会话
10994
public static final String EVT_KF_SWITCH_SESSION = "kf_switch_session"; // 客服转接会话
110-
11195
///////////////////////
11296
// 上传多媒体文件的类型
11397
///////////////////////
@@ -116,53 +100,89 @@ public class WxConsts {
116100
public static final String MEDIA_VIDEO = "video";
117101
public static final String MEDIA_THUMB = "thumb";
118102
public static final String MEDIA_FILE = "file";
119-
120103
///////////////////////
121104
// 文件类型
122105
///////////////////////
123106
public static final String FILE_JPG = "jpeg";
124107
public static final String FILE_MP3 = "mp3";
125108
public static final String FILE_AMR = "amr";
126109
public static final String FILE_MP4 = "mp4";
110+
/**
111+
* 点击推事件
112+
*/
113+
public static final String BUTTON_CLICK = "click";
127114

128115

129116
///////////////////////
130117
// 自定义菜单的按钮类型
131118
///////////////////////
132-
/** 点击推事件 */
133-
public static final String BUTTON_CLICK = "click";
134-
/** 跳转URL */
119+
/**
120+
* 跳转URL
121+
*/
135122
public static final String BUTTON_VIEW = "view";
136-
/** 扫码推事件 */
123+
/**
124+
* 扫码推事件
125+
*/
137126
public static final String BUTTON_SCANCODE_PUSH = "scancode_push";
138-
/** 扫码推事件且弹出“消息接收中”提示框 */
127+
/**
128+
* 扫码推事件且弹出“消息接收中”提示框
129+
*/
139130
public static final String BUTTON_SCANCODE_WAITMSG = "scancode_waitmsg";
140-
/** 弹出系统拍照发图 */
131+
/**
132+
* 弹出系统拍照发图
133+
*/
141134
public static final String BUTTON_PIC_SYSPHOTO = "pic_sysphoto";
142-
/** 弹出拍照或者相册发图 */
135+
/**
136+
* 弹出拍照或者相册发图
137+
*/
143138
public static final String BUTTON_PIC_PHOTO_OR_ALBUM = "pic_photo_or_album";
144-
/** 弹出微信相册发图器 */
139+
/**
140+
* 弹出微信相册发图器
141+
*/
145142
public static final String BUTTON_PIC_WEIXIN = "pic_weixin";
146-
/** 弹出地理位置选择器 */
143+
/**
144+
* 弹出地理位置选择器
145+
*/
147146
public static final String BUTTON_LOCATION_SELECT = "location_select";
148-
/** 下发消息(除文本消息) */
147+
/**
148+
* 下发消息(除文本消息)
149+
*/
149150
public static final String BUTTON_MEDIA_ID = "media_id";
150-
/** 跳转图文消息URL */
151+
/**
152+
* 跳转图文消息URL
153+
*/
151154
public static final String BUTTON_VIEW_LIMITED = "view_limited";
155+
/**
156+
* 不弹出授权页面,直接跳转,只能获取用户openid
157+
*/
158+
public static final String OAUTH2_SCOPE_BASE = "snsapi_base";
152159

153160
///////////////////////
154161
// oauth2网页授权的scope
155162
///////////////////////
156-
/** 不弹出授权页面,直接跳转,只能获取用户openid */
157-
public static final String OAUTH2_SCOPE_BASE = "snsapi_base";
158-
/** 弹出授权页面,可通过openid拿到昵称、性别、所在地。并且,即使在未关注的情况下,只要用户授权,也能获取其信息 */
163+
/**
164+
* 弹出授权页面,可通过openid拿到昵称、性别、所在地。并且,即使在未关注的情况下,只要用户授权,也能获取其信息
165+
*/
159166
public static final String OAUTH2_SCOPE_USER_INFO = "snsapi_userinfo";
160-
161167
///////////////////////
162168
// 永久素材类型
163169
///////////////////////
164170
public static final String MATERIAL_NEWS = "news";
165171
public static final String MATERIAL_VOICE = "voice";
166172
public static final String MATERIAL_IMAGE = "image";
167173
public static final String MATERIAL_VIDEO = "video";
174+
175+
static {
176+
MASS_ST_2_DESC.put(MASS_ST_SUCCESS, "发送成功");
177+
MASS_ST_2_DESC.put(MASS_ST_FAIL, "发送失败");
178+
MASS_ST_2_DESC.put(MASS_ST_涉嫌广告, "涉嫌广告");
179+
MASS_ST_2_DESC.put(MASS_ST_涉嫌政治, "涉嫌政治");
180+
MASS_ST_2_DESC.put(MASS_ST_涉嫌社会, "涉嫌社会");
181+
MASS_ST_2_DESC.put(MASS_ST_涉嫌色情, "涉嫌色情");
182+
MASS_ST_2_DESC.put(MASS_ST_涉嫌违法犯罪, "涉嫌违法犯罪");
183+
MASS_ST_2_DESC.put(MASS_ST_涉嫌欺诈, "涉嫌欺诈");
184+
MASS_ST_2_DESC.put(MASS_ST_涉嫌版权, "涉嫌版权");
185+
MASS_ST_2_DESC.put(MASS_ST_涉嫌互推_互相宣传, "涉嫌互推_互相宣传");
186+
MASS_ST_2_DESC.put(MASS_ST_涉嫌其他, "涉嫌其他");
187+
}
168188
}

weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxMessageDuplicateChecker.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ public interface WxMessageDuplicateChecker {
1010

1111
/**
1212
* <h2>公众号的排重方式</h2>
13-
*
13+
* <p>
1414
* <p>普通消息:关于重试的消息排重,推荐使用msgid排重。<a href="http://mp.weixin.qq.com/wiki/10/79502792eef98d6e0c6e1739da387346.html">文档参考</a>。</p>
1515
* <p>事件消息:关于重试的消息排重,推荐使用FromUserName + CreateTime 排重。<a href="http://mp.weixin.qq.com/wiki/2/5baf56ce4947d35003b86a9805634b1e.html">文档参考</a></p>
16-
*
16+
* <p>
1717
* <h2>企业号的排重方式</h2>
18-
*
18+
* <p>
1919
* 官方文档完全没有写,参照公众号的方式排重。
20-
*
20+
* <p>
2121
* <p>或者可以采取更简单的方式,如果有MsgId就用MsgId排重,如果没有就用FromUserName+CreateTime排重</p>
22+
*
2223
* @param messageId messageId需要根据上面讲的方式构造
2324
* @return 如果是重复消息,返回true,否则返回false
2425
*/

weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxMessageInMemoryDuplicateChecker.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public WxMessageInMemoryDuplicateChecker() {
4646

4747
/**
4848
* WxMsgIdInMemoryDuplicateChecker构造函数
49-
* @param timeToLive 一个消息ID在内存的过期时间:毫秒
49+
*
50+
* @param timeToLive 一个消息ID在内存的过期时间:毫秒
5051
* @param clearPeriod 每隔多少周期检查消息ID是否过期:毫秒
5152
*/
5253
public WxMessageInMemoryDuplicateChecker(Long timeToLive, Long clearPeriod) {

0 commit comments

Comments
 (0)