Skip to content

准备发布新版本2.4.0 #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 47 commits into from
Nov 30, 2016
Merged
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
8dadf49
更改版本号为snapshot版本
binarywang Nov 1, 2016
fad9aba
将httpclient显式进行依赖,以便于客户端优先使用配置的版本
binarywang Nov 1, 2016
8c00299
同步更新gradle相关配置
binarywang Nov 1, 2016
3ed717a
Update README.md
binarywang Nov 4, 2016
6cf7b08
去掉模版消息里无用的topcolor参数
binarywang Nov 4, 2016
1bd4f68
完善模板消息发送的单元测试,加入颜色
binarywang Nov 4, 2016
f478ceb
按openid群发消息时提供setToUsers方法,方便客户端直接设置所有群发对象的openid列表
binarywang Nov 4, 2016
e3fd108
Update README.md
binarywang Nov 8, 2016
109cab8
Update README.md
binarywang Nov 8, 2016
e4df6c8
重构优化XStreamTransformer代码
binarywang Nov 9, 2016
a887198
补充public方法的注释
binarywang Nov 9, 2016
fce1c2f
Update README.md
binarywang Nov 10, 2016
6dccfc7
upgrade version for maven-compiler-plugin
binarywang Nov 14, 2016
44d6b95
Update README.md
binarywang Nov 14, 2016
86160ca
更新javadoc
binarywang Nov 16, 2016
efa59d5
Update README.md
binarywang Nov 16, 2016
c84767c
Update README.md
binarywang Nov 16, 2016
0b0fbcd
使用大写L代替小写l,以免容易误解
binarywang Nov 17, 2016
25c792b
补充完善部分缺失的javadoc
binarywang Nov 17, 2016
88f0eb8
Update README.md
binarywang Nov 17, 2016
6d01fa5
修改WxCpMessage中agentId的数据类型, String-> Integer
Nov 16, 2016
a37a869
Merge pull request #79 from withinthefog/agentid-fix
binarywang Nov 18, 2016
088a972
为WxMpConfigStorage接口增加autoRefreshToken方法,以方便客户端设置是否自动刷新token. for #77
binarywang Nov 18, 2016
e4d5545
reformat some code
binarywang Nov 21, 2016
72d6aad
修复 #80 menuCreate()方法代码的问题,and reformat code
binarywang Nov 21, 2016
b09c5ae
Merge pull request #1 from wechat-group/develop
ZhaoxiongTan Nov 21, 2016
5f20d2c
图文消息统计接口, statDate类型改为String
ZhaoxiongTan Nov 21, 2016
9eadcf5
Merge pull request #81 from ZhaoxiongTan/develop
binarywang Nov 21, 2016
0acde03
修改获取Token/Ticket时的同步机制,改由通过锁来进行同步,由WxMpConfigStorage来提供锁实现。
ericlogic Nov 21, 2016
6278161
Merge pull request #82 from iwareserictsai/develop
binarywang Nov 22, 2016
b3778d1
添加贡献者信息
binarywang Nov 22, 2016
077f39c
添加贡献者信息
binarywang Nov 22, 2016
33ef6eb
修复#82引入代码导致的单元测试失败的问题
binarywang Nov 22, 2016
a26715c
增加对微信硬件平台事件消息的支持
Nov 24, 2016
1bc2a5c
部分实现微信支付查询退款的接口 for #59
binarywang Nov 24, 2016
fd4505d
Merge pull request #83 from johnnytung/develop
binarywang Nov 25, 2016
95821da
实现获取自定义菜单配置的接口 for #70
binarywang Nov 25, 2016
33de0d8
添加贡献者信息
binarywang Nov 25, 2016
160f608
test enhancement for template message
binarywang Nov 28, 2016
5bb6a24
reformat code
binarywang Nov 28, 2016
9d06a69
增加查询红包记录的接口 for #73
binarywang Nov 28, 2016
baf92b6
完善注释
binarywang Nov 29, 2016
eb9c55d
修正部分接口的注释中文档链接地址为新的文档地址
binarywang Nov 29, 2016
ef15580
一些小的代码调整
binarywang Nov 29, 2016
23f344b
修正WxMpXmlMessage中,设备id的XStreamAlias为DeviceID
Nov 30, 2016
19dc664
Merge pull request #85 from johnnytung/develop
binarywang Nov 30, 2016
6ca78bb
升级版本为2.4.0
binarywang Nov 30, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
修复 #80 menuCreate()方法代码的问题,and reformat code
  • Loading branch information
binarywang committed Nov 21, 2016
commit 72d6aadd9703c33f0d8ae6591c82fb9799024ad3
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpHost;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
Expand Down Expand Up @@ -69,7 +68,7 @@ public class WxCpServiceImpl implements WxCpService {
public boolean checkSignature(String msgSignature, String timestamp, String nonce, String data) {
try {
return SHA1.gen(this.configStorage.getToken(), timestamp, nonce, data)
.equals(msgSignature);
.equals(msgSignature);
} catch (Exception e) {
return false;
}
Expand All @@ -95,18 +94,18 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
synchronized (this.globalAccessTokenRefreshLock) {
if (this.configStorage.isAccessTokenExpired()) {
String url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?"
+ "&corpid=" + this.configStorage.getCorpId()
+ "&corpsecret=" + this.configStorage.getCorpSecret();
+ "&corpid=" + this.configStorage.getCorpId()
+ "&corpsecret=" + this.configStorage.getCorpSecret();
try {
HttpGet httpGet = new HttpGet(url);
if (this.httpProxy != null) {
RequestConfig config = RequestConfig.custom()
.setProxy(this.httpProxy).build();
.setProxy(this.httpProxy).build();
httpGet.setConfig(config);
}
String resultContent = null;
try (CloseableHttpClient httpclient = getHttpclient();
CloseableHttpResponse response = httpclient.execute(httpGet)) {
CloseableHttpResponse response = httpclient.execute(httpGet)) {
resultContent = new BasicResponseHandler().handleResponse(response);
} finally {
httpGet.releaseConnection();
Expand All @@ -117,9 +116,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
}
WxAccessToken accessToken = WxAccessToken.fromJson(resultContent);
this.configStorage.updateAccessToken(
accessToken.getAccessToken(), accessToken.getExpiresIn());
} catch (ClientProtocolException e) {
throw new RuntimeException(e);
accessToken.getAccessToken(), accessToken.getExpiresIn());
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -149,7 +146,7 @@ public String getJsapiTicket(boolean forceRefresh) throws WxErrorException {
String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
this.configStorage.updateJsapiTicket(jsapiTicket,
expiresInSeconds);
expiresInSeconds);
}
}
}
Expand All @@ -162,10 +159,10 @@ public WxJsapiSignature createJsapiSignature(String url) throws WxErrorException
String noncestr = RandomUtils.getRandomStr();
String jsapiTicket = getJsapiTicket(false);
String signature = SHA1.genWithAmple(
"jsapi_ticket=" + jsapiTicket,
"noncestr=" + noncestr,
"timestamp=" + timestamp,
"url=" + url
"jsapi_ticket=" + jsapiTicket,
"noncestr=" + noncestr,
"timestamp=" + timestamp,
"url=" + url
);
WxJsapiSignature jsapiSignature = new WxJsapiSignature();
jsapiSignature.setTimestamp(timestamp);
Expand Down Expand Up @@ -193,7 +190,7 @@ public void menuCreate(WxMenu menu) throws WxErrorException {
@Override
public void menuCreate(Integer agentId, WxMenu menu) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/menu/create?agentid="
+ this.configStorage.getAgentId();
+ this.configStorage.getAgentId();
post(url, menu.toJson());
}

Expand Down Expand Up @@ -230,7 +227,7 @@ public WxMenu menuGet(Integer agentId) throws WxErrorException {

@Override
public WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream inputStream)
throws WxErrorException, IOException {
throws WxErrorException, IOException {
return mediaUpload(mediaType, FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), fileType));
}

Expand All @@ -244,19 +241,19 @@ public WxMediaUploadResult mediaUpload(String mediaType, File file) throws WxErr
public File mediaDownload(String media_id) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/media/get";
return execute(
new MediaDownloadRequestExecutor(
this.configStorage.getTmpDirFile()),
url, "media_id=" + media_id);
new MediaDownloadRequestExecutor(
this.configStorage.getTmpDirFile()),
url, "media_id=" + media_id);
}


@Override
public Integer departCreate(WxCpDepart depart) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/department/create";
String responseContent = execute(
new SimplePostRequestExecutor(),
url,
depart.toJson());
new SimplePostRequestExecutor(),
url,
depart.toJson());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return GsonHelper.getAsInteger(tmpJsonElement.getAsJsonObject().get("id"));
}
Expand All @@ -283,11 +280,11 @@ public List<WxCpDepart> departGet() throws WxErrorException {
*/
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxCpGsonBuilder.INSTANCE.create()
.fromJson(
tmpJsonElement.getAsJsonObject().get("department"),
new TypeToken<List<WxCpDepart>>() {
}.getType()
);
.fromJson(
tmpJsonElement.getAsJsonObject().get("department"),
new TypeToken<List<WxCpDepart>>() {
}.getType()
);
}

@Override
Expand All @@ -313,8 +310,8 @@ public void userDelete(String[] userids) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/batchdelete";
JsonObject jsonObject = new JsonObject();
JsonArray jsonArray = new JsonArray();
for (int i = 0; i < userids.length; i++) {
jsonArray.add(new JsonPrimitive(userids[i]));
for (String userid : userids) {
jsonArray.add(new JsonPrimitive(userid));
}
jsonObject.add("useridlist", jsonArray);
post(url, jsonObject.toString());
Expand Down Expand Up @@ -343,11 +340,11 @@ public List<WxCpUser> userList(Integer departId, Boolean fetchChild, Integer sta
String responseContent = get(url, params);
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxCpGsonBuilder.INSTANCE.create()
.fromJson(
tmpJsonElement.getAsJsonObject().get("userlist"),
new TypeToken<List<WxCpUser>>() {
}.getType()
);
.fromJson(
tmpJsonElement.getAsJsonObject().get("userlist"),
new TypeToken<List<WxCpUser>>() {
}.getType()
);
}

@Override
Expand All @@ -366,11 +363,11 @@ public List<WxCpUser> departGetUsers(Integer departId, Boolean fetchChild, Integ
String responseContent = get(url, params);
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxCpGsonBuilder.INSTANCE.create()
.fromJson(
tmpJsonElement.getAsJsonObject().get("userlist"),
new TypeToken<List<WxCpUser>>() {
}.getType()
);
.fromJson(
tmpJsonElement.getAsJsonObject().get("userlist"),
new TypeToken<List<WxCpUser>>() {
}.getType()
);
}

@Override
Expand Down Expand Up @@ -404,11 +401,11 @@ public List<WxCpTag> tagGet() throws WxErrorException {
String responseContent = get(url, null);
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxCpGsonBuilder.INSTANCE.create()
.fromJson(
tmpJsonElement.getAsJsonObject().get("taglist"),
new TypeToken<List<WxCpTag>>() {
}.getType()
);
.fromJson(
tmpJsonElement.getAsJsonObject().get("taglist"),
new TypeToken<List<WxCpTag>>() {
}.getType()
);
}

@Override
Expand All @@ -417,11 +414,11 @@ public List<WxCpUser> tagGetUsers(String tagId) throws WxErrorException {
String responseContent = get(url, null);
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxCpGsonBuilder.INSTANCE.create()
.fromJson(
tmpJsonElement.getAsJsonObject().get("userlist"),
new TypeToken<List<WxCpUser>>() {
}.getType()
);
.fromJson(
tmpJsonElement.getAsJsonObject().get("userlist"),
new TypeToken<List<WxCpUser>>() {
}.getType()
);
}

@Override
Expand Down Expand Up @@ -460,14 +457,14 @@ public void tagRemoveUsers(String tagId, List<String> userIds) throws WxErrorExc
}

@Override
public String oauth2buildAuthorizationUrl(String state) {
return this.oauth2buildAuthorizationUrl(
this.configStorage.getOauth2redirectUri(),
state
);
}
public String oauth2buildAuthorizationUrl(String state) {
return this.oauth2buildAuthorizationUrl(
this.configStorage.getOauth2redirectUri(),
state
);
}

@Override
@Override
public String oauth2buildAuthorizationUrl(String redirectUri, String state) {
String url = "https://open.weixin.qq.com/connect/oauth2/authorize?";
url += "appid=" + this.configStorage.getCorpId();
Expand All @@ -489,8 +486,8 @@ public String[] oauth2getUserInfo(String code) throws WxErrorException {
@Override
public String[] oauth2getUserInfo(Integer agentId, String code) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?"
+ "code=" + code
+ "&agentid=" + agentId;
+ "code=" + code
+ "&agentid=" + agentId;
String responseText = get(url, null);
JsonElement je = new JsonParser().parse(responseText);
JsonObject jo = je.getAsJsonObject();
Expand Down Expand Up @@ -544,14 +541,14 @@ public <T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) thro
return executeInternal(executor, uri, data);
} catch (WxErrorException e) {
WxError error = e.getError();
/**
/*
* -1 系统繁忙, 1000ms后重试
*/
if (error.getErrorCode() == -1) {
int sleepMillis = this.retrySleepMillis * (1 << retryTimes);
try {
this.log.debug("微信系统繁忙,{}ms 后重试(第{}次)", sleepMillis,
retryTimes + 1);
retryTimes + 1);
Thread.sleep(sleepMillis);
} catch (InterruptedException e1) {
throw new RuntimeException(e1);
Expand All @@ -566,7 +563,7 @@ public <T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) thro
}

protected synchronized <T, E> T executeInternal(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException {
if (uri.indexOf("access_token=") != -1) {
if (uri.contains("access_token=")) {
throw new IllegalArgumentException("uri参数中不允许有access_token: " + uri);
}
String accessToken = getAccessToken(false);
Expand All @@ -576,7 +573,7 @@ protected synchronized <T, E> T executeInternal(RequestExecutor<T, E> executor,

try {
return executor.execute(getHttpclient(), this.httpProxy,
uriWithAccessToken, data);
uriWithAccessToken, data);
} catch (WxErrorException e) {
WxError error = e.getError();
/*
Expand All @@ -593,8 +590,6 @@ protected synchronized <T, E> T executeInternal(RequestExecutor<T, E> executor,
throw new WxErrorException(error);
}
return null;
} catch (ClientProtocolException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -608,15 +603,15 @@ protected CloseableHttpClient getHttpclient() {
public void setWxCpConfigStorage(WxCpConfigStorage wxConfigProvider) {
this.configStorage = wxConfigProvider;
ApacheHttpClientBuilder apacheHttpClientBuilder = this.configStorage
.getApacheHttpClientBuilder();
.getApacheHttpClientBuilder();
if (null == apacheHttpClientBuilder) {
apacheHttpClientBuilder = DefaultApacheHttpClientBuilder.get();
}

apacheHttpClientBuilder.httpProxyHost(this.configStorage.getHttpProxyHost())
.httpProxyPort(this.configStorage.getHttpProxyPort())
.httpProxyUsername(this.configStorage.getHttpProxyUsername())
.httpProxyPassword(this.configStorage.getHttpProxyPassword());
.httpProxyPort(this.configStorage.getHttpProxyPort())
.httpProxyUsername(this.configStorage.getHttpProxyUsername())
.httpProxyPassword(this.configStorage.getHttpProxyPassword());

if (this.configStorage.getHttpProxyHost() != null && this.configStorage.getHttpProxyPort() > 0) {
this.httpProxy = new HttpHost(this.configStorage.getHttpProxyHost(), this.configStorage.getHttpProxyPort());
Expand Down