Commit 61ac241b authored by xiaoyu's avatar xiaoyu
Browse files

微信V3接口退款

parent 072aa10c
...@@ -95,19 +95,13 @@ public class WxpayRefundService extends AbstractRefundService { ...@@ -95,19 +95,13 @@ public class WxpayRefundService extends AbstractRefundService {
amountJson.put("refund", refundOrder.getRefundAmount());// 退款金额 amountJson.put("refund", refundOrder.getRefundAmount());// 退款金额
amountJson.put("total", payOrder.getAmount());// 订单总金额 amountJson.put("total", payOrder.getAmount());// 订单总金额
amountJson.put("currency", "CNY");// 币种 amountJson.put("currency", "CNY");// 币种
reqJSON.put("amount", amountJson.toJSONString()); reqJSON.put("amount", amountJson);
WxPayService wxPayService = mchAppConfigContext.getWxServiceWrapper().getWxPayService(); WxPayService wxPayService = mchAppConfigContext.getWxServiceWrapper().getWxPayService();
setCretPath(mchAppConfigContext, wxPayService); // 证书路径 setCretPath(mchAppConfigContext, wxPayService); // 证书路径
if(mchAppConfigContext.isIsvsubMch()){ // 特约商户 if(mchAppConfigContext.isIsvsubMch()){ // 特约商户
WxpayIsvsubMchParams isvsubMchParams = mchAppConfigContext.getIsvsubMchParamsByIfCode(getIfCode(), WxpayIsvsubMchParams.class); WxpayIsvsubMchParams isvsubMchParams = mchAppConfigContext.getIsvsubMchParamsByIfCode(getIfCode(), WxpayIsvsubMchParams.class);
reqJSON.put("sp_appid", wxPayService.getConfig().getAppId());
reqJSON.put("sp_mchid", wxPayService.getConfig().getMchId());
reqJSON.put("sub_mchid", isvsubMchParams.getSubMchId()); reqJSON.put("sub_mchid", isvsubMchParams.getSubMchId());
reqJSON.put("sub_appid", isvsubMchParams.getSubMchAppId());
}else { // 普通商户
reqJSON.put("appid", wxPayService.getConfig().getAppId());
reqJSON.put("mchid", wxPayService.getConfig().getMchId());
} }
JSONObject resultJSON = WxpayV3Util.refundV3(reqJSON, mchAppConfigContext.getWxServiceWrapper().getWxPayService().getConfig()); JSONObject resultJSON = WxpayV3Util.refundV3(reqJSON, mchAppConfigContext.getWxServiceWrapper().getWxPayService().getConfig());
...@@ -116,6 +110,10 @@ public class WxpayRefundService extends AbstractRefundService { ...@@ -116,6 +110,10 @@ public class WxpayRefundService extends AbstractRefundService {
String refundId = resultJSON.getString("refund_id"); String refundId = resultJSON.getString("refund_id");
channelRetMsg.setChannelState(ChannelRetMsg.ChannelState.CONFIRM_SUCCESS); channelRetMsg.setChannelState(ChannelRetMsg.ChannelState.CONFIRM_SUCCESS);
channelRetMsg.setChannelOrderId(refundId); channelRetMsg.setChannelOrderId(refundId);
}else if ("PROCESSING".equals(status)){ // 退款处理中
String refundId = resultJSON.getString("refund_id");
channelRetMsg.setChannelState(ChannelRetMsg.ChannelState.WAITING);
channelRetMsg.setChannelOrderId(refundId);
}else{ }else{
channelRetMsg.setChannelState(ChannelRetMsg.ChannelState.CONFIRM_FAIL); channelRetMsg.setChannelState(ChannelRetMsg.ChannelState.CONFIRM_FAIL);
channelRetMsg.setChannelErrMsg(status); channelRetMsg.setChannelErrMsg(status);
...@@ -157,7 +155,14 @@ public class WxpayRefundService extends AbstractRefundService { ...@@ -157,7 +155,14 @@ public class WxpayRefundService extends AbstractRefundService {
}else if (CS.PAY_IF_VERSION.WX_V3.equals(mchAppConfigContext.getWxServiceWrapper().getApiVersion())) { //V3 }else if (CS.PAY_IF_VERSION.WX_V3.equals(mchAppConfigContext.getWxServiceWrapper().getApiVersion())) { //V3
WxPayService wxPayService = mchAppConfigContext.getWxServiceWrapper().getWxPayService(); WxPayService wxPayService = mchAppConfigContext.getWxServiceWrapper().getWxPayService();
setCretPath(mchAppConfigContext, wxPayService); // 证书路径 setCretPath(mchAppConfigContext, wxPayService); // 证书路径
JSONObject resultJSON = WxpayV3Util.refundQueryV3(refundOrder.getRefundOrderId(), wxPayService.getConfig()); JSONObject resultJSON = null;
if (mchAppConfigContext.isIsvsubMch()) {
WxpayIsvsubMchParams isvsubMchParams = mchAppConfigContext.getIsvsubMchParamsByIfCode(getIfCode(), WxpayIsvsubMchParams.class);
wxPayService.getConfig().setSubMchId(isvsubMchParams.getSubMchId());
resultJSON = WxpayV3Util.refundQueryV3Isv(refundOrder.getRefundOrderId(), wxPayService.getConfig());
}else {
resultJSON = WxpayV3Util.refundQueryV3(refundOrder.getRefundOrderId(), wxPayService.getConfig());
}
String status = resultJSON.getString("status"); String status = resultJSON.getString("status");
if("SUCCESS".equals(status)){ // 退款成功 if("SUCCESS".equals(status)){ // 退款成功
channelRetMsg.setChannelState(ChannelRetMsg.ChannelState.CONFIRM_SUCCESS); channelRetMsg.setChannelState(ChannelRetMsg.ChannelState.CONFIRM_SUCCESS);
......
...@@ -94,6 +94,12 @@ public class WxpayV3Util { ...@@ -94,6 +94,12 @@ public class WxpayV3Util {
return JSON.parseObject(response); return JSON.parseObject(response);
} }
public static JSONObject refundQueryV3Isv(String refundOrderId, WxPayConfig wxPayConfig) throws WxPayException {
String url = String.format("%s/v3/refund/domestic/refunds/%s?sub_mchid=%s", PAY_BASE_URL, refundOrderId, wxPayConfig.getSubMchId());
String response = getV3(url, wxPayConfig);
return JSON.parseObject(response);
}
public static String postV3(String url, String requestStr, WxPayConfig wxPayConfig) throws WxPayException { public static String postV3(String url, String requestStr, WxPayConfig wxPayConfig) throws WxPayException {
CloseableHttpClient httpClient = createApiV3HttpClient(wxPayConfig); CloseableHttpClient httpClient = createApiV3HttpClient(wxPayConfig);
HttpPost httpPost = createHttpPost(url, requestStr); HttpPost httpPost = createHttpPost(url, requestStr);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment