Skip to content

Commit dc91381

Browse files
committed
Merge branch 'develop-chan' into develop
2 parents 39c2f09 + f45562d commit dc91381

File tree

20 files changed

+1384
-85
lines changed

20 files changed

+1384
-85
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<httpclient.version>4.5</httpclient.version>
4545
<slf4j.version>1.7.10</slf4j.version>
4646
<logback.version>1.1.2</logback.version>
47+
<jodd-http.version>3.6.7</jodd-http.version>
4748
</properties>
4849

4950
<dependencies>
@@ -68,6 +69,11 @@
6869
<artifactId>httpmime</artifactId>
6970
<version>${httpclient.version}</version>
7071
</dependency>
72+
<dependency>
73+
<groupId>org.jodd</groupId>
74+
<artifactId>jodd-http</artifactId>
75+
<version>${jodd-http.version}</version>
76+
</dependency>
7177
<dependency>
7278
<groupId>com.google.code.gson</groupId>
7379
<artifactId>gson</artifactId>

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class WxConsts {
4747
///////////////////////
4848
public static final String MASS_ST_SUCCESS = "send success";
4949
public static final String MASS_ST_FAIL = "send fail";
50-
public static final String MASS_ST_涉嫌广告 = "err(10001)";
50+
public static final String MASS_ST_涉嫌广告 = "err(10001)";
5151
public static final String MASS_ST_涉嫌政治 = "err(20001)";
5252
public static final String MASS_ST_涉嫌社会 = "err(20004)";
5353
public static final String MASS_ST_涉嫌色情 = "err(20002)";
@@ -93,6 +93,15 @@ public class WxConsts {
9393
public static final String EVT_LOCATION_SELECT = "location_select";
9494
public static final String EVT_TEMPLATESENDJOBFINISH = "TEMPLATESENDJOBFINISH";
9595
public static final String EVT_ENTER_AGENT = "enter_agent";
96+
public static final String EVT_CARD_PASS_CHECK = "card_pass_check";
97+
public static final String EVT_CARD_NOT_PASS_CHECK = "card_not_pass_check";
98+
public static final String EVT_USER_GET_CARD = "user_get_card";
99+
public static final String EVT_USER_DEL_CARD = "user_del_card";
100+
public static final String EVT_USER_CONSUME_CARD = "user_consume_card";
101+
public static final String EVT_USER_PAY_FROM_PAY_CELL = "user_pay_from_pay_cell";
102+
public static final String EVT_USER_VIEW_CARD = "user_view_card";
103+
public static final String EVT_USER_ENTER_SESSION_FROM_CARD = "user_enter_session_from_card";
104+
public static final String EVT_CARD_SKU_REMIND = "card_sku_remind"; // 库存报警
96105

97106
///////////////////////
98107
// 上传多媒体文件的类型
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package me.chanjar.weixin.common.bean;
2+
3+
import java.io.Serializable;
4+
5+
/**
6+
* 卡券Api签名
7+
*
8+
* @author YuJian
9+
* @version 15/11/8
10+
*/
11+
public class WxCardApiSignature implements Serializable {
12+
13+
private String appId;
14+
15+
private String cardId;
16+
17+
private String cardType;
18+
19+
private String locationId;
20+
21+
private String code;
22+
23+
private String openId;
24+
25+
private Long timestamp;
26+
27+
private String nonceStr;
28+
29+
private String signature;
30+
31+
public String getAppId() {
32+
return appId;
33+
}
34+
35+
public void setAppId(String appId) {
36+
this.appId = appId;
37+
}
38+
39+
public String getCardId() {
40+
return cardId;
41+
}
42+
43+
public void setCardId(String cardId) {
44+
this.cardId = cardId;
45+
}
46+
47+
public String getCardType() {
48+
return cardType;
49+
}
50+
51+
public void setCardType(String cardType) {
52+
this.cardType = cardType;
53+
}
54+
55+
public String getLocationId() {
56+
return locationId;
57+
}
58+
59+
public void setLocationId(String locationId) {
60+
this.locationId = locationId;
61+
}
62+
63+
public String getCode() {
64+
return code;
65+
}
66+
67+
public void setCode(String code) {
68+
this.code = code;
69+
}
70+
71+
public String getOpenId() {
72+
return openId;
73+
}
74+
75+
public void setOpenId(String openId) {
76+
this.openId = openId;
77+
}
78+
79+
public Long getTimestamp() {
80+
return timestamp;
81+
}
82+
83+
public void setTimestamp(Long timestamp) {
84+
this.timestamp = timestamp;
85+
}
86+
87+
public String getNonceStr() {
88+
return nonceStr;
89+
}
90+
91+
public void setNonceStr(String nonceStr) {
92+
this.nonceStr = nonceStr;
93+
}
94+
95+
public String getSignature() {
96+
return signature;
97+
}
98+
99+
public void setSignature(String signature) {
100+
this.signature = signature;
101+
}
102+
}

weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxMenu.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package me.chanjar.weixin.common.bean;
22

3+
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
4+
import org.apache.commons.codec.Charsets;
5+
36
import java.io.InputStream;
47
import java.io.InputStreamReader;
58
import java.io.Serializable;
69
import java.util.ArrayList;
710
import java.util.List;
811

9-
import org.apache.commons.codec.Charsets;
10-
11-
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
12-
1312
/**
1413
* 企业号菜单
1514
* @author Daniel Qian
@@ -136,6 +135,7 @@ public static class WxMenuRule {
136135
private String province;
137136
private String city;
138137
private String clientPlatformType;
138+
private String language;
139139

140140
public String getGroupId() {
141141
return groupId;
@@ -184,8 +184,16 @@ public String getClientPlatformType() {
184184
public void setClientPlatformType(String clientPlatformType) {
185185
this.clientPlatformType = clientPlatformType;
186186
}
187-
188-
@Override
187+
188+
public String getLanguage() {
189+
return language;
190+
}
191+
192+
public void setLanguage(String language) {
193+
this.language = language;
194+
}
195+
196+
@Override
189197
public String toString() {
190198
return "matchrule:{" +
191199
"group_id='" + groupId + '\'' +
@@ -194,6 +202,7 @@ public String toString() {
194202
", province" + province + '\'' +
195203
", city" + city + '\'' +
196204
", client_platform_type" + clientPlatformType + '\'' +
205+
", language" + language + '\'' +
197206
"}";
198207
}
199208
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package me.chanjar.weixin.common.util.http;
2+
3+
import jodd.http.HttpRequest;
4+
import jodd.http.HttpResponse;
5+
import jodd.http.ProxyInfo;
6+
import jodd.http.net.SocketHttpConnectionProvider;
7+
import me.chanjar.weixin.common.bean.result.WxError;
8+
import me.chanjar.weixin.common.exception.WxErrorException;
9+
import org.apache.http.HttpHost;
10+
import org.apache.http.impl.client.CloseableHttpClient;
11+
12+
import java.io.IOException;
13+
14+
/**
15+
* 简单的GET请求执行器,请求的参数是String, 返回的结果也是String
16+
*
17+
* @author Daniel Qian
18+
*/
19+
public class JoddGetRequestExecutor implements RequestExecutor<String, String> {
20+
21+
@Override
22+
public String execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri,
23+
String queryParam) throws WxErrorException, IOException {
24+
if (queryParam != null) {
25+
if (uri.indexOf('?') == -1) {
26+
uri += '?';
27+
}
28+
uri += uri.endsWith("?") ? queryParam : '&' + queryParam;
29+
}
30+
31+
SocketHttpConnectionProvider provider = new SocketHttpConnectionProvider();
32+
33+
if (httpProxy != null) {
34+
ProxyInfo proxyInfoObj = new ProxyInfo(
35+
ProxyInfo.ProxyType.HTTP,
36+
httpProxy.getAddress().getHostAddress(),
37+
httpProxy.getPort(), "", "");
38+
provider.useProxy(proxyInfoObj);
39+
}
40+
41+
HttpRequest request = HttpRequest.get(uri);
42+
request.method("GET");
43+
request.charset("UTF-8");
44+
45+
HttpResponse response = request.open(provider).send();
46+
response.charset("UTF-8");
47+
String result = response.bodyText();
48+
49+
WxError error = WxError.fromJson(result);
50+
if (error.getErrorCode() != 0) {
51+
throw new WxErrorException(error);
52+
}
53+
return result;
54+
}
55+
56+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package me.chanjar.weixin.common.util.http;
2+
3+
import jodd.http.HttpRequest;
4+
import jodd.http.HttpResponse;
5+
import jodd.http.ProxyInfo;
6+
import jodd.http.net.SocketHttpConnectionProvider;
7+
import me.chanjar.weixin.common.bean.result.WxError;
8+
import me.chanjar.weixin.common.exception.WxErrorException;
9+
import org.apache.http.HttpHost;
10+
import org.apache.http.impl.client.CloseableHttpClient;
11+
12+
import java.io.IOException;
13+
14+
/**
15+
* 简单的POST请求执行器,请求的参数是String, 返回的结果也是String
16+
*
17+
* @author Edison Guo
18+
*/
19+
public class JoddPostRequestExecutor implements RequestExecutor<String, String> {
20+
21+
@Override
22+
public String execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri,
23+
String postEntity) throws WxErrorException, IOException {
24+
SocketHttpConnectionProvider provider = new SocketHttpConnectionProvider();
25+
26+
if (httpProxy != null) {
27+
ProxyInfo proxyInfoObj = new ProxyInfo(
28+
ProxyInfo.ProxyType.HTTP,
29+
httpProxy.getAddress().getHostAddress(),
30+
httpProxy.getPort(), "", "");
31+
provider.useProxy(proxyInfoObj);
32+
}
33+
34+
HttpRequest request = HttpRequest.get(uri);
35+
request.method("POST");
36+
request.charset("UTF-8");
37+
request.bodyText(postEntity);
38+
39+
HttpResponse response = request.open(provider).send();
40+
response.charset("UTF-8");
41+
String result = response.bodyText();
42+
43+
WxError error = WxError.fromJson(result);
44+
if (error.getErrorCode() != 0) {
45+
throw new WxErrorException(error);
46+
}
47+
return result;
48+
}
49+
50+
}

weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
*/
99
package me.chanjar.weixin.common.util.json;
1010

11-
import java.lang.reflect.Type;
12-
13-
import com.google.gson.Gson;
1411
import com.google.gson.JsonArray;
1512
import com.google.gson.JsonDeserializationContext;
1613
import com.google.gson.JsonDeserializer;
@@ -19,9 +16,10 @@
1916
import com.google.gson.JsonParseException;
2017
import com.google.gson.JsonSerializationContext;
2118
import com.google.gson.JsonSerializer;
22-
2319
import me.chanjar.weixin.common.bean.WxMenu;
2420

21+
import java.lang.reflect.Type;
22+
2523
/**
2624
*
2725
* @author Daniel Qian
@@ -40,8 +38,7 @@ public JsonElement serialize(WxMenu menu, Type typeOfSrc, JsonSerializationConte
4038
json.add("button", buttonArray);
4139

4240
if (menu.getMatchRule() != null) {
43-
Gson gson = new Gson();
44-
json.add("matchrule", gson.toJsonTree(menu.getMatchRule()));
41+
json.add("matchrule", convertToJson(menu.getMatchRule()));
4542
}
4643

4744
return json;
@@ -63,6 +60,18 @@ protected JsonObject convertToJson(WxMenu.WxMenuButton button) {
6360
return buttonJson;
6461
}
6562

63+
protected JsonObject convertToJson(WxMenu.WxMenuRule menuRule){
64+
JsonObject matchRule = new JsonObject();
65+
matchRule.addProperty("group_id",menuRule.getGroupId());
66+
matchRule.addProperty("sex",menuRule.getSex());
67+
matchRule.addProperty("country",menuRule.getCountry());
68+
matchRule.addProperty("province",menuRule.getProvince());
69+
matchRule.addProperty("city",menuRule.getCity());
70+
matchRule.addProperty("client_platform_type",menuRule.getClientPlatformType());
71+
matchRule.addProperty("language",menuRule.getLanguage());
72+
return matchRule;
73+
}
74+
6675
public WxMenu deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
6776
/*
6877
* 操蛋的微信

0 commit comments

Comments
 (0)