|
|
package com.yoho.pay;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.yoho.core.common.utils.DateUtil;
|
|
|
import com.yoho.core.common.utils.MD5;
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
public class PayTest {
|
|
|
|
|
|
|
|
|
public static final String url = "https://qr-test2.chinaums.com/netpay-route-server/api/";
|
|
|
|
|
|
/**
|
|
|
* 预支付=下单接口 支付宝
|
|
|
*/
|
|
|
@Test
|
|
|
public void testPrepay() throws Exception {
|
|
|
|
|
|
JSONObject data = new JSONObject();
|
|
|
data.put("msgSrc","WWW.TEST.COM");
|
|
|
// 支付宝
|
|
|
data.put("msgType", "trade.precreate"); // 微信:wx.unifiedOrder, 支付宝:trade.precreate, 全民付:qmf.order, 银联云闪付:uac.appOrder
|
|
|
data.put("requestTimestamp", DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
|
|
// 支付宝- 31945075157
|
|
|
data.put("merOrderId", "31945075157");
|
|
|
data.put("mid", "898310148160568"); //商户号 仅用于支付宝和云闪付
|
|
|
data.put("tid","00000001"); //终端号
|
|
|
data.put("instMid", "APPDEFAULT"); // 机构商户号
|
|
|
data.put("totalAmount", 1);
|
|
|
|
|
|
|
|
|
data.put("sign", getSign(data));
|
|
|
|
|
|
HttpClient httpClient = new HttpClient();
|
|
|
httpClient.init();
|
|
|
String result = httpClient.post(url, JSON.toJSONString(data));
|
|
|
System.out.println(result);
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 预支付=下单接口 微信
|
|
|
*/
|
|
|
@Test
|
|
|
public void testPrepayWx() throws Exception {
|
|
|
|
|
|
JSONObject data = new JSONObject();
|
|
|
data.put("msgSrc","WWW.TEST.COM");
|
|
|
// 支付宝
|
|
|
data.put("msgType", "wx.unifiedOrder"); // 微信:wx.unifiedOrder, 支付宝:trade.precreate, 全民付:qmf.order, 银联云闪付:uac.appOrder
|
|
|
data.put("requestTimestamp", DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
|
|
// 支付宝- 31945075157
|
|
|
data.put("merOrderId", "3194"+"24253748565");
|
|
|
data.put("mid", "898310148160568"); //商户号 仅用于支付宝和云闪付
|
|
|
data.put("tid","00000001"); //终端号
|
|
|
data.put("instMid", "APPDEFAULT"); // 机构商户号
|
|
|
data.put("totalAmount", 1);
|
|
|
data.put("tradeType","APP");
|
|
|
|
|
|
|
|
|
data.put("sign", getSign(data));
|
|
|
|
|
|
HttpClient httpClient = new HttpClient();
|
|
|
httpClient.init();
|
|
|
String result = httpClient.post(url, JSON.toJSONString(data));
|
|
|
System.out.println(result);
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 预支付=下单接口 微信
|
|
|
*/
|
|
|
@Test
|
|
|
public void testPrepayQmf() throws Exception {
|
|
|
|
|
|
JSONObject data = new JSONObject();
|
|
|
data.put("msgSrc","WWW.TEST.COM");
|
|
|
// 支付宝
|
|
|
data.put("msgType", "uac.appOrder"); // 微信:wx.unifiedOrder, 支付宝:trade.precreate, 全民付:qmf.order, 银联云闪付:uac.appOrder
|
|
|
data.put("requestTimestamp", DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
|
|
// 支付宝- 31945075157
|
|
|
data.put("merOrderId", "3194"+"24253748567");
|
|
|
data.put("mid", "898310148160568"); //商户号 仅用于支付宝和云闪付
|
|
|
data.put("tid","00000001"); //终端号
|
|
|
data.put("instMid", "APPDEFAULT"); // 机构商户号
|
|
|
data.put("totalAmount", 1);
|
|
|
data.put("tradeType","APP");
|
|
|
|
|
|
|
|
|
data.put("sign", getSign(data));
|
|
|
|
|
|
HttpClient httpClient = new HttpClient();
|
|
|
httpClient.init();
|
|
|
String result = httpClient.post(url, JSON.toJSONString(data));
|
|
|
System.out.println(result);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
public static String getSign(JSONObject data){
|
|
|
List<String> list = Lists.newArrayList();
|
|
|
for (String str: data.keySet()){
|
|
|
list.add(str+"="+data.getString(str));
|
|
|
}
|
|
|
|
|
|
Collections.sort(list);
|
|
|
String param = list.stream().collect(Collectors.joining("&"));
|
|
|
|
|
|
String sign = MD5.md5(param+"fcAmtnx7MwismjWNhNKdHC44mNXtnEQeJkRrhKJwyrW2ysRR");
|
|
|
return sign;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 订单查询接口
|
|
|
*/
|
|
|
@Test
|
|
|
public void testQuary(){
|
|
|
|
|
|
JSONObject data = new JSONObject();
|
|
|
data.put("msgSrc","WWW.TEST.COM");
|
|
|
// 支付宝
|
|
|
data.put("msgType", "query"); // 微信:wx.unifiedOrder, 支付宝:trade.precreate, 全民付:qmf.order, 银联云闪付:uac.appOrder
|
|
|
data.put("requestTimestamp", DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
|
|
data.put("merOrderId", "24455075157");
|
|
|
data.put("mid", "898310148160568"); //商户号 仅用于支付宝和云闪付
|
|
|
data.put("tid","00000001"); //终端号
|
|
|
data.put("instMid", "APPDEFAULT"); // 机构商户号
|
|
|
|
|
|
data.put("sign", getSign(data));
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 订单退款
|
|
|
*/
|
|
|
@Test
|
|
|
public void testRefund(){
|
|
|
|
|
|
JSONObject data = new JSONObject();
|
|
|
data.put("msgSrc","WWW.TEST.COM");
|
|
|
// 支付宝
|
|
|
data.put("msgType", "refund"); // 微信:wx.unifiedOrder, 支付宝:trade.precreate, 全民付:qmf.order, 银联云闪付:uac.appOrder
|
|
|
data.put("requestTimestamp", DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
|
|
data.put("merOrderId", "24455075157");
|
|
|
data.put("mid", "898310148160568"); //商户号 仅用于支付宝和云闪付
|
|
|
data.put("tid","00000001"); //终端号
|
|
|
data.put("instMid", "APPDEFAULT"); // 机构商户号
|
|
|
data.put("refundAmount",1);
|
|
|
|
|
|
data.put("sign", getSign(data));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 订单关闭
|
|
|
*/
|
|
|
@Test
|
|
|
public void testClose(){
|
|
|
|
|
|
JSONObject data = new JSONObject();
|
|
|
data.put("msgSrc","WWW.TEST.COM");
|
|
|
// 支付宝
|
|
|
data.put("msgType", "close"); // 微信:wx.unifiedOrder, 支付宝:trade.precreate, 全民付:qmf.order, 银联云闪付:uac.appOrder
|
|
|
data.put("requestTimestamp", DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
|
|
data.put("merOrderId", "24455075157");
|
|
|
data.put("mid", "898310148160568"); //商户号 仅用于支付宝和云闪付
|
|
|
data.put("tid","00000001"); //终端号
|
|
|
data.put("instMid", "APPDEFAULT"); // 机构商户号
|
|
|
data.put("refundAmount",1);
|
|
|
|
|
|
data.put("sign", getSign(data));
|
|
|
}
|
|
|
|
|
|
// 回调接口
|
|
|
|
|
|
} |
...
|
...
|
|