继续上篇
@Autowired
WeixinMiniProgramPayProperties weixinPayProperties;
@Override
public Map refund(String logKey, String refundOrderNumber, String transactionId, String openId, String fee) throws Exception
{
//1.参数封装
Map param = new HashMap();
param.put("appid", weixinPayProperties.getAppid());// 公众账号ID
param.put("mch_id", weixinPayProperties.getMchId());// 商户
param.put("nonce_str", WXPayUtil.generateNonceStr());// 随机字符串
param.put("transaction_id", transactionId);// 微信返回的交易订单号param.put("out_trade_no", orderNumber);
//
param.put("out_refund_no", refundOrderNumber);
param.put("total_fee", fee); // 金额(分)
param.put("refund_fee", fee); // 金额(分)
// param.put("notify_url", weixinPayProperties.getRefundUrl());
logger.info(logKey + " weixinPayProperties" + weixinPayProperties);
String sign = WXPayUtil.generateSignature(param, weixinPayProperties.getPartnerkey());
param.put("sign", sign);
logger.info(logKey + " weixinService#refund:" + param);
// HttpClient httpClient = new HttpClient(weixinPayProperties.getRefundUrl());
// httpClient.setHttps(true);
// httpClient.setXmlParam(xml2String(param));
// httpClient.post();
// String xmlResult = httpClient.getContent();
// Map<String, String> mapResult = WXPayUtil.xmlToMap(xmlResult);
String xmlResult = WXHttpCertUtils.doPost(weixinPayProperties.getWechatRefundUrl(), xml2String(param));
logger.info(logKey + " weixinService#refund.wxpay.mp.xml.result:" + xmlResult);
Map<String, String> mapResult = WXPayUtil.xmlToMap(xmlResult);
logger.info(logKey + " weixinService#refund.wxpay.mp.map.result:" + xmlResult);
Map<String, String> result = new HashMap<>();
result.put("code", "500");
result.put("message", "系统错误");
if("SUCCESS".equalsIgnoreCase(mapResult.get("result_code")))
{
result.put("code", "200");
result.put("message", "支付成功");
}
// 转帐失败
else if ("FAIL".equalsIgnoreCase(mapResult.get("result_code")))
{
result.put("code", "500");
// 系统错误需要重试[请先调用查询接口,查看此次付款结果,如结果为不明确状态(如订单号不存在),请务必使用原商户订单号进行重试。]
if ("SYSTEMERROR".equalsIgnoreCase(mapResult.get("err_code")))
{
// result.put("message", "支付成功");
}
// 金额超限
else if("AMOUNT_LIMIT".equalsIgnoreCase(mapResult.get("err_code")))
{
result.put("message", "金额超限");
}
// 余额不足
else if("NOTENOUGH".equalsIgnoreCase(mapResult.get("err_code")))
{
// result.put("message", "支付成功");
}
// 超过频率限制,请稍后再试。
else if("FREQ_LIMIT".equalsIgnoreCase(mapResult.get("err_code")))
{
result.put("message", "超过频率限制,请稍后再试。");
}
// 已经达到今日付款总额上限/已达到付款给此用户额度上限
else if("MONEY_LIMIT".equalsIgnoreCase(mapResult.get("err_code")))
{
result.put("message", "已经达到今日付款总额上限");
}
// 无法给非实名用户付款
else if ("V2_ACCOUNT_SIMPLE_BAN".equalsIgnoreCase(mapResult.get("err_code")))
{
result.put("message", "无法给非实名用户付款");
}
// 该用户今日付款次数超过限制,如有需要请登录微信支付商户平台更改API安全配置
else if("SENDNUM_LIMIT".equalsIgnoreCase(mapResult.get("err_code")))
{
result.put("message", "今日付款次数超过限制");
}
}
else
{
// 系统错误
result.put("code", "500");
result.put("message", "系统错误");
}
logger.info(logKey + " weixinService#refund.wxpay.mp.result:" + mapResult);
return result;
}
网友评论