...
|
...
|
@@ -9,6 +9,7 @@ import com.yohoufo.common.utils.TimeUtils; |
|
|
import com.yohoufo.common.utils.WXUtils;
|
|
|
import com.yohoufo.order.common.Payment;
|
|
|
import com.yohoufo.order.config.WeixinPayConfig;
|
|
|
import com.yohoufo.order.constants.RefundContant;
|
|
|
import com.yohoufo.order.model.OrderInfo;
|
|
|
import com.yohoufo.order.model.PayQueryBo;
|
|
|
import com.yohoufo.order.model.PayRefundBo;
|
...
|
...
|
@@ -208,8 +209,66 @@ public abstract class AbstractWeixinPayService extends AbstractPayService { |
|
|
}
|
|
|
|
|
|
|
|
|
public PayRefundBo refundOpenApi(PayRefundBo refundBo){
|
|
|
return null;
|
|
|
public PayRefundBo refundOpenApi(PayRefundBo refundBo){
|
|
|
Map<String, String> queryParams = buildRefundParams(refundBo);
|
|
|
String requestXml = WXUtils.createWXPayXml(queryParams);
|
|
|
String respXml = sendRefundRequest(String.valueOf(refundBo.getPayOrderCode()), requestXml);
|
|
|
return refundConvert(respXml, refundBo);
|
|
|
}
|
|
|
|
|
|
|
|
|
private PayRefundBo refundConvert(String responseXml, PayRefundBo bo) {
|
|
|
//PayRefundBo bo = new PayRefundBo();
|
|
|
if (StringUtils.isEmpty(responseXml)) {
|
|
|
bo.setRefundStatus(RefundContant.PAYMENT_REFUND_RESULTCODE_REQERR);
|
|
|
bo.setRefundMsg("退款申请请求失败");
|
|
|
return bo;
|
|
|
}
|
|
|
|
|
|
Map<String, String> reponseMap = WXUtils.parseWXPayXml(responseXml);
|
|
|
if(!"SUCCESS".equals(reponseMap.get("return_code"))) {
|
|
|
bo.setRefundStatus(RefundContant.PAYMENT_REFUND_RESULTCODE_REQERR);
|
|
|
bo.setRefundMsg(reponseMap.get("return_msg"));
|
|
|
return bo;
|
|
|
}
|
|
|
if(!"SUCCESS".equals(reponseMap.get("result_code"))) {
|
|
|
bo.setRefundStatus(RefundContant.PAYMENT_REFUND_RESULTCODE_FAIL);
|
|
|
bo.setRefundMsg(reponseMap.get("err_code") + ": " + reponseMap.get("err_code_des"));
|
|
|
return bo;
|
|
|
}
|
|
|
|
|
|
bo.setRefundStatus(RefundContant.PAYMENT_REFUND_RESULTCODE_SUCCESS);
|
|
|
bo.setSerialNo(reponseMap.get("refund_id"));
|
|
|
bo.setRefundMsg("退款成功");
|
|
|
|
|
|
return bo;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 退款请求
|
|
|
* @param orderCode
|
|
|
* @param requestXml
|
|
|
* @return
|
|
|
*/
|
|
|
private String sendRefundRequest(String tradeNo, String requestXml) {
|
|
|
logger.info("WeixinRefunder request tradeNo: {}, request: {}", tradeNo, requestXml);
|
|
|
|
|
|
String respXml = "";
|
|
|
HttpClient httpClient = getSslHttpClient();
|
|
|
if(httpClient == null) {
|
|
|
logger.error("init weixin ssl httpclient faild, unable refund weixinpay");
|
|
|
return respXml;
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
respXml = httpClient.post(WeixinPayConfig.WEIXIN_PAY_REFUND_URL, requestXml);
|
|
|
} catch (Exception e) {
|
|
|
logger.error("WeixinRefunder request failed, orderCode:{}, ex: {}", tradeNo, e.getMessage());
|
|
|
}
|
|
|
|
|
|
logger.info("WeixinRefunder response: {}", respXml);
|
|
|
return respXml;
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
@@ -234,6 +293,29 @@ public abstract class AbstractWeixinPayService extends AbstractPayService { |
|
|
return prepayJson;
|
|
|
}
|
|
|
|
|
|
private Map<String, String> buildRefundParams(PayRefundBo refundBo) {
|
|
|
|
|
|
Map<String, String> paramMap = new HashMap<String, String>();
|
|
|
paramMap.put("appid", getAppId());
|
|
|
paramMap.put("mch_id", getMchId());
|
|
|
paramMap.put("nonce_str", WXUtils.getNonceStr());
|
|
|
paramMap.put("out_trade_no", WeixinPayConfig.WECHAT_TRADE_NO_PREFIX + refundBo.getPayOrderCode());
|
|
|
paramMap.put("out_refund_no", refundBo.getRefundOrderCode());
|
|
|
|
|
|
//String totalFee = String.valueOf((int)YHMath.mul(amount, 100)); //微信金额必须以分为单位,且不能包含小数点
|
|
|
paramMap.put("total_fee", String.valueOf((int)YHMath.mul(refundBo.getOrderTotalFee(), 100)));
|
|
|
paramMap.put("refund_fee", String.valueOf((int)YHMath.mul(refundBo.getAmount(), 100)));
|
|
|
paramMap.put("op_user_id", getMchId());
|
|
|
|
|
|
//签名
|
|
|
//md5签名
|
|
|
String sign = WXUtils.signMd5(paramMap, getMchKey());
|
|
|
paramMap.put(WeixinPayConfig.ApiConstants.SIGN, sign);
|
|
|
|
|
|
return paramMap;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取预支付的返回数据
|
...
|
...
|
|