@@ -1,6 +1,7 @@ | |||||
package com.github.binarywang.wxpay.bean.request; | package com.github.binarywang.wxpay.bean.request; | ||||
import com.github.binarywang.wxpay.config.WxPayConfig; | import com.github.binarywang.wxpay.config.WxPayConfig; | ||||
import com.github.binarywang.wxpay.constant.WxPayConstants.TradeType; | |||||
import com.github.binarywang.wxpay.exception.WxPayException; | import com.github.binarywang.wxpay.exception.WxPayException; | ||||
import com.thoughtworks.xstream.annotations.XStreamAlias; | import com.thoughtworks.xstream.annotations.XStreamAlias; | ||||
import lombok.*; | import lombok.*; | ||||
@@ -23,8 +24,6 @@ import org.apache.commons.lang3.StringUtils; | |||||
@AllArgsConstructor | @AllArgsConstructor | ||||
@XStreamAlias("xml") | @XStreamAlias("xml") | ||||
public class WxPayUnifiedOrderRequest extends WxPayBaseRequest { | public class WxPayUnifiedOrderRequest extends WxPayBaseRequest { | ||||
private static final String[] TRADE_TYPES = new String[]{"JSAPI", "NATIVE", "APP", "MWEB"}; | |||||
/** | /** | ||||
* <pre> | * <pre> | ||||
* 字段名:设备号 | * 字段名:设备号 | ||||
@@ -334,16 +333,11 @@ public class WxPayUnifiedOrderRequest extends WxPayBaseRequest { | |||||
@Override | @Override | ||||
protected void checkConstraints() throws WxPayException { | protected void checkConstraints() throws WxPayException { | ||||
// if (!ArrayUtils.contains(TRADE_TYPES, this.getTradeType())) { | |||||
// throw new WxPayException(String.format("trade_type目前必须为%s其中之一,实际值:%s", | |||||
// Arrays.toString(TRADE_TYPES), this.getTradeType())); | |||||
// } | |||||
if ("JSAPI".equals(this.getTradeType()) && this.getOpenid() == null && this.getSubOpenid() == null) { | |||||
if (TradeType.JSAPI.equals(this.getTradeType()) && this.getOpenid() == null && this.getSubOpenid() == null) { | |||||
throw new WxPayException("当 trade_type是'JSAPI'时未指定openid或sub_openid"); | throw new WxPayException("当 trade_type是'JSAPI'时未指定openid或sub_openid"); | ||||
} | } | ||||
if ("NATIVE".equals(this.getTradeType()) && this.getProductId() == null) { | |||||
if (TradeType.NATIVE.equals(this.getTradeType()) && this.getProductId() == null) { | |||||
throw new WxPayException("当 trade_type是'NATIVE'时未指定product_id"); | throw new WxPayException("当 trade_type是'NATIVE'时未指定product_id"); | ||||
} | } | ||||
} | } | ||||
@@ -24,7 +24,6 @@ import java.nio.file.Files; | |||||
import java.nio.file.Path; | import java.nio.file.Path; | ||||
import java.util.Calendar; | import java.util.Calendar; | ||||
import java.util.Date; | import java.util.Date; | ||||
import java.util.Map; | |||||
import static org.testng.Assert.*; | import static org.testng.Assert.*; | ||||
@@ -103,26 +102,11 @@ public class WxPayServiceAbstractImplTest { | |||||
.createOrder(WxPayUnifiedOrderRequest.newBuilder() | .createOrder(WxPayUnifiedOrderRequest.newBuilder() | ||||
.body("我去") | .body("我去") | ||||
.totalFee(1) | .totalFee(1) | ||||
.productId("aaa") | |||||
.spbillCreateIp("11.1.11.1") | .spbillCreateIp("11.1.11.1") | ||||
.notifyURL("111111") | .notifyURL("111111") | ||||
.tradeType(TradeType.NATIVE) | .tradeType(TradeType.NATIVE) | ||||
.outTradeNo("1111112") | |||||
.build()); | |||||
this.logger.info(result.toString()); | |||||
this.logger.warn(this.payService.getWxApiData().toString()); | |||||
} | |||||
@Test | |||||
public void testCreateOrder_micropay() throws Exception { | |||||
//TODO 待完善 | |||||
Object result = this.payService | |||||
.createOrder(WxPayUnifiedOrderRequest.newBuilder() | |||||
.body("我去") | |||||
.totalFee(1) | |||||
.spbillCreateIp("11.1.11.1") | |||||
.notifyURL("111111") | |||||
.tradeType(TradeType.MICROPAY) | |||||
.outTradeNo("1111112") | |||||
.outTradeNo("111111290") | |||||
.build()); | .build()); | ||||
this.logger.info(result.toString()); | this.logger.info(result.toString()); | ||||
this.logger.warn(this.payService.getWxApiData().toString()); | this.logger.warn(this.payService.getWxApiData().toString()); | ||||
@@ -130,17 +114,7 @@ public class WxPayServiceAbstractImplTest { | |||||
@Test | @Test | ||||
public void testGetPayInfo() throws Exception { | public void testGetPayInfo() throws Exception { | ||||
Map<String, String> payInfo = this.payService | |||||
.getPayInfo(WxPayUnifiedOrderRequest.newBuilder() | |||||
.body("我去") | |||||
.totalFee(1) | |||||
.spbillCreateIp("1.11.1.11") | |||||
.notifyURL("111111") | |||||
.tradeType(TradeType.JSAPI) | |||||
.outTradeNo("1111113") | |||||
.openid(((XmlWxPayConfig) this.payService.getConfig()).getOpenid()) | |||||
.build()); | |||||
this.logger.info(payInfo.toString()); | |||||
//please use createOrder instead | |||||
} | } | ||||
/** | /** | ||||