|
|
@@ -7,9 +7,7 @@ import com.mrxu.framework.common.util.IdFunc;
|
|
|
import com.mrxu.framework.common.util.MrxuAssert;
|
|
|
import com.mrxu.framework.common.util.StrFunc;
|
|
|
import com.mrxu.framework.common.xcx.WeixinUtil;
|
|
|
-import com.mrxu.framework.common.xcx.bean.PayBaseResponse;
|
|
|
-import com.mrxu.framework.common.xcx.bean.UnifiedorderRequest;
|
|
|
-import com.mrxu.framework.common.xcx.bean.UnifiedorderResponse;
|
|
|
+import com.mrxu.framework.common.xcx.bean.*;
|
|
|
|
|
|
import java.util.TreeMap;
|
|
|
|
|
|
@@ -19,7 +17,9 @@ public class PayService {
|
|
|
private static String unifiedorder = "https://api.mch.weixin.qq.com/pay/unifiedorder";
|
|
|
//查询订单状态
|
|
|
private static String orderquery = "https://api.mch.weixin.qq.com/pay/orderquery";
|
|
|
-
|
|
|
+ // 关闭订单
|
|
|
+ private static String closeorder = "https://api.mch.weixin.qq.com/pay/closeorder";
|
|
|
+ // 申请退款
|
|
|
private static String refund = "https://api.mch.weixin.qq.com/secapi/pay/refund";
|
|
|
|
|
|
// https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_1
|
|
|
@@ -27,6 +27,21 @@ public class PayService {
|
|
|
return request(UnifiedorderResponse.class,unifiedorder,"POST",request,apiKey,null);
|
|
|
}
|
|
|
|
|
|
+ // https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_2
|
|
|
+ public static OrderqueryResponse orderquery(OrderqueryRequest request, String apiKey) {
|
|
|
+ return request(OrderqueryResponse.class,orderquery,"POST",request,apiKey,null);
|
|
|
+ }
|
|
|
+
|
|
|
+ // https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_3
|
|
|
+ public static CloseorderResponse closeorder(CloseorderRequest request, String apiKey) {
|
|
|
+ return request(CloseorderResponse.class,closeorder,"POST",request,apiKey,null);
|
|
|
+ }
|
|
|
+
|
|
|
+ // https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_4
|
|
|
+ public static RefundResponse refund(RefundRequest request, String apiKey) {
|
|
|
+ return request(RefundResponse.class,refund,"POST",request,apiKey,null);
|
|
|
+ }
|
|
|
+
|
|
|
private static <T extends PayBaseResponse> T request(Class<T> clazz, String requestUrl, String requestMethod, Object requestBean, String apiKey, String certName) {
|
|
|
MrxuAssert.validateBean(requestBean);
|
|
|
String jsonStr = JSONUtil.toJsonStr(requestBean);
|
|
|
@@ -36,6 +51,7 @@ public class PayService {
|
|
|
parameters.put("sign", sign);
|
|
|
String requestXML = WeixinUtil.getRequestXml(parameters);
|
|
|
String resultStr = HttpUtil.httpsRequest(requestUrl,requestMethod,requestXML,null);
|
|
|
+ MrxuAssert.isNotEmpty(resultStr,"微信未响应");
|
|
|
System.out.println(resultStr);
|
|
|
JSONObject resultJson = WeixinUtil.doXMLParse(resultStr);
|
|
|
T result = JSONUtil.toBean(resultJson.toJSONString(),clazz);
|
|
|
@@ -43,7 +59,16 @@ public class PayService {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
+ public static void orderquery(String[] args) {
|
|
|
+ OrderqueryRequest request = new OrderqueryRequest();
|
|
|
+ request.setAppid("wx199e4718946c4e6d");
|
|
|
+ request.setMch_id("1514682921");
|
|
|
+ request.setNonce_str(StrFunc.randomString(32));
|
|
|
+ request.setOut_trade_no(IdFunc.getId("F"));
|
|
|
+ orderquery(request,"7616442b20a95c985ae712d72797c4c7");
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void createOrder(String[] args) {
|
|
|
UnifiedorderRequest request = new UnifiedorderRequest();
|
|
|
request.setAppid("wx199e4718946c4e6d");
|
|
|
request.setMch_id("1514682921");
|
|
|
@@ -59,5 +84,26 @@ public class PayService {
|
|
|
unifiedorder(request,"7616442b20a95c985ae712d72797c4c7");
|
|
|
}
|
|
|
|
|
|
+ public static void closeorder(String[] args) {
|
|
|
+ CloseorderRequest request = new CloseorderRequest();
|
|
|
+ request.setAppid("wx199e4718946c4e6d");
|
|
|
+ request.setMch_id("1514682921");
|
|
|
+ request.setNonce_str(StrFunc.randomString(32));
|
|
|
+ request.setOut_trade_no(IdFunc.getId("F"));
|
|
|
+ closeorder(request,"7616442b20a95c985ae712d72797c4c7");
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ RefundRequest request = new RefundRequest();
|
|
|
+ request.setAppid("wx199e4718946c4e6d");
|
|
|
+ request.setMch_id("1514682921");
|
|
|
+ request.setNonce_str(StrFunc.randomString(32));
|
|
|
+ request.setOut_trade_no(IdFunc.getId("F"));
|
|
|
+ request.setOut_refund_no(IdFunc.getId("F"));
|
|
|
+ request.setTotal_fee(100);
|
|
|
+ request.setRefund_fee(10);
|
|
|
+ refund(request,"7616442b20a95c985ae712d72797c4c7");
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|