u
This commit is contained in:
parent
841e1f76f1
commit
daba44fd02
@ -27,167 +27,305 @@ import com.foxinmy.weixin4j.type.TradeType;
|
|||||||
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* 支付相关测试
|
* 支付相关测试
|
||||||
*
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
* @className PayTest
|
* @className PayTest
|
||||||
|
*
|
||||||
* @author jy
|
* @author jy
|
||||||
|
*
|
||||||
* @date 2015年8月19日
|
* @date 2015年8月19日
|
||||||
|
*
|
||||||
* @since JDK 1.7
|
* @since JDK 1.7
|
||||||
|
*
|
||||||
* @see
|
* @see
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class PayTest {
|
public class PayTest {
|
||||||
|
|
||||||
protected final static Pay2Api PAY2;
|
protected final static Pay2Api PAY2;
|
||||||
|
|
||||||
protected final static WeixinPayProxy PAY3;
|
protected final static WeixinPayProxy PAY3;
|
||||||
|
|
||||||
protected final static WeixinPayAccount ACCOUNT2;
|
protected final static WeixinPayAccount ACCOUNT2;
|
||||||
|
|
||||||
protected final static WeixinPayAccount ACCOUNT3;
|
protected final static WeixinPayAccount ACCOUNT3;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
ACCOUNT2 = new WeixinPayAccount("请填入v2版本的appid", "请填入v2版本的appSecret",
|
|
||||||
"请填入v2版本的paysignkey", null, null, null, "请填入v2版本的partnerId",
|
ACCOUNT2 = new WeixinPayAccount(
|
||||||
"请填入v2版本的partnerKey");
|
|
||||||
|
"wxba294f2c6f330361",
|
||||||
|
|
||||||
|
"8e33f5371a1afea1f7bce88088cb4bba",
|
||||||
|
|
||||||
|
"gADrKITv3qYWu9JEg1NS0WPaU5yFgTwS9WfPueskfPpt3OZGpnUN1uBom36G2tP701vi2pPRJLZF9dEDFj9pqxidPn10Y91Lj8kK37Svz6S4MfeAHo9svFZmHkIKScGb",
|
||||||
|
|
||||||
|
null, null, null, "1221928801",
|
||||||
|
|
||||||
|
"8d1b26231827a965ef54fe6a3a151551");
|
||||||
|
|
||||||
PAY2 = new Pay2Api(ACCOUNT2, new FileTokenStorager(
|
PAY2 = new Pay2Api(ACCOUNT2, new FileTokenStorager(
|
||||||
|
|
||||||
Weixin4jConfigUtil
|
Weixin4jConfigUtil
|
||||||
|
|
||||||
.getValue("token_path", "/tmp/weixin4j/token")));
|
.getValue("token_path", "/tmp/weixin4j/token")));
|
||||||
ACCOUNT3 = new WeixinPayAccount("请填入v3版本的appid", "请填入v3版本的appSecret",
|
|
||||||
"请填入v3版本的paysignkey", "请填入v3版本的mchid");
|
ACCOUNT3 = new WeixinPayAccount("wx0d1d598c0c03c999",
|
||||||
|
|
||||||
|
"2513ac683f1beabdb6b98d9ddd9e5755",
|
||||||
|
|
||||||
|
"GATFzDwbQdbbci3QEQxX2rUBvwTrsMiZ", "10020674");
|
||||||
|
|
||||||
PAY3 = new WeixinPayProxy(ACCOUNT3);
|
PAY3 = new WeixinPayProxy(ACCOUNT3);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* 商户的证书文件
|
* 商户的证书文件
|
||||||
*/
|
*/
|
||||||
protected final File caFile = new File("签名证书,如12333.p12");
|
|
||||||
|
protected final File caFile = new File(
|
||||||
|
|
||||||
|
"/Users/jy/workspace/feican/canyi-weixin-parent/canyi-weixin-service/src/main/resources/10020674.p12");
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void orderQueryV2() throws WeixinException {
|
public void orderQueryV2() throws WeixinException {
|
||||||
|
|
||||||
System.err.println(PAY2.orderQuery(new IdQuery("D14110500021",
|
System.err.println(PAY2.orderQuery(new IdQuery("D14110500021",
|
||||||
|
|
||||||
IdType.REFUNDNO)));
|
IdType.REFUNDNO)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void refundV2() throws WeixinException {
|
public void refundV2() throws WeixinException {
|
||||||
File caFile = new File("签名证书,如12333.pfx");
|
|
||||||
|
File caFile = new File(
|
||||||
|
|
||||||
|
"/Users/jy/workspace/feican/canyi-weixin-parent/canyi-weixin-service/src/main/resources/1221928801.pfx");
|
||||||
|
|
||||||
IdQuery idQuery = new IdQuery("D15020300005", IdType.TRADENO);
|
IdQuery idQuery = new IdQuery("D15020300005", IdType.TRADENO);
|
||||||
|
|
||||||
System.err.println(PAY2.refundApply(caFile, idQuery, "1422925555037",
|
System.err.println(PAY2.refundApply(caFile, idQuery, "1422925555037",
|
||||||
|
|
||||||
16d, 16d, "1221928801", "111111", null, null, null));
|
16d, 16d, "1221928801", "111111", null, null, null));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void refundQueryV2() throws WeixinException {
|
public void refundQueryV2() throws WeixinException {
|
||||||
|
|
||||||
System.err.println(PAY2.refundQuery(new IdQuery("D14123000004",
|
System.err.println(PAY2.refundQuery(new IdQuery("D14123000004",
|
||||||
|
|
||||||
IdType.TRADENO)));
|
IdType.TRADENO)));
|
||||||
|
|
||||||
refundQueryV3();
|
refundQueryV3();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void downbillV2() throws WeixinException {
|
public void downbillV2() throws WeixinException {
|
||||||
|
|
||||||
Calendar c = Calendar.getInstance();
|
Calendar c = Calendar.getInstance();
|
||||||
|
|
||||||
c.set(Calendar.YEAR, 2014);
|
c.set(Calendar.YEAR, 2014);
|
||||||
|
|
||||||
c.set(Calendar.MONTH, 11);
|
c.set(Calendar.MONTH, 11);
|
||||||
|
|
||||||
c.set(Calendar.DAY_OF_MONTH, 22);
|
c.set(Calendar.DAY_OF_MONTH, 22);
|
||||||
|
|
||||||
File file = PAY2.downloadbill(c.getTime(), null);
|
File file = PAY2.downloadbill(c.getTime(), null);
|
||||||
|
|
||||||
System.err.println(file);
|
System.err.println(file);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void orderQueryV3() throws WeixinException {
|
public void orderQueryV3() throws WeixinException {
|
||||||
|
|
||||||
Order order = PAY3.orderQuery(new IdQuery("T0002", IdType.TRADENO));
|
Order order = PAY3.orderQuery(new IdQuery("T0002", IdType.TRADENO));
|
||||||
|
|
||||||
System.err.println(order);
|
System.err.println(order);
|
||||||
|
|
||||||
String sign = order.getSign();
|
String sign = order.getSign();
|
||||||
|
|
||||||
order.setSign(null);
|
order.setSign(null);
|
||||||
|
|
||||||
String valiSign = PayUtil.paysignMd5(order, ACCOUNT3.getPaySignKey());
|
String valiSign = PayUtil.paysignMd5(order, ACCOUNT3.getPaySignKey());
|
||||||
|
|
||||||
System.err
|
System.err
|
||||||
|
|
||||||
.println(String.format("sign=%s,valiSign=%s", sign, valiSign));
|
.println(String.format("sign=%s,valiSign=%s", sign, valiSign));
|
||||||
|
|
||||||
Assert.assertEquals(valiSign, sign);
|
Assert.assertEquals(valiSign, sign);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void refundQueryV3() throws WeixinException {
|
public void refundQueryV3() throws WeixinException {
|
||||||
|
|
||||||
com.foxinmy.weixin4j.payment.mch.RefundRecord record = PAY3
|
com.foxinmy.weixin4j.payment.mch.RefundRecord record = PAY3
|
||||||
|
|
||||||
.refundQueryV3(new IdQuery("TT_1427183696238", IdType.TRADENO));
|
.refundQueryV3(new IdQuery("TT_1427183696238", IdType.TRADENO));
|
||||||
|
|
||||||
System.err.println(record);
|
System.err.println(record);
|
||||||
|
|
||||||
// 这里的验证签名需要把details循环拼接
|
// 这里的验证签名需要把details循环拼接
|
||||||
|
|
||||||
String sign = record.getSign();
|
String sign = record.getSign();
|
||||||
|
|
||||||
record.setSign(null);
|
record.setSign(null);
|
||||||
|
|
||||||
String valiSign = PayUtil.paysignMd5(record, ACCOUNT3.getPaySignKey());
|
String valiSign = PayUtil.paysignMd5(record, ACCOUNT3.getPaySignKey());
|
||||||
|
|
||||||
System.err
|
System.err
|
||||||
|
|
||||||
.println(String.format("sign=%s,valiSign=%s", sign, valiSign));
|
.println(String.format("sign=%s,valiSign=%s", sign, valiSign));
|
||||||
|
|
||||||
Assert.assertEquals(valiSign, sign);
|
Assert.assertEquals(valiSign, sign);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void downbillV3() throws WeixinException {
|
public void downbillV3() throws WeixinException {
|
||||||
|
|
||||||
Calendar c = Calendar.getInstance();
|
Calendar c = Calendar.getInstance();
|
||||||
|
|
||||||
System.err.println(c.getTime());
|
System.err.println(c.getTime());
|
||||||
|
|
||||||
c.set(Calendar.YEAR, 2015);
|
c.set(Calendar.YEAR, 2015);
|
||||||
|
|
||||||
c.set(Calendar.MONTH, 2);
|
c.set(Calendar.MONTH, 2);
|
||||||
|
|
||||||
c.set(Calendar.DAY_OF_MONTH, 24);
|
c.set(Calendar.DAY_OF_MONTH, 24);
|
||||||
|
|
||||||
System.err.println(c.getTime());
|
System.err.println(c.getTime());
|
||||||
|
|
||||||
File file = PAY3.downloadbill(c.getTime(), null);
|
File file = PAY3.downloadbill(c.getTime(), null);
|
||||||
|
|
||||||
System.err.println(file);
|
System.err.println(file);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void refundV3() throws WeixinException, IOException {
|
public void refundV3() throws WeixinException, IOException {
|
||||||
|
|
||||||
IdQuery idQuery = new IdQuery("TT_1427183696238", IdType.TRADENO);
|
IdQuery idQuery = new IdQuery("TT_1427183696238", IdType.TRADENO);
|
||||||
|
|
||||||
com.foxinmy.weixin4j.payment.mch.RefundResult result = PAY3
|
com.foxinmy.weixin4j.payment.mch.RefundResult result = PAY3
|
||||||
|
|
||||||
.refundApply(new FileInputStream(caFile), idQuery, "TT_R"
|
.refundApply(new FileInputStream(caFile), idQuery, "TT_R"
|
||||||
|
|
||||||
+ System.currentTimeMillis(), 0.01d, 0.01d, null,
|
+ System.currentTimeMillis(), 0.01d, 0.01d, null,
|
||||||
|
|
||||||
"10020674");
|
"10020674");
|
||||||
|
|
||||||
System.err.println(result);
|
System.err.println(result);
|
||||||
|
|
||||||
String sign = result.getSign();
|
String sign = result.getSign();
|
||||||
|
|
||||||
result.setSign(null);
|
result.setSign(null);
|
||||||
|
|
||||||
String valiSign = PayUtil.paysignMd5(result, ACCOUNT3.getPaySignKey());
|
String valiSign = PayUtil.paysignMd5(result, ACCOUNT3.getPaySignKey());
|
||||||
|
|
||||||
System.err
|
System.err
|
||||||
|
|
||||||
.println(String.format("sign=%s,valiSign=%s", sign, valiSign));
|
.println(String.format("sign=%s,valiSign=%s", sign, valiSign));
|
||||||
|
|
||||||
Assert.assertEquals(valiSign, sign);
|
Assert.assertEquals(valiSign, sign);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nativeV3() throws WeixinException {
|
public void nativeV3() throws WeixinException {
|
||||||
|
|
||||||
MchPayPackage payPackageV3 = new MchPayPackage(ACCOUNT3,
|
MchPayPackage payPackageV3 = new MchPayPackage(ACCOUNT3,
|
||||||
|
|
||||||
"oyFLst1bqtuTcxK-ojF8hOGtLQao", "native测试", "T0001", 0.1d,
|
"oyFLst1bqtuTcxK-ojF8hOGtLQao", "native测试", "T0001", 0.1d,
|
||||||
|
|
||||||
"127.0.0.1", TradeType.NATIVE);
|
"127.0.0.1", TradeType.NATIVE);
|
||||||
|
|
||||||
payPackageV3.setProductId("0001");
|
payPackageV3.setProductId("0001");
|
||||||
|
|
||||||
payPackageV3.setNotifyUrl("xxxx");
|
payPackageV3.setNotifyUrl("xxxx");
|
||||||
|
|
||||||
PrePay prePay = null;
|
PrePay prePay = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
prePay = PayUtil.createPrePay(payPackageV3,
|
prePay = PayUtil.createPrePay(payPackageV3,
|
||||||
|
|
||||||
ACCOUNT3.getPaySignKey());
|
ACCOUNT3.getPaySignKey());
|
||||||
|
|
||||||
} catch (PayException e) {
|
} catch (PayException e) {
|
||||||
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
System.err.println(prePay);
|
System.err.println(prePay);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void closeOrder() throws WeixinException {
|
public void closeOrder() throws WeixinException {
|
||||||
|
|
||||||
ApiResult result = PAY3.closeOrder("D111");
|
ApiResult result = PAY3.closeOrder("D111");
|
||||||
|
|
||||||
System.err.println(result);
|
System.err.println(result);
|
||||||
|
|
||||||
String sign = result.getSign();
|
String sign = result.getSign();
|
||||||
|
|
||||||
result.setSign(null);
|
result.setSign(null);
|
||||||
|
|
||||||
String valiSign = PayUtil.paysignMd5(result, ACCOUNT3.getPaySignKey());
|
String valiSign = PayUtil.paysignMd5(result, ACCOUNT3.getPaySignKey());
|
||||||
|
|
||||||
System.err
|
System.err
|
||||||
|
|
||||||
.println(String.format("sign=%s,valiSign=%s", sign, valiSign));
|
.println(String.format("sign=%s,valiSign=%s", sign, valiSign));
|
||||||
|
|
||||||
Assert.assertEquals(valiSign, sign);
|
Assert.assertEquals(valiSign, sign);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shortUrl() throws WeixinException {
|
public void shortUrl() throws WeixinException {
|
||||||
|
|
||||||
String url = "weixin://wxpay/bizpayurl?xxxxxx";
|
String url = "weixin://wxpay/bizpayurl?xxxxxx";
|
||||||
|
|
||||||
String shortUrl = PAY3.getPayShorturl(url);
|
String shortUrl = PAY3.getPayShorturl(url);
|
||||||
|
|
||||||
System.err.println(shortUrl);
|
System.err.println(shortUrl);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void interfaceReport() throws WeixinException {
|
public void interfaceReport() throws WeixinException {
|
||||||
|
|
||||||
String interfaceUrl = "https://api.mch.weixin.qq.com/pay/unifiedorder";
|
String interfaceUrl = "https://api.mch.weixin.qq.com/pay/unifiedorder";
|
||||||
|
|
||||||
int executeTime = 2500;
|
int executeTime = 2500;
|
||||||
|
|
||||||
String outTradeNo = null;
|
String outTradeNo = null;
|
||||||
|
|
||||||
String ip = "127.0.0.1";
|
String ip = "127.0.0.1";
|
||||||
|
|
||||||
Date time = new Date();
|
Date time = new Date();
|
||||||
|
|
||||||
XmlResult returnXml = new XmlResult("SUCCESS", "");
|
XmlResult returnXml = new XmlResult("SUCCESS", "");
|
||||||
|
|
||||||
returnXml.setResultCode("SUCCESS");
|
returnXml.setResultCode("SUCCESS");
|
||||||
|
|
||||||
returnXml = PAY3.interfaceReport(interfaceUrl, executeTime, outTradeNo,
|
returnXml = PAY3.interfaceReport(interfaceUrl, executeTime, outTradeNo,
|
||||||
|
|
||||||
ip, time, returnXml);
|
ip, time, returnXml);
|
||||||
|
|
||||||
System.err.println(returnXml);
|
System.err.println(returnXml);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user