Skip to content

Commit 4f1c66e

Browse files
committed
优化统一下单时参数校验逻辑
1 parent 24e80a9 commit 4f1c66e

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
<dependency>
153153
<groupId>org.apache.commons</groupId>
154154
<artifactId>commons-lang3</artifactId>
155-
<version>3.6</version>
155+
<version>3.5</version>
156156
</dependency>
157157
<dependency>
158158
<groupId>org.slf4j</groupId>

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayUnifiedOrderRequest.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,12 +333,18 @@ public void setTradeType(String tradeType) {
333333

334334
@Override
335335
protected void checkConstraints() throws WxPayException {
336-
if (TradeType.JSAPI.equals(this.getTradeType()) && this.getOpenid() == null && this.getSubOpenid() == null) {
337-
throw new WxPayException("当 trade_type是'JSAPI'时未指定openid或sub_openid");
336+
if (TradeType.JSAPI.equals(this.getTradeType())) {
337+
if (StringUtils.isBlank(this.getSubAppId()) && StringUtils.isBlank(this.getOpenid())) {
338+
throw new WxPayException("当trade_type是'JSAPI'时,需指定非空的openid值");
339+
}
340+
341+
if (StringUtils.isNotBlank(this.getSubAppId()) && StringUtils.isBlank(this.getSubOpenid())) {
342+
throw new WxPayException("在服务商模式下,当trade_type是'JSAPI'时,需指定非空的sub_openid值");
343+
}
338344
}
339345

340-
if (TradeType.NATIVE.equals(this.getTradeType()) && this.getProductId() == null) {
341-
throw new WxPayException("当 trade_type是'NATIVE'时未指定product_id");
346+
if (TradeType.NATIVE.equals(this.getTradeType()) && StringUtils.isBlank(this.getProductId())) {
347+
throw new WxPayException("当trade_type是'NATIVE'时,需指定非空的product_id值");
342348
}
343349
}
344350

0 commit comments

Comments
 (0)