提交 61ac241b 编写于 作者: X xiaoyu

微信V3接口退款

上级 072aa10c
......@@ -95,19 +95,13 @@ public class WxpayRefundService extends AbstractRefundService {
amountJson.put("refund", refundOrder.getRefundAmount());// 退款金额
amountJson.put("total", payOrder.getAmount());// 订单总金额
amountJson.put("currency", "CNY");// 币种
reqJSON.put("amount", amountJson.toJSONString());
reqJSON.put("amount", amountJson);
WxPayService wxPayService = mchAppConfigContext.getWxServiceWrapper().getWxPayService();
setCretPath(mchAppConfigContext, wxPayService); // 证书路径
if(mchAppConfigContext.isIsvsubMch()){ // 特约商户
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_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());
......@@ -116,6 +110,10 @@ public class WxpayRefundService extends AbstractRefundService {
String refundId = resultJSON.getString("refund_id");
channelRetMsg.setChannelState(ChannelRetMsg.ChannelState.CONFIRM_SUCCESS);
channelRetMsg.setChannelOrderId(refundId);
}else if ("PROCESSING".equals(status)){ // 退款处理中
String refundId = resultJSON.getString("refund_id");
channelRetMsg.setChannelState(ChannelRetMsg.ChannelState.WAITING);
channelRetMsg.setChannelOrderId(refundId);
}else{
channelRetMsg.setChannelState(ChannelRetMsg.ChannelState.CONFIRM_FAIL);
channelRetMsg.setChannelErrMsg(status);
......@@ -157,7 +155,14 @@ public class WxpayRefundService extends AbstractRefundService {
}else if (CS.PAY_IF_VERSION.WX_V3.equals(mchAppConfigContext.getWxServiceWrapper().getApiVersion())) { //V3
WxPayService wxPayService = mchAppConfigContext.getWxServiceWrapper().getWxPayService();
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");
if("SUCCESS".equals(status)){ // 退款成功
channelRetMsg.setChannelState(ChannelRetMsg.ChannelState.CONFIRM_SUCCESS);
......
......@@ -94,6 +94,12 @@ public class WxpayV3Util {
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 {
CloseableHttpClient httpClient = createApiV3HttpClient(wxPayConfig);
HttpPost httpPost = createHttpPost(url, requestStr);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册