Skip to content

Commit 70f7bd7

Browse files
committed
优化代码,尽量使用已定义的常量
1 parent b7443f4 commit 70f7bd7

2 files changed

Lines changed: 6 additions & 38 deletions

File tree

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.github.binarywang.wxpay.bean.request;
22

33
import com.github.binarywang.wxpay.config.WxPayConfig;
4+
import com.github.binarywang.wxpay.constant.WxPayConstants.TradeType;
45
import com.github.binarywang.wxpay.exception.WxPayException;
56
import com.thoughtworks.xstream.annotations.XStreamAlias;
67
import lombok.*;
@@ -23,8 +24,6 @@
2324
@AllArgsConstructor
2425
@XStreamAlias("xml")
2526
public class WxPayUnifiedOrderRequest extends WxPayBaseRequest {
26-
private static final String[] TRADE_TYPES = new String[]{"JSAPI", "NATIVE", "APP", "MWEB"};
27-
2827
/**
2928
* <pre>
3029
* 字段名:设备号
@@ -334,16 +333,11 @@ public void setTradeType(String tradeType) {
334333

335334
@Override
336335
protected void checkConstraints() throws WxPayException {
337-
// if (!ArrayUtils.contains(TRADE_TYPES, this.getTradeType())) {
338-
// throw new WxPayException(String.format("trade_type目前必须为%s其中之一,实际值:%s",
339-
// Arrays.toString(TRADE_TYPES), this.getTradeType()));
340-
// }
341-
342-
if ("JSAPI".equals(this.getTradeType()) && this.getOpenid() == null && this.getSubOpenid() == null) {
336+
if (TradeType.JSAPI.equals(this.getTradeType()) && this.getOpenid() == null && this.getSubOpenid() == null) {
343337
throw new WxPayException("当 trade_type是'JSAPI'时未指定openid或sub_openid");
344338
}
345339

346-
if ("NATIVE".equals(this.getTradeType()) && this.getProductId() == null) {
340+
if (TradeType.NATIVE.equals(this.getTradeType()) && this.getProductId() == null) {
347341
throw new WxPayException("当 trade_type是'NATIVE'时未指定product_id");
348342
}
349343
}

‎weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/WxPayServiceAbstractImplTest.java‎

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.nio.file.Path;
2525
import java.util.Calendar;
2626
import java.util.Date;
27-
import java.util.Map;
2827

2928
import static org.testng.Assert.*;
3029

@@ -103,44 +102,19 @@ public void testCreateOrder_native() throws Exception {
103102
.createOrder(WxPayUnifiedOrderRequest.newBuilder()
104103
.body("我去")
105104
.totalFee(1)
105+
.productId("aaa")
106106
.spbillCreateIp("11.1.11.1")
107107
.notifyURL("111111")
108108
.tradeType(TradeType.NATIVE)
109-
.outTradeNo("1111112")
110-
.build());
111-
this.logger.info(result.toString());
112-
this.logger.warn(this.payService.getWxApiData().toString());
113-
}
114-
115-
@Test
116-
public void testCreateOrder_micropay() throws Exception {
117-
//TODO 待完善
118-
Object result = this.payService
119-
.createOrder(WxPayUnifiedOrderRequest.newBuilder()
120-
.body("我去")
121-
.totalFee(1)
122-
.spbillCreateIp("11.1.11.1")
123-
.notifyURL("111111")
124-
.tradeType(TradeType.MICROPAY)
125-
.outTradeNo("1111112")
109+
.outTradeNo("111111290")
126110
.build());
127111
this.logger.info(result.toString());
128112
this.logger.warn(this.payService.getWxApiData().toString());
129113
}
130114

131115
@Test
132116
public void testGetPayInfo() throws Exception {
133-
Map<String, String> payInfo = this.payService
134-
.getPayInfo(WxPayUnifiedOrderRequest.newBuilder()
135-
.body("我去")
136-
.totalFee(1)
137-
.spbillCreateIp("1.11.1.11")
138-
.notifyURL("111111")
139-
.tradeType(TradeType.JSAPI)
140-
.outTradeNo("1111113")
141-
.openid(((XmlWxPayConfig) this.payService.getConfig()).getOpenid())
142-
.build());
143-
this.logger.info(payInfo.toString());
117+
//please use createOrder instead
144118
}
145119

146120
/**

0 commit comments

Comments
 (0)