Skip to content

Commit 463b2e3

Browse files
author
Keung
authored
Merge pull request binarywang#3 from Wechat-Group/develop
Develop
2 parents 575458d + c0a3259 commit 463b2e3

19 files changed

+995
-417
lines changed
Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
package me.chanjar.weixin.common.util;
22

3+
import java.lang.reflect.Field;
4+
import java.util.ArrayList;
5+
import java.util.Arrays;
6+
import java.util.List;
7+
import java.util.Map;
8+
9+
import org.slf4j.Logger;
10+
import org.slf4j.LoggerFactory;
11+
312
import com.google.common.collect.Lists;
413
import com.google.common.collect.Maps;
514
import com.thoughtworks.xstream.annotations.XStreamAlias;
15+
616
import me.chanjar.weixin.common.annotation.Required;
717
import me.chanjar.weixin.common.bean.result.WxError;
818
import me.chanjar.weixin.common.exception.WxErrorException;
919

10-
import java.lang.reflect.Field;
11-
import java.util.ArrayList;
12-
import java.util.Arrays;
13-
import java.util.List;
14-
import java.util.Map;
15-
1620
/**
1721
* <pre>
1822
* bean操作的一些工具类
@@ -21,6 +25,7 @@
2125
* </pre>
2226
*/
2327
public class BeanUtils {
28+
private static Logger log = LoggerFactory.getLogger(BeanUtils.class);
2429

2530
/**
2631
* 检查bean里标记为@Required的field是否为空,为空则抛异常
@@ -48,41 +53,42 @@ public static void checkRequiredFields(Object bean) throws WxErrorException {
4853
}
4954

5055
if (!nullFields.isEmpty()) {
51-
throw new WxErrorException(WxError.newBuilder().setErrorMsg("必填字段 " + nullFields + " 必须提供值").build());
56+
String msg = "必填字段 " + nullFields + " 必须提供值";
57+
log.debug(msg);
58+
throw new WxErrorException(WxError.newBuilder().setErrorMsg(msg).build());
5259
}
5360
}
5461

55-
/**
56-
* 将bean按照@XStreamAlias标识的字符串内容生成以之为key的map对象
57-
* @param bean 包含@XStreamAlias的xml bean对象
58-
* @return map对象
59-
*/
60-
public static Map<String, String> xmlBean2Map(Object bean) {
61-
Map<String, String> result = Maps.newHashMap();
62-
List<Field> fields = new ArrayList<>( Arrays.asList(bean.getClass().getDeclaredFields()));
63-
fields.addAll(Arrays.asList(bean.getClass().getSuperclass().getDeclaredFields()));
64-
for (Field field : fields) {
65-
try {
66-
boolean isAccessible = field.isAccessible();
67-
field.setAccessible(true);
68-
if (field.get(bean) == null) {
69-
field.setAccessible(isAccessible);
70-
continue;
71-
}
62+
/**
63+
* 将bean按照@XStreamAlias标识的字符串内容生成以之为key的map对象
64+
*
65+
* @param bean 包含@XStreamAlias的xml bean对象
66+
* @return map对象
67+
*/
68+
public static Map<String, String> xmlBean2Map(Object bean) {
69+
Map<String, String> result = Maps.newHashMap();
70+
List<Field> fields = new ArrayList<>(Arrays.asList(bean.getClass().getDeclaredFields()));
71+
fields.addAll(Arrays.asList(bean.getClass().getSuperclass().getDeclaredFields()));
72+
for (Field field : fields) {
73+
try {
74+
boolean isAccessible = field.isAccessible();
75+
field.setAccessible(true);
76+
if (field.get(bean) == null) {
77+
field.setAccessible(isAccessible);
78+
continue;
79+
}
7280

73-
if (field.isAnnotationPresent(XStreamAlias.class)) {
74-
result.put(field.getAnnotation(XStreamAlias.class).value(),
75-
field.get(bean).toString());
76-
}
81+
if (field.isAnnotationPresent(XStreamAlias.class)) {
82+
result.put(field.getAnnotation(XStreamAlias.class).value(), field.get(bean).toString());
83+
}
7784

78-
field.setAccessible(isAccessible);
79-
} catch (SecurityException | IllegalArgumentException
80-
| IllegalAccessException e) {
81-
e.printStackTrace();
82-
}
85+
field.setAccessible(isAccessible);
86+
} catch (SecurityException | IllegalArgumentException | IllegalAccessException e) {
87+
e.printStackTrace();
88+
}
8389

84-
}
90+
}
8591

86-
return result;
87-
}
92+
return result;
93+
}
8894
}

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder;
55

66
import javax.net.ssl.SSLContext;
7+
78
import java.io.File;
89
import java.util.concurrent.locks.Lock;
910

@@ -81,6 +82,23 @@ public interface WxMpConfigStorage {
8182
String getPartnerId();
8283

8384
String getPartnerKey();
85+
86+
/**
87+
* 微信支付异步回掉地址,通知url必须为直接可访问的url,不能携带参数。
88+
* @since 2.5.0
89+
* @return
90+
*/
91+
String getNotifyURL();
92+
93+
/**
94+
* 交易类型
95+
* <pre>
96+
* JSAPI--公众号支付、NATIVE--原生扫码支付、APP--app支付
97+
* </pre>
98+
* @since 2.5.0
99+
* @return
100+
*/
101+
String getTradeType();
84102

85103
String getToken();
86104

@@ -112,4 +130,5 @@ public interface WxMpConfigStorage {
112130
* 是否自动刷新token
113131
*/
114132
boolean autoRefreshToken();
133+
115134
}

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public class WxMpInMemoryConfigStorage implements WxMpConfigStorage {
2020
protected volatile String secret;
2121
protected volatile String partnerId;
2222
protected volatile String partnerKey;
23+
protected volatile String notifyURL;
24+
protected volatile String tradeType;
2325
protected volatile String token;
2426
protected volatile String accessToken;
2527
protected volatile String aesKey;
@@ -267,8 +269,25 @@ public String getPartnerKey() {
267269
public void setPartnerKey(String partnerKey) {
268270
this.partnerKey = partnerKey;
269271
}
272+
273+
274+
public String getNotifyURL() {
275+
return notifyURL;
276+
}
270277

271-
@Override
278+
public void setNotifyURL(String notifyURL) {
279+
this.notifyURL = notifyURL;
280+
}
281+
282+
public String getTradeType() {
283+
return tradeType;
284+
}
285+
286+
public void setTradeType(String tradeType) {
287+
this.tradeType = tradeType;
288+
}
289+
290+
@Override
272291
public File getTmpDirFile() {
273292
return this.tmpDirFile;
274293
}

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java

Lines changed: 86 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package me.chanjar.weixin.mp.api;
22

33
import me.chanjar.weixin.common.exception.WxErrorException;
4-
import me.chanjar.weixin.mp.bean.pay.WxPayJsSDKCallback;
54
import me.chanjar.weixin.mp.bean.pay.request.WxEntPayRequest;
65
import me.chanjar.weixin.mp.bean.pay.request.WxPayRefundRequest;
76
import me.chanjar.weixin.mp.bean.pay.request.WxPaySendRedpackRequest;
@@ -31,9 +30,8 @@ public interface WxMpPayService {
3130
* 接口地址:https://api.mch.weixin.qq.com/pay/orderquery
3231
* </pre>
3332
*
34-
* @param transactionId 微信支付分配的商户号
33+
* @param transactionId 微信订单号
3534
* @param outTradeNo 商户系统内部的订单号,当没提供transaction_id时需要传这个。
36-
* @throws WxErrorException
3735
*/
3836
WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) throws WxErrorException;
3937

@@ -50,7 +48,6 @@ public interface WxMpPayService {
5048
* </pre>
5149
*
5250
* @param outTradeNo 商户系统内部的订单号,当没提供transaction_id时需要传这个。
53-
* @throws WxErrorException
5451
*/
5552
WxPayOrderCloseResult closeOrder(String outTradeNo) throws WxErrorException;
5653

@@ -60,7 +57,6 @@ public interface WxMpPayService {
6057
* 接口地址:https://api.mch.weixin.qq.com/pay/unifiedorder
6158
*
6259
* @param request 请求对象,注意一些参数如appid、mchid等不用设置,方法内会自动从配置对象中获取到(前提是对应配置中已经设置)
63-
* @throws WxErrorException
6460
*/
6561
WxPayUnifiedOrderResult unifiedOrder(WxPayUnifiedOrderRequest request) throws WxErrorException;
6662

@@ -69,7 +65,6 @@ public interface WxMpPayService {
6965
* 详见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN
7066
*
7167
* @param request 请求对象,注意一些参数如appid、mchid等不用设置,方法内会自动从配置对象中获取到(前提是对应配置中已经设置)
72-
* @throws WxErrorException
7368
*/
7469
Map<String, String> getPayInfo(WxPayUnifiedOrderRequest request) throws WxErrorException;
7570

@@ -81,7 +76,7 @@ public interface WxMpPayService {
8176
* </pre>
8277
*
8378
* @param request 请求对象
84-
* @param keyFile 证书文件对象
79+
* @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3)
8580
* @return 退款操作结果
8681
*/
8782
WxPayRefundResult refund(WxPayRefundRequest request, File keyFile) throws WxErrorException;
@@ -94,7 +89,8 @@ public interface WxMpPayService {
9489
* 详见 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_5
9590
* 接口链接:https://api.mch.weixin.qq.com/pay/refundquery
9691
* </pre>
97-
* 以下四个参数四选一
92+
* 以下四个参数四选一
93+
*
9894
* @param transactionId 微信订单号
9995
* @param outTradeNo 商户订单号
10096
* @param outRefundNo 商户退款单号
@@ -107,15 +103,86 @@ public interface WxMpPayService {
107103
* 读取支付结果通知
108104
* 详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7
109105
*/
110-
WxPayJsSDKCallback getJSSDKCallbackData(String xmlData) throws WxErrorException;
106+
WxPayOrderNotifyResult getOrderNotifyResult(String xmlData) throws WxErrorException;
111107

112108
/**
113-
* <pre>
114-
* 计算Map键值对是否和签名相符,
115-
* 按照字段名的 ASCII 码从小到大排序(字典序)后,使用 URL 键值对的 格式(即 key1=value1&key2=value2...)拼接成字符串
116-
* </pre>
109+
* 微信公众号支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3)
110+
*
111+
* @param xmlbean Bean需要标记有XML注解,默认使用配置中的PartnerKey进行签名
112+
* @return 签名字符串
113+
* @see #createSign(Map, String)
114+
* @since 2.5.0
117115
*/
118-
boolean checkJSSDKCallbackDataSignature(Map<String, String> kvm, String signature);
116+
String createSign(Object xmlbean);
117+
118+
/**
119+
* 微信公众号支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3)
120+
*
121+
* @param xmlbean Bean需要标记有XML注解
122+
* @param signKey 签名Key
123+
* @return 签名字符串
124+
* @see #createSign(Map, String)
125+
*/
126+
String createSign(Object xmlbean, String signKey);
127+
128+
/**
129+
* 微信公众号支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3)
130+
*
131+
* @param prams 参数信息,默认使用配置中的PartnerKey进行签名
132+
* @return 签名字符串
133+
* @see #createSign(Map, String)
134+
*/
135+
String createSign(Map<String, String> prams);
136+
137+
138+
/**
139+
* 微信公众号支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3)
140+
*
141+
* @param prams 参数信息
142+
* @param signKey 签名Key
143+
* @return 签名字符串
144+
*/
145+
String createSign(Map<String, String> prams, String signKey);
146+
147+
148+
/**
149+
* 校验签名是否正确,默认使用配置中的PartnerKey进行签名
150+
*
151+
* @param xmlbean Bean需要标记有XML注解
152+
* @return true - 签名校验成功,false - 签名校验失败
153+
* @see #checkSign(Map, String)
154+
*/
155+
boolean checkSign(Object xmlbean);
156+
157+
/**
158+
* 校验签名是否正确
159+
*
160+
* @param xmlbean Bean需要标记有XML注解
161+
* @param signKey 校验的签名Key
162+
* @return true - 签名校验成功,false - 签名校验失败
163+
* @see #checkSign(Map, String)
164+
*/
165+
boolean checkSign(Object xmlbean, String signKey);
166+
167+
/**
168+
* 校验签名是否正确,默认使用配置中的PartnerKey进行签名
169+
*
170+
* @param prams 需要校验的参数Map
171+
* @return true - 签名校验成功,false - 签名校验失败
172+
* @see #checkSign(Map, String)
173+
*/
174+
boolean checkSign(Map<String, String> prams);
175+
176+
/**
177+
* 校验签名是否正确
178+
*
179+
* @param params 需要校验的参数Map
180+
* @param signKey 校验的签名Key
181+
* @return true - 签名校验成功,false - 签名校验失败
182+
* @see #checkSign(Map, String)
183+
*/
184+
boolean checkSign(Map<String, String> params, String signKey);
185+
119186

120187
/**
121188
* 发送微信红包给个人用户
@@ -128,7 +195,7 @@ public interface WxMpPayService {
128195
* </pre>
129196
*
130197
* @param request 请求对象
131-
* @param keyFile 证书文件对象
198+
* @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3)
132199
*/
133200
WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request, File keyFile) throws WxErrorException;
134201

@@ -140,8 +207,9 @@ public interface WxMpPayService {
140207
* 是否需要证书 是(证书及使用说明详见商户证书)
141208
* 请求方式 POST
142209
* </pre>
210+
*
143211
* @param mchBillNo 商户发放红包的商户订单号,比如10000098201411111234567890
144-
* @param keyFile 证书文件对象
212+
* @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3)
145213
*/
146214
WxPayRedpackQueryResult queryRedpack(String mchBillNo, File keyFile) throws WxErrorException;
147215

@@ -156,7 +224,7 @@ public interface WxMpPayService {
156224
* </pre>
157225
*
158226
* @param request 请求对象
159-
* @param keyFile 证书文件对象
227+
* @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3)
160228
*/
161229
WxEntPayResult entPay(WxEntPayRequest request, File keyFile) throws WxErrorException;
162230

@@ -169,7 +237,7 @@ public interface WxMpPayService {
169237
* </pre>
170238
*
171239
* @param partnerTradeNo 商户订单号
172-
* @param keyFile 证书文件对象
240+
* @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3)
173241
*/
174242
WxEntPayQueryResult queryEntPay(String partnerTradeNo, File keyFile) throws WxErrorException;
175243

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import me.chanjar.weixin.mp.api.WxMpMenuService;
66
import me.chanjar.weixin.mp.api.WxMpService;
77
import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult;
8-
import me.chanjar.weixin.mp.bean.menu.WxMpSelfMenuInfo;
98
import org.slf4j.Logger;
109
import org.slf4j.LoggerFactory;
1110

0 commit comments

Comments
 (0)