|
|
@@ -11,6 +11,7 @@ import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
import com.alibaba.fastjson.JSON; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
|
import com.github.binarywang.wxpay.service.WxPayService; |
|
|
import com.iformall.common.ErrorCode; |
|
|
import com.iformall.common.ErrorCode; |
|
|
import com.iformall.common.Result; |
|
|
import com.iformall.common.Result; |
|
|
import com.iformall.common.ResultData; |
|
|
import com.iformall.common.ResultData; |
|
|
@@ -18,6 +19,7 @@ import com.iformall.domain.po.WxAppinfo; |
|
|
import com.iformall.domain.po.WxPayAccount; |
|
|
import com.iformall.domain.po.WxPayAccount; |
|
|
import com.iformall.domain.po.WxPayOrder; |
|
|
import com.iformall.domain.po.WxPayOrder; |
|
|
import com.iformall.domain.po.WxRefundOrder; |
|
|
import com.iformall.domain.po.WxRefundOrder; |
|
|
|
|
|
import com.iformall.enums.EnumPayMchType; |
|
|
import com.iformall.enums.EnumPayMode; |
|
|
import com.iformall.enums.EnumPayMode; |
|
|
import com.iformall.enums.EnumPayType; |
|
|
import com.iformall.enums.EnumPayType; |
|
|
import com.iformall.enums.EnumPayWay; |
|
|
import com.iformall.enums.EnumPayWay; |
|
|
@@ -28,14 +30,17 @@ import com.iformall.mapper.WxPayAccountMapper; |
|
|
import com.iformall.mapper.WxPayOrderMapper; |
|
|
import com.iformall.mapper.WxPayOrderMapper; |
|
|
import com.iformall.mapper.WxRefundOrderMapper; |
|
|
import com.iformall.mapper.WxRefundOrderMapper; |
|
|
import com.iformall.pay.WxPay; |
|
|
import com.iformall.pay.WxPay; |
|
|
|
|
|
import com.iformall.pay.WxPayV3; |
|
|
import com.iformall.pay.WxPayment; |
|
|
import com.iformall.pay.WxPayment; |
|
|
import com.iformall.pay.WxRefundOrderP; |
|
|
import com.iformall.pay.WxRefundOrderP; |
|
|
import com.iformall.pay.WxRefundOrderSP; |
|
|
import com.iformall.pay.WxRefundOrderSP; |
|
|
import com.iformall.service.pay.service.refund.RefundPayAdapterService; |
|
|
import com.iformall.service.pay.service.refund.RefundPayAdapterService; |
|
|
import com.iformall.service.pay.service.refund.entity.RefundAdapterResult; |
|
|
import com.iformall.service.pay.service.refund.entity.RefundAdapterResult; |
|
|
import com.iformall.service.pay.service.refund.entity.RefundNotifyAdapterResult; |
|
|
import com.iformall.service.pay.service.refund.entity.RefundNotifyAdapterResult; |
|
|
|
|
|
import com.iformall.service.pay.service.refund.wx.v3.entity.V3PayRefundReq; |
|
|
import com.iformall.utils.BeanUtils; |
|
|
import com.iformall.utils.BeanUtils; |
|
|
import com.iformall.utils.CipherUtil; |
|
|
import com.iformall.utils.CipherUtil; |
|
|
|
|
|
import com.iformall.utils.MaUtil; |
|
|
import com.iformall.utils.Utility; |
|
|
import com.iformall.utils.Utility; |
|
|
import com.iformall.utils.XmlUtil; |
|
|
import com.iformall.utils.XmlUtil; |
|
|
|
|
|
|
|
|
@@ -45,192 +50,10 @@ import lombok.extern.slf4j.Slf4j; |
|
|
@Service |
|
|
@Service |
|
|
public class WxRefundV3AdapterService implements RefundPayAdapterService{ |
|
|
public class WxRefundV3AdapterService implements RefundPayAdapterService{ |
|
|
|
|
|
|
|
|
JSONObject errorRefundReqMap = JSON.parseObject("{\n" + |
|
|
|
|
|
" \"SYSTEMERROR\": {\n" + |
|
|
|
|
|
" \"detail\": \"接口返回错误\",\n" + |
|
|
|
|
|
" \"reason\": \"系统超时等\",\n" + |
|
|
|
|
|
" \"resolution\": \"请不要更换商户退款单号,请使用相同参数再次调用API。\"\n" + |
|
|
|
|
|
" },\n" + |
|
|
|
|
|
" \"BIZERR_NEED_RETRY\": {\n" + |
|
|
|
|
|
" \"detail\": \"退款业务流程错误,需要商户触发重试来解决\",\n" + |
|
|
|
|
|
" \"reason\": \"并发情况下,业务被拒绝,商户重试即可解决\",\n" + |
|
|
|
|
|
" \"resolution\": \"请不要更换商户退款单号,请使用相同参数再次调用API。\"\n" + |
|
|
|
|
|
" },\n" + |
|
|
|
|
|
" \"TRADE_OVERDUE\": {\n" + |
|
|
|
|
|
" \"detail\": \"订单已经超过退款期限\",\n" + |
|
|
|
|
|
" \"reason\": \"订单已经超过可退款的最大期限(支付后一年内可退款)\\t\",\n" + |
|
|
|
|
|
" \"resolution\": \"请选择其他方式自行退款\"\n" + |
|
|
|
|
|
" },\n" + |
|
|
|
|
|
" \"ERROR\": {\n" + |
|
|
|
|
|
" \"detail\": \"业务错误\",\n" + |
|
|
|
|
|
" \"reason\": \"申请退款业务发生错误\",\n" + |
|
|
|
|
|
" \"resolution\": \"该错误都会返回具体的错误原因,请根据实际返回做相应处理。\"\n" + |
|
|
|
|
|
" },\n" + |
|
|
|
|
|
" \"USER_ACCOUNT_ABNORMAL\": {\n" + |
|
|
|
|
|
" \"detail\": \"退款请求失败\",\n" + |
|
|
|
|
|
" \"reason\": \"用户帐号注销\",\n" + |
|
|
|
|
|
" \"resolution\": \"此状态代表退款申请失败,商户可自行处理退款。\"\n" + |
|
|
|
|
|
" },\n" + |
|
|
|
|
|
" \"INVALID_REQ_TOO_MUCH\": {\n" + |
|
|
|
|
|
" \"detail\": \"无效请求过多\",\n" + |
|
|
|
|
|
" \"reason\": \"连续错误请求数过多被系统短暂屏蔽\\t\",\n" + |
|
|
|
|
|
" \"resolution\": \"请检查业务是否正常,确认业务正常后请在1分钟后再来重试\"\n" + |
|
|
|
|
|
" },\n" + |
|
|
|
|
|
" \"NOTENOUGH\": {\n" + |
|
|
|
|
|
" \"detail\": \"余额不足\",\n" + |
|
|
|
|
|
" \"reason\": \"商户可用退款余额不足\",\n" + |
|
|
|
|
|
" \"resolution\": \"此状态代表退款申请失败,商户可根据具体的错误提示做相应的处理。\"\n" + |
|
|
|
|
|
" },\n" + |
|
|
|
|
|
" \"INVALID_TRANSACTIONID\": {\n" + |
|
|
|
|
|
" \"detail\": \"无效transaction_id\",\n" + |
|
|
|
|
|
" \"reason\": \"请求参数未按指引进行填写\",\n" + |
|
|
|
|
|
" \"resolution\": \"请求参数错误,检查原交易号是否存在或发起支付交易接口返回失败\"\n" + |
|
|
|
|
|
" },\n" + |
|
|
|
|
|
" \"PARAM_ERROR\": {\n" + |
|
|
|
|
|
" \"detail\": \"参数错误\",\n" + |
|
|
|
|
|
" \"reason\": \"请求参数未按指引进行填写\",\n" + |
|
|
|
|
|
" \"resolution\": \"请求参数错误,请重新检查再调用退款申请\"\n" + |
|
|
|
|
|
" },\n" + |
|
|
|
|
|
" \"APPID_NOT_EXIST\": {\n" + |
|
|
|
|
|
" \"detail\": \"APPID不存在\",\n" + |
|
|
|
|
|
" \"reason\": \"参数中缺少APPID\",\n" + |
|
|
|
|
|
" \"resolution\": \"请检查APPID是否正确\"\n" + |
|
|
|
|
|
" },\n" + |
|
|
|
|
|
" \"MCHID_NOT_EXIST\": {\n" + |
|
|
|
|
|
" \"detail\": \"MCHID不存在\",\n" + |
|
|
|
|
|
" \"reason\": \"参数中缺少MCHID\",\n" + |
|
|
|
|
|
" \"resolution\": \"请检查MCHID是否正确\"\n" + |
|
|
|
|
|
" },\n" + |
|
|
|
|
|
" \"REQUIRE_POST_METHOD\": {\n" + |
|
|
|
|
|
" \"detail\": \"请使用post方法\",\n" + |
|
|
|
|
|
" \"reason\": \"未使用post传递参数\",\n" + |
|
|
|
|
|
" \"resolution\": \"请检查请求参数是否通过post方法提交\"\n" + |
|
|
|
|
|
" },\n" + |
|
|
|
|
|
" \"SIGNERROR\": {\n" + |
|
|
|
|
|
" \"detail\": \"签名错误\",\n" + |
|
|
|
|
|
" \"reason\": \"参数签名结果不正确\",\n" + |
|
|
|
|
|
" \"resolution\": \"请检查签名参数和方法是否都符合签名算法要求\"\n" + |
|
|
|
|
|
" },\n" + |
|
|
|
|
|
" \"XML_FORMAT_ERROR\": {\n" + |
|
|
|
|
|
" \"detail\": \"XML格式错误\",\n" + |
|
|
|
|
|
" \"reason\": \"XML格式错误\",\n" + |
|
|
|
|
|
" \"resolution\": \"请检查XML参数格式是否正确\"\n" + |
|
|
|
|
|
" },\n" + |
|
|
|
|
|
" \"FREQUENCY_LIMITED\": {\n" + |
|
|
|
|
|
" \"detail\": \"频率限制\",\n" + |
|
|
|
|
|
" \"reason\": \"2个月之前的订单申请退款有频率限制\",\n" + |
|
|
|
|
|
" \"resolution\": \"该笔退款未受理,请降低频率后重试\"\n" + |
|
|
|
|
|
" }\n" + |
|
|
|
|
|
"}"); |
|
|
|
|
|
|
|
|
|
|
|
JSONObject errorRefundQueryMap = JSON.parseObject("{\n" + |
|
|
|
|
|
" \"SYSTEMERROR\": {\n" + |
|
|
|
|
|
" \"detail\": \"接口返回错误\",\n" + |
|
|
|
|
|
" \"reason\": \"系统超时等\",\n" + |
|
|
|
|
|
" \"resolution\": \"请不要更换商户退款单号,请使用相同参数再次调用API。\"\n" + |
|
|
|
|
|
" },\n" + |
|
|
|
|
|
" \"BIZERR_NEED_RETRY\": {\n" + |
|
|
|
|
|
" \"detail\": \"退款业务流程错误,需要商户触发重试来解决\",\n" + |
|
|
|
|
|
" \"reason\": \"并发情况下,业务被拒绝,商户重试即可解决\",\n" + |
|
|
|
|
|
" \"resolution\": \"请不要更换商户退款单号,请使用相同参数再次调用API。\"\n" + |
|
|
|
|
|
" },\n" + |
|
|
|
|
|
" \"TRADE_OVERDUE\": {\n" + |
|
|
|
|
|
" \"detail\": \"订单已经超过退款期限\",\n" + |
|
|
|
|
|
" \"reason\": \"订单已经超过可退款的最大期限(支付后一年内可退款)\\t\",\n" + |
|
|
|
|
|
" \"resolution\": \"请选择其他方式自行退款\"\n" + |
|
|
|
|
|
" },\n" + |
|
|
|
|
|
" \"ERROR\": {\n" + |
|
|
|
|
|
" \"detail\": \"业务错误\",\n" + |
|
|
|
|
|
" \"reason\": \"申请退款业务发生错误\",\n" + |
|
|
|
|
|
" \"resolution\": \"该错误都会返回具体的错误原因,请根据实际返回做相应处理。\"\n" + |
|
|
|
|
|
" },\n" + |
|
|
|
|
|
" \"USER_ACCOUNT_ABNORMAL\": {\n" + |
|
|
|
|
|
" \"detail\": \"退款请求失败\",\n" + |
|
|
|
|
|
" \"reason\": \"用户帐号注销\",\n" + |
|
|
|
|
|
" \"resolution\": \"此状态代表退款申请失败,商户可自行处理退款。\"\n" + |
|
|
|
|
|
" },\n" + |
|
|
|
|
|
" \"INVALID_REQ_TOO_MUCH\": {\n" + |
|
|
|
|
|
" \"detail\": \"无效请求过多\",\n" + |
|
|
|
|
|
" \"reason\": \"连续错误请求数过多被系统短暂屏蔽\\t\",\n" + |
|
|
|
|
|
" \"resolution\": \"请检查业务是否正常,确认业务正常后请在1分钟后再来重试\"\n" + |
|
|
|
|
|
" },\n" + |
|
|
|
|
|
" \"NOTENOUGH\": {\n" + |
|
|
|
|
|
" \"detail\": \"余额不足\",\n" + |
|
|
|
|
|
" \"reason\": \"商户可用退款余额不足\",\n" + |
|
|
|
|
|
" \"resolution\": \"此状态代表退款申请失败,商户可根据具体的错误提示做相应的处理。\"\n" + |
|
|
|
|
|
" },\n" + |
|
|
|
|
|
" \"INVALID_TRANSACTIONID\": {\n" + |
|
|
|
|
|
" \"detail\": \"无效transaction_id\",\n" + |
|
|
|
|
|
" \"reason\": \"请求参数未按指引进行填写\",\n" + |
|
|
|
|
|
" \"resolution\": \"请求参数错误,检查原交易号是否存在或发起支付交易接口返回失败\"\n" + |
|
|
|
|
|
" },\n" + |
|
|
|
|
|
" \"PARAM_ERROR\": {\n" + |
|
|
|
|
|
" \"detail\": \"参数错误\",\n" + |
|
|
|
|
|
" \"reason\": \"请求参数未按指引进行填写\",\n" + |
|
|
|
|
|
" \"resolution\": \"请求参数错误,请重新检查再调用退款申请\"\n" + |
|
|
|
|
|
" },\n" + |
|
|
|
|
|
" \"APPID_NOT_EXIST\": {\n" + |
|
|
|
|
|
" \"detail\": \"APPID不存在\",\n" + |
|
|
|
|
|
" \"reason\": \"参数中缺少APPID\",\n" + |
|
|
|
|
|
" \"resolution\": \"请检查APPID是否正确\"\n" + |
|
|
|
|
|
" },\n" + |
|
|
|
|
|
" \"MCHID_NOT_EXIST\": {\n" + |
|
|
|
|
|
" \"detail\": \"MCHID不存在\",\n" + |
|
|
|
|
|
" \"reason\": \"参数中缺少MCHID\",\n" + |
|
|
|
|
|
" \"resolution\": \"请检查MCHID是否正确\"\n" + |
|
|
|
|
|
" },\n" + |
|
|
|
|
|
" \"REQUIRE_POST_METHOD\": {\n" + |
|
|
|
|
|
" \"detail\": \"请使用post方法\",\n" + |
|
|
|
|
|
" \"reason\": \"未使用post传递参数\",\n" + |
|
|
|
|
|
" \"resolution\": \"请检查请求参数是否通过post方法提交\"\n" + |
|
|
|
|
|
" },\n" + |
|
|
|
|
|
" \"SIGNERROR\": {\n" + |
|
|
|
|
|
" \"detail\": \"签名错误\",\n" + |
|
|
|
|
|
" \"reason\": \"参数签名结果不正确\",\n" + |
|
|
|
|
|
" \"resolution\": \"请检查签名参数和方法是否都符合签名算法要求\"\n" + |
|
|
|
|
|
" },\n" + |
|
|
|
|
|
" \"XML_FORMAT_ERROR\": {\n" + |
|
|
|
|
|
" \"detail\": \"XML格式错误\",\n" + |
|
|
|
|
|
" \"reason\": \"XML格式错误\",\n" + |
|
|
|
|
|
" \"resolution\": \"请检查XML参数格式是否正确\"\n" + |
|
|
|
|
|
" },\n" + |
|
|
|
|
|
" \"FREQUENCY_LIMITED\": {\n" + |
|
|
|
|
|
" \"detail\": \"频率限制\",\n" + |
|
|
|
|
|
" \"reason\": \"2个月之前的订单申请退款有频率限制\",\n" + |
|
|
|
|
|
" \"resolution\": \"该笔退款未受理,请降低频率后重试\"\n" + |
|
|
|
|
|
" }\n" + |
|
|
|
|
|
"}"); |
|
|
|
|
|
|
|
|
|
|
|
private WxRefundOrderP generateWxRefundOrderP(WxPayAccount payAccount,WxAppinfo appInfo,WxRefundOrder record,WxPayOrder payOrder,EnumPayType payType) { |
|
|
|
|
|
String noncestr = Utility.generate32UUID(); |
|
|
|
|
|
WxRefundOrderP wxRefundOrderP = new WxRefundOrderP(); |
|
|
|
|
|
wxRefundOrderP.setAppid(appInfo.getAppId()); |
|
|
|
|
|
wxRefundOrderP.setMch_id(payAccount.getMchId()); |
|
|
|
|
|
wxRefundOrderP.setNonce_str(noncestr); |
|
|
|
|
|
// 微信内部订单号 |
|
|
|
|
|
if (record.getTransactionId() != null) |
|
|
|
|
|
wxRefundOrderP.setTransaction_id(record.getTransactionId()); |
|
|
|
|
|
// 支付订单号 |
|
|
|
|
|
wxRefundOrderP.setOut_trade_no(payOrder.getPayOrderNo()); |
|
|
|
|
|
// 退款支付订单号 |
|
|
|
|
|
wxRefundOrderP.setOut_refund_no(String.valueOf(record.getId())); |
|
|
|
|
|
wxRefundOrderP.setTotal_fee(record.getTotalFee()); |
|
|
|
|
|
wxRefundOrderP.setRefund_fee(record.getRefundFee()); |
|
|
|
|
|
if(null != payType) { |
|
|
|
|
|
if (payType == EnumPayType.PAY_B_REFUND) { |
|
|
|
|
|
wxRefundOrderP.setRefund_desc("B端商户退款"); |
|
|
|
|
|
} else if (payType == EnumPayType.PAY_ADMIN_REFUND) { |
|
|
|
|
|
wxRefundOrderP.setRefund_desc("管理端商户退款"); |
|
|
|
|
|
} else if (payType == EnumPayType.PAY_AUTO_REFUND) { |
|
|
|
|
|
wxRefundOrderP.setRefund_desc("超期自动退款"); |
|
|
|
|
|
} else { |
|
|
|
|
|
wxRefundOrderP.setRefund_desc("用户自己退款"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
wxRefundOrderP.setNotify_url(payAccount.getRefundNotifyUrl()); |
|
|
|
|
|
return wxRefundOrderP; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
MaUtil maUtil; |
|
|
|
|
|
|
|
|
private RefundAdapterResult getReusltFromp(String response,WxRefundOrder record,WxPayOrder payOrder) throws MallinkException{ |
|
|
private RefundAdapterResult getReusltFromp(String response,WxRefundOrder record,WxPayOrder payOrder) throws MallinkException{ |
|
|
Map<String, String> returnMap = WxPayment.xmlToMap(response); |
|
|
Map<String, String> returnMap = WxPayment.xmlToMap(response); |
|
|
String result_no = returnMap.get("result_code"); |
|
|
String result_no = returnMap.get("result_code"); |
|
|
@@ -270,39 +93,6 @@ public class WxRefundV3AdapterService implements RefundPayAdapterService{ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private WxRefundOrderSP generateWxRefundOrderSP(WxPayAccount payAccount,WxAppinfo appInfo,WxRefundOrder record,WxPayOrder payOrder,EnumPayType payType) { |
|
|
|
|
|
String noncestr = Utility.generate32UUID(); |
|
|
|
|
|
WxRefundOrderSP wxRefundOrderSP = new WxRefundOrderSP(); |
|
|
|
|
|
wxRefundOrderSP.setAppid(appInfo.getParentAppId()); |
|
|
|
|
|
wxRefundOrderSP.setSub_appid(appInfo.getAppId()); |
|
|
|
|
|
wxRefundOrderSP.setMch_id(payAccount.getMchId()); |
|
|
|
|
|
wxRefundOrderSP.setSub_mch_id(payAccount.getSubMchId()); |
|
|
|
|
|
wxRefundOrderSP.setNonce_str(noncestr); |
|
|
|
|
|
// 微信内部订单号 |
|
|
|
|
|
if (record.getTransactionId() != null) |
|
|
|
|
|
wxRefundOrderSP.setTransaction_id(record.getTransactionId()); |
|
|
|
|
|
// 支付订单号 |
|
|
|
|
|
wxRefundOrderSP.setOut_trade_no(payOrder.getPayOrderNo()); |
|
|
|
|
|
// 退款支付订单号 |
|
|
|
|
|
wxRefundOrderSP.setOut_refund_no(String.valueOf(record.getId())); |
|
|
|
|
|
wxRefundOrderSP.setTotal_fee(record.getTotalFee()); |
|
|
|
|
|
wxRefundOrderSP.setRefund_fee(record.getRefundFee()); |
|
|
|
|
|
if(null != payType) { |
|
|
|
|
|
if (payType == EnumPayType.PAY_B_REFUND) { |
|
|
|
|
|
wxRefundOrderSP.setRefund_desc("B端商户退款"); |
|
|
|
|
|
} else if (payType == EnumPayType.PAY_ADMIN_REFUND) { |
|
|
|
|
|
wxRefundOrderSP.setRefund_desc("管理端商户退款"); |
|
|
|
|
|
} else if (payType == EnumPayType.PAY_AUTO_REFUND) { |
|
|
|
|
|
wxRefundOrderSP.setRefund_desc("超期自动退款"); |
|
|
|
|
|
} else { |
|
|
|
|
|
wxRefundOrderSP.setRefund_desc("用户自己退款"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
wxRefundOrderSP.setNotify_url(payAccount.getRefundNotifyUrl()); |
|
|
|
|
|
wxRefundOrderSP.setSign_type("HMAC-SHA256"); |
|
|
|
|
|
return wxRefundOrderSP; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private RefundAdapterResult getResultFromSp(String response,WxRefundOrder record,WxPayOrder payOrder) { |
|
|
private RefundAdapterResult getResultFromSp(String response,WxRefundOrder record,WxPayOrder payOrder) { |
|
|
Map<String, String> returnMap = WxPayment.xmlToMap(response); |
|
|
Map<String, String> returnMap = WxPayment.xmlToMap(response); |
|
|
String result_no = returnMap.get("result_code"); |
|
|
String result_no = returnMap.get("result_code"); |
|
|
@@ -341,64 +131,28 @@ public class WxRefundV3AdapterService implements RefundPayAdapterService{ |
|
|
return new RefundAdapterResult(false,EnumRefundStatus.REFUND_REQ_FAIL.getCode(),errMsg,returnMap); |
|
|
return new RefundAdapterResult(false,EnumRefundStatus.REFUND_REQ_FAIL.getCode(),errMsg,returnMap); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private V3PayRefundReq getReq(WxPayAccount payAccount,WxAppinfo appInfo,WxRefundOrder record,WxPayOrder payOrder,EnumPayType payType) { |
|
|
|
|
|
V3PayRefundReq req = new V3PayRefundReq(); |
|
|
|
|
|
if (payAccount.getMchType() == EnumPayMchType.DIRECT.getCode()) { |
|
|
|
|
|
req.setSub_mchid(getMerchantUid(record,composeOrder.getSingleOrder())); |
|
|
|
|
|
//总分 |
|
|
|
|
|
}else if (payAccount.getMchType() == EnumPayMchType.TOTAL.getCode()) { |
|
|
|
|
|
req.setSub_mchid(payAccount.getSubMchId()); |
|
|
|
|
|
}else { |
|
|
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"当前支付模式非法"); |
|
|
|
|
|
} |
|
|
|
|
|
req.setSub_mchid(sub_mchid); |
|
|
|
|
|
} |
|
|
@Override |
|
|
@Override |
|
|
public RefundAdapterResult refund(WxPayAccount payAccount,WxAppinfo appInfo,WxRefundOrder record,WxPayOrder payOrder,EnumPayType payType) { |
|
|
public RefundAdapterResult refund(WxPayAccount payAccount,WxAppinfo appInfo,WxRefundOrder record,WxPayOrder payOrder,EnumPayType payType) { |
|
|
if (StringUtils.isBlank(payAccount.getApiKey())) { |
|
|
|
|
|
log.error("支付密钥为空"); |
|
|
|
|
|
throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND.getCode(), "支付密钥为空,请联系商城管理员"); |
|
|
|
|
|
} |
|
|
|
|
|
if (StringUtils.isBlank(payAccount.getCertPath())) { |
|
|
|
|
|
log.error("证书路径为空"); |
|
|
|
|
|
throw new MallinkException(ErrorCode.CERT_PATH_NOT_FOUND.getCode(), "证书路径为空,请联系商城管理员"); |
|
|
|
|
|
} |
|
|
|
|
|
if (!Utility.isFileExist(payAccount.getCertPath())) { |
|
|
|
|
|
log.error("证书文件不存在"); |
|
|
|
|
|
throw new MallinkException(ErrorCode.CERT_PATH_NOT_FOUND.getCode(), "证书文件不存在,请联系商城管理员"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 实际支付 |
|
|
|
|
|
// 向微信提交退款申请 |
|
|
// 向微信提交退款申请 |
|
|
if (payAccount.getType() == EnumPayMode.MCH.getCode()) { |
|
|
if (payAccount.getType() == EnumPayMode.MCH.getCode()) { |
|
|
// 普通商户模式 |
|
|
|
|
|
WxRefundOrderP wxRefundOrderP = generateWxRefundOrderP(payAccount, appInfo, record, payOrder, payType); |
|
|
|
|
|
|
|
|
|
|
|
Map signMap = null; |
|
|
|
|
|
try { |
|
|
|
|
|
signMap = BeanUtils.toStringMap(wxRefundOrderP); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("退款命令生辰: " + e.getMessage()); |
|
|
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "退款签名异常"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String signAgent = WxPayment.createSign(signMap, payAccount.getApiKey()); |
|
|
|
|
|
signMap.put("sign", signAgent); |
|
|
|
|
|
String response = null; |
|
|
|
|
|
try { |
|
|
|
|
|
response = WxPay.orderRefund(signMap, payAccount.getCertPath(), payAccount.getMchId()); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("退款异常: " + e.getMessage()); |
|
|
|
|
|
throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), "退款异常"); |
|
|
|
|
|
} |
|
|
|
|
|
log.info("微信退款订单:" + wxRefundOrderP.toString() + ", response: " + response.toString()); |
|
|
|
|
|
return getReusltFromp(response, record, payOrder); |
|
|
|
|
|
} else { |
|
|
} else { |
|
|
// 服务商模式 |
|
|
// 服务商模式 |
|
|
WxRefundOrderSP wxRefundOrderSP = generateWxRefundOrderSP(payAccount, appInfo, record, payOrder, payType); |
|
|
|
|
|
|
|
|
|
|
|
Map signMap = null; |
|
|
|
|
|
try { |
|
|
|
|
|
signMap = BeanUtils.toStringMap(wxRefundOrderSP); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("退款命令生成: " + e.getMessage()); |
|
|
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "退款签名异常"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String signAgent = WxPayment.createSignHMAC(signMap, payAccount.getApiKey()); |
|
|
|
|
|
signMap.put("sign", signAgent); |
|
|
|
|
|
|
|
|
WxPayService payService = maUtil.getWxPayService(appInfo, payAccount); |
|
|
String response = null; |
|
|
String response = null; |
|
|
try { |
|
|
try { |
|
|
response = WxPay.orderRefund(signMap, payAccount.getCertPath(), payAccount.getMchId()); |
|
|
|
|
|
|
|
|
response = WxPayV3.payCommonRefund(payService, getReq(payAccount, appInfo, record, payOrder, payType)); |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
log.error("退款异常: " + e.getMessage()); |
|
|
log.error("退款异常: " + e.getMessage()); |
|
|
throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), "退款异常"); |
|
|
throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), "退款异常"); |
|
|
|