Procházet zdrojové kódy

优化代码,尽量使用已定义的常量

master
Binary Wang před 7 roky
rodič
revize
70f7bd7e7a
2 změnil soubory, kde provedl 6 přidání a 38 odebrání
  1. +3
    -9
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayUnifiedOrderRequest.java
  2. +3
    -29
      weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/WxPayServiceAbstractImplTest.java

+ 3
- 9
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayUnifiedOrderRequest.java Zobrazit soubor

@@ -1,6 +1,7 @@
package com.github.binarywang.wxpay.bean.request;

import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.constant.WxPayConstants.TradeType;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.*;
@@ -23,8 +24,6 @@ import org.apache.commons.lang3.StringUtils;
@AllArgsConstructor
@XStreamAlias("xml")
public class WxPayUnifiedOrderRequest extends WxPayBaseRequest {
private static final String[] TRADE_TYPES = new String[]{"JSAPI", "NATIVE", "APP", "MWEB"};

/**
* <pre>
* 字段名:设备号
@@ -334,16 +333,11 @@ public class WxPayUnifiedOrderRequest extends WxPayBaseRequest {

@Override
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");
}

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");
}
}


+ 3
- 29
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/WxPayServiceAbstractImplTest.java Zobrazit soubor

@@ -24,7 +24,6 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;

import static org.testng.Assert.*;

@@ -103,26 +102,11 @@ public class WxPayServiceAbstractImplTest {
.createOrder(WxPayUnifiedOrderRequest.newBuilder()
.body("我去")
.totalFee(1)
.productId("aaa")
.spbillCreateIp("11.1.11.1")
.notifyURL("111111")
.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());
this.logger.info(result.toString());
this.logger.warn(this.payService.getWxApiData().toString());
@@ -130,17 +114,7 @@ public class WxPayServiceAbstractImplTest {

@Test
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
}

/**


Načítá se…
Zrušit
Uložit