更新单元测试类
This commit is contained in:
parent
9dbc95a2dd
commit
21e5947ca4
@ -55,11 +55,32 @@ public class WeixinPayAccount extends WeixinAccount {
|
||||
* @param paySignKey
|
||||
* 支付密钥字符串(必填)
|
||||
* @param mchId
|
||||
* 微信支付分配的商户号(必填)
|
||||
*/
|
||||
public WeixinPayAccount(String appId, String appSecret, String paySignKey,
|
||||
String mchId) {
|
||||
this(appId, appSecret, paySignKey, mchId, null, null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付商户信息
|
||||
*
|
||||
* @param appId
|
||||
* 公众号唯一的身份ID
|
||||
* @param appSecret
|
||||
* 调用接口的凭证
|
||||
* @param paySignKey
|
||||
* 支付密钥字符串(必填)
|
||||
* @param mchId
|
||||
* 微信支付分配的商户号(V3版本必填)
|
||||
* @param partnerId 财付通的商户号(V2版本必填)
|
||||
* @param partnerKey 财付通商户权限密钥Key(V2版本必填)
|
||||
* @param subMchId 微信支付分配的子商户号,受理模式下必填(商户平台版)
|
||||
* @param deviceInfo 微信支付分配的设备号(商户平台版)
|
||||
* @param partnerId
|
||||
* 财付通的商户号(V2版本必填)
|
||||
* @param partnerKey
|
||||
* 财付通商户权限密钥Key(V2版本必填)
|
||||
* @param subMchId
|
||||
* 微信支付分配的子商户号,受理模式下必填(商户平台版)
|
||||
* @param deviceInfo
|
||||
* 微信支付分配的设备号(商户平台版)
|
||||
*/
|
||||
@JSONCreator
|
||||
public WeixinPayAccount(@JSONField(name = "id") String appId,
|
||||
|
||||
@ -22,7 +22,7 @@ import com.foxinmy.weixin4j.type.MPPaymentCheckNameType;
|
||||
* @since JDK 1.7
|
||||
* @see
|
||||
*/
|
||||
public class CashTest extends CouponTest {
|
||||
public class CashTest extends PayTest {
|
||||
|
||||
@Test
|
||||
public void sendRedpacket() throws WeixinException, IOException {
|
||||
@ -35,7 +35,7 @@ public class CashTest extends CouponTest {
|
||||
redpacket.setRemark("快来领取红包吧!");
|
||||
redpacket.setTotalNum(1);
|
||||
redpacket.setWishing("来就送钱");
|
||||
RedpacketSendResult result = WEIXINPAY.sendRedpack(new FileInputStream(
|
||||
RedpacketSendResult result = PAY3.sendRedpack(new FileInputStream(
|
||||
caFile), redpacket);
|
||||
System.err.println(result);
|
||||
}
|
||||
@ -43,7 +43,7 @@ public class CashTest extends CouponTest {
|
||||
@Test
|
||||
public void queryRedpacket() throws WeixinException, IOException {
|
||||
String outTradeNo = "HB001";
|
||||
RedpacketRecord record = WEIXINPAY.queryRedpack(new FileInputStream(
|
||||
RedpacketRecord record = PAY3.queryRedpack(new FileInputStream(
|
||||
caFile), outTradeNo);
|
||||
System.err.println(record);
|
||||
}
|
||||
@ -53,7 +53,7 @@ public class CashTest extends CouponTest {
|
||||
MPPayment payment = new MPPayment("MP001",
|
||||
"oyFLst1bqtuTcxK-ojF8hOGtLQao",
|
||||
MPPaymentCheckNameType.NO_CHECK, "企业付款测试", 0.01d, "127.0.0.1");
|
||||
MPPaymentResult result = WEIXINPAY.mpPayment(
|
||||
MPPaymentResult result = PAY3.mpPayment(
|
||||
new FileInputStream(caFile), payment);
|
||||
System.err.println(result);
|
||||
}
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package com.foxinmy.weixin4j.mp.test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
@ -10,8 +9,6 @@ import org.junit.Test;
|
||||
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.model.Consts;
|
||||
import com.foxinmy.weixin4j.model.WeixinPayAccount;
|
||||
import com.foxinmy.weixin4j.payment.WeixinPayProxy;
|
||||
import com.foxinmy.weixin4j.payment.coupon.CouponDetail;
|
||||
import com.foxinmy.weixin4j.payment.coupon.CouponResult;
|
||||
import com.foxinmy.weixin4j.payment.coupon.CouponStock;
|
||||
@ -26,34 +23,26 @@ import com.foxinmy.weixin4j.util.DateUtil;
|
||||
* @since JDK 1.7
|
||||
* @see
|
||||
*/
|
||||
public class CouponTest {
|
||||
protected final static WeixinPayProxy WEIXINPAY;
|
||||
protected final static WeixinPayAccount ACCOUNT;
|
||||
static {
|
||||
ACCOUNT = new WeixinPayAccount("appid", "appsecret", "paysign",
|
||||
"mchid", null, null, null, null);
|
||||
WEIXINPAY = new WeixinPayProxy(ACCOUNT);
|
||||
}
|
||||
protected final File caFile = new File("证书文件路径(*.p12)");
|
||||
public class CouponTest extends PayTest {
|
||||
|
||||
@Test
|
||||
public void sendCoupon() throws WeixinException, IOException {
|
||||
String partnerTradeNo = String.format("%s%s%s", ACCOUNT.getMchId(),
|
||||
String partnerTradeNo = String.format("%s%s%s", ACCOUNT3.getMchId(),
|
||||
DateUtil.fortmat2yyyyMMdd(new Date()), "1");
|
||||
CouponResult result = WEIXINPAY.sendCoupon(new FileInputStream(caFile),
|
||||
CouponResult result = PAY3.sendCoupon(new FileInputStream(caFile),
|
||||
"123", partnerTradeNo, "oyFLst1bqtuTcxK-ojF8hOGtLQao", null);
|
||||
Assert.assertTrue(result.getRetCode().equalsIgnoreCase(Consts.SUCCESS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryCouponStock() throws WeixinException {
|
||||
CouponStock couponStock = WEIXINPAY.queryCouponStock("couponStockId");
|
||||
CouponStock couponStock = PAY3.queryCouponStock("couponStockId");
|
||||
System.err.println(couponStock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryCouponDetail() throws WeixinException {
|
||||
CouponDetail couponDetail = WEIXINPAY.queryCouponDetail("couponId");
|
||||
CouponDetail couponDetail = PAY3.queryCouponDetail("couponId");
|
||||
System.err.println(couponDetail);
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,21 +26,35 @@ import com.foxinmy.weixin4j.type.IdType;
|
||||
import com.foxinmy.weixin4j.type.TradeType;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
||||
|
||||
/**
|
||||
* 支付相关测试
|
||||
*
|
||||
* @className PayTest
|
||||
* @author jy
|
||||
* @date 2015年8月19日
|
||||
* @since JDK 1.7
|
||||
* @see
|
||||
*/
|
||||
public class PayTest {
|
||||
private final static Pay2Api PAY2;
|
||||
private final static WeixinPayProxy PAY3;
|
||||
private final static WeixinPayAccount ACCOUNT2;
|
||||
private final static WeixinPayAccount ACCOUNT3;
|
||||
protected final static Pay2Api PAY2;
|
||||
protected final static WeixinPayProxy PAY3;
|
||||
protected final static WeixinPayAccount ACCOUNT2;
|
||||
protected final static WeixinPayAccount ACCOUNT3;
|
||||
static {
|
||||
ACCOUNT2 = new WeixinPayAccount("请填入v2版本的appid", "请填入v2版本的appSecret",
|
||||
"请填入v2版本的paysignkey", null, null, null, "请填入v2版本的partnerId",
|
||||
"请填入v2版本的partnerKey");
|
||||
PAY2 = new Pay2Api(ACCOUNT2, new FileTokenStorager(Weixin4jConfigUtil.getValue(
|
||||
"token_path", "/tmp/weixin4j/token")));
|
||||
PAY2 = new Pay2Api(ACCOUNT2, new FileTokenStorager(
|
||||
Weixin4jConfigUtil
|
||||
.getValue("token_path", "/tmp/weixin4j/token")));
|
||||
ACCOUNT3 = new WeixinPayAccount("请填入v3版本的appid", "请填入v3版本的appSecret",
|
||||
"请填入v3版本的paysignkey", "请填入v3版本的mchid", null, null, null, null);
|
||||
"请填入v3版本的paysignkey", "请填入v3版本的mchid");
|
||||
PAY3 = new WeixinPayProxy(ACCOUNT3);
|
||||
}
|
||||
/**
|
||||
* 商户的证书文件
|
||||
*/
|
||||
protected final File caFile = new File("签名证书,如12333.p12");
|
||||
|
||||
@Test
|
||||
public void orderQueryV2() throws WeixinException {
|
||||
@ -50,7 +64,7 @@ public class PayTest {
|
||||
|
||||
@Test
|
||||
public void refundV2() throws WeixinException {
|
||||
File caFile = new File("签名文件,如12333.pfx");
|
||||
File caFile = new File("签名证书,如12333.pfx");
|
||||
IdQuery idQuery = new IdQuery("D15020300005", IdType.TRADENO);
|
||||
System.err.println(PAY2.refundApply(caFile, idQuery, "1422925555037",
|
||||
16d, 16d, "1221928801", "111111", null, null, null));
|
||||
@ -113,7 +127,6 @@ public class PayTest {
|
||||
|
||||
@Test
|
||||
public void refundV3() throws WeixinException, IOException {
|
||||
File caFile = new File("签名文件如123.p12");
|
||||
IdQuery idQuery = new IdQuery("TT_1427183696238", IdType.TRADENO);
|
||||
com.foxinmy.weixin4j.payment.mch.RefundResult result = PAY3
|
||||
.refundApply(new FileInputStream(caFile), idQuery, "TT_R"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user