记得上下班打卡 | git大法好,push需谨慎

Commit bdc3454b authored by anjiabin's avatar anjiabin

修改redis的退款相关id获取

parent cddb2f87
......@@ -68,7 +68,7 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
new Object[]{code, refundCode, orderRefundCode, price, reason, notifyUrl, paymentType, nowTime, nowTime},
DragonConstant.MysqlRedisQueueEnum.DRAGON_REFUND_KEY.getCode()
);
dataUtils.setRefundNotifyUrl(DragonConstant.REFUND_REDIS_KET + orderRefundCode, notifyUrl);
dataUtils.setRefundNotifyUrl(orderRefundCode, notifyUrl);
DragonRefundChannelDto dto = null;
String localWePayCallBackUrl = url + "/refund/callBack/wepay";
if (insertResult) {
......@@ -94,32 +94,37 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
case DragonConstant.REFUND_TYPE_JS_WEPAY:
dto = weyPayRefund(code, orderRefundCode, code, reason, price, priceTotal, paymentId, paymentType, localWePayCallBackUrl, nowTime);
break;
case DragonConstant.REFUND_TYPE_APPLET_WEPAY:
dto = weyPayRefund(code, orderRefundCode, code, reason, price, priceTotal, paymentId, paymentType, localWePayCallBackUrl, nowTime);
break;
}
if (dto.getResult().equalsIgnoreCase("refunding")) {
log.info("");
log.info("dto = " + JSON.toJSONString(dto));
if (dto == null) {
return ResponseDto.failure("退款失败:参数异常");
} else if (dto.getResult().equalsIgnoreCase("refunding")) {
} else if (dto.getResult().equalsIgnoreCase("refunded")) {
//调用回调
log.info("");
} else if (dto.getResult().equalsIgnoreCase("error")) {
//调用回调
log.error("");
return ResponseDto.failure("退款失败:" + dto.getMessage());
} else if (dto.getResult().equalsIgnoreCase("exception")) {
log.error("");
}
DragonRefundAppDto refundAppDto = new DragonRefundAppDto();
refundAppDto.setOrderCode(orderCode);
refundAppDto.setCode(code);
refundAppDto.setOrderRefundCode(orderRefundCode);
refundAppDto.setRefundCode(refundCode);
log.info("refundAppDto = " + JSON.toJSONString(refundAppDto));
return ResponseDto.success(refundAppDto);
} else {
return ResponseDto.failure("退款失败");
}
} catch (Exception e) {
e.printStackTrace();
log.error("");
log.info("orderCode = " + orderCode + "", e);
return ResponseDto.failure("退款失败:" + e.getMessage());
}
}
......@@ -155,7 +160,7 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
String sign = PayWepayUtils.getInstance().createSign(parameters);
parameters.put("sign", sign);
String data = PayWepayUtils.getInstance().getRequestXml(parameters);
log.debug("XMLSTRING = " + data);
String refundError = "";
try {
HttpPost httpost = new HttpPost("https://api.mch.weixin.qq.com/secapi/pay/refund");
httpost.setEntity(new StringEntity(data, "UTF-8"));
......@@ -164,20 +169,18 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
HttpEntity entity = response.getEntity();
entity.getContent();
String jsonStr = EntityUtils.toString(entity, "UTF-8");
log.debug("JSONSTR = " + jsonStr);
log.info("JSONSTR = " + jsonStr);
WePayRefundReturnDto wePayRefundReturnDto = XmlUtil.toBean(jsonStr, WePayRefundReturnDto.class);
if (wePayRefundReturnDto.getErrCodeDes() != null) {
channelDto.setResult("error");
channelDto.setMessage(paymentType + " refund error: " + wePayRefundReturnDto.getErrCodeDes());
channelDto.setMessage(wePayRefundReturnDto.getErrCodeDes());
contentDto.setRequest(data);
contentDto.setResponse(jsonStr);
channelDto.setContent(contentDto);
return channelDto;
}
log.debug("BEAN = " + wePayRefundReturnDto);
if (!wePayRefundReturnDto.getReturnCode().equalsIgnoreCase("SUCCESS") || wePayRefundReturnDto.getReturnCode() == null) {
try {
String refundError = "";
refundStatus = DragonConstant.RefundStatusEnum.STATUS_ERROR.getCode();
if (null == wePayRefundReturnDto.getReturnMsg()) {
refundError = "退款失败,原因未知";
......@@ -202,7 +205,7 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
return channelDto;
}
channelDto.setResult("error");
channelDto.setMessage(paymentType + " refund error: ");
channelDto.setMessage(refundError);
contentDto.setRequest(data);
contentDto.setResponse(jsonStr);
channelDto.setContent(contentDto);
......@@ -261,6 +264,7 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
RefundContentDto contentDto = new RefundContentDto();
AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();//创建API对应的request类
try {
String refundError = "";
request.setBizContent("{" +
"\"out_trade_no\":\"" + code + "\"," +
"\"trade_no\":\"" + paymentId + "\"," +
......@@ -268,9 +272,8 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
"\"refund_reason\":\"" + reason + "\"," +
"\"refund_amount\":\"" + price.doubleValue() + "\"}"); //设置业务参数
AlipayTradeRefundResponse response = PayAlipayUtils.getInstance().getHttpClient().execute(request);
if (response.getFundChange().equals("N") || response.getFundChange() == null) {
if (response.getFundChange() == null || response.getFundChange().equals("N")) {
try {
String refundError = "";
refundStatus = DragonConstant.RefundStatusEnum.STATUS_ERROR.getCode();
if (null == response.getSubMsg()) {
refundError = "退款失败,原因未知";
......@@ -295,7 +298,7 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
return channelDto;
}
channelDto.setResult("error");
channelDto.setMessage(paymentType + " refund error: ");
channelDto.setMessage(refundError);
contentDto.setRequest(JSON.toJSONString(response.getParams()));
contentDto.setResponse(response.getBody());
channelDto.setContent(contentDto);
......@@ -323,7 +326,6 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
);
} catch (Exception e) {
e.printStackTrace();
log.error("");
channelDto.setResult("exception");
channelDto.setMessage("update order refund with db error: " + e.getMessage());
contentDto.setRequest(JSON.toJSONString(response.getParams()));
......@@ -361,17 +363,14 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
String jsonStr = new String(outSteam.toByteArray(), "utf-8");
outSteam.close();
inStream.close();
log.debug("JSON = " + jsonStr);
WePayRefundReturnCallBackDto callBackDto = XmlUtil.toBean(jsonStr, WePayRefundReturnCallBackDto.class);
log.debug("DATA = " + callBackDto);
log.info("callBackDto = " + callBackDto);
if (callBackDto.getReturnCode().equalsIgnoreCase("SUCCESS")) {
String reqInfo = PayWepayUtils.getInstance().unCodeReqInfo(callBackDto.getReqInfo());
log.debug("REQINFO = " + reqInfo);
WePayRefundReturnCallBackInfoDto info = XmlUtil.toBean(reqInfo, WePayRefundReturnCallBackInfoDto.class);
String outRefundNo = info.getOutRefundNo();
String refundAt = info.getSuccessTime();
try {
NotifyUrlDto dto = new NotifyUrlDto();
if (info.getRefundStatus().equalsIgnoreCase("SUCCESS")) {
dto.setStatus(1);
......@@ -383,8 +382,8 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
dto.setRefundPrice(new BigDecimal(info.getRefundFee()).divide(BigDecimal.valueOf(100)).toString());
dto.setRefundAt(refundAt);
dto.setRefundError(callBackDto.getReturnMsg());
log.debug("SEND WEPAY NOTIFTURL = " + JSON.toJSONString(dto));
sendNotifyUrl(dto);
log.info("SEND WEPAY NOTIFTURL = " + JSON.toJSONString(dto));
sendNotifyUrl(dto, null);
mqHandleUtil.sendMySqlRedis(
SqlMapping.get("dragon_order_refund_log.insert"),
......@@ -413,7 +412,61 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
}
@Override
public String aliPayRefundCodeStatus(String outTradeNo, String tradeNo, String outBizNo,String callBackUrl) {
public String aliPayRefundCodeStatus(String outTradeNo, String tradeNo, String outBizNo, String callBackUrl) {
try {
LocalDateTime nowTime = LocalDateTime.now();
AlipayTradeFastpayRefundQueryRequest request = new AlipayTradeFastpayRefundQueryRequest();//创建API对应的request类
request.setBizContent("{" +
"\"out_trade_no\":\"" + outTradeNo + "\"," +
"\"trade_no\":\"" + tradeNo + "\"," +
"\"out_request_no\":\"" + outBizNo + "\"}"); //设置业务参数
AlipayTradeFastpayRefundQueryResponse response = PayAlipayUtils.getInstance().getHttpClient().execute(request);
log.info("AlipayTradeFastpayRefundQueryRequest -> data = " + response);
if (response.isSuccess()) {
try {
NotifyUrlDto dto = new NotifyUrlDto();
if (response.getMsg().equalsIgnoreCase("SUCCESS")) {
dto.setStatus(1);
} else {
dto.setStatus(0);
}
dto.setOrderRefundCode(response.getOutRequestNo());
dto.setRefundCode(response.getOutTradeNo());
dto.setRefundPrice(response.getRefundAmount());
dto.setRefundAt(DateUtil.Formatter.yyyyMMddHHmmss.format(LocalDateTime.now()));
dto.setRefundPrice(response.getRefundAmount());
dto.setRefundError("");
sendNotifyUrl(dto, callBackUrl);
log.debug("SEND ALIPAY NOTIFTURL2 = " + JSON.toJSONString(dto));
mqHandleUtil.sendMySqlRedis(
SqlMapping.get("dragon_order_refund_log.insert"),
new Object[]{outBizNo, "ALIPAY", JSON.toJSONString(response), nowTime, nowTime},
DragonConstant.MysqlRedisQueueEnum.DRAGON_REFUND_KEY.getCode()
);
mqHandleUtil.sendMySqlRedis(
SqlMapping.get("dragon_order_refund_success.update"),
new Object[]{nowTime, DateUtil.format(response.getGmtRefundPay(), DateUtil.Formatter.yyyyMMddHHmmss), DragonConstant.RefundStatusEnum.STATUS_REFUNDED.getCode(), response.getOutRequestNo()},
DragonConstant.MysqlRedisQueueEnum.DRAGON_REFUND_KEY.getCode()
);
return "success";
} catch (Exception e) {
e.printStackTrace();
log.error("");
return "fail";
}
} else {
log.error("response.isSuccess() -> fail ");
return "fail";
}
} catch (Exception e) {
}
return null;
}
......@@ -427,11 +480,10 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
"\"trade_no\":\"" + callBackDto.getTradeNo() + "\"," +
"\"out_request_no\":\"" + callBackDto.getOutBizNo() + "\"}"); //设置业务参数
AlipayTradeFastpayRefundQueryResponse response = PayAlipayUtils.getInstance().getHttpClient().execute(request);
log.debug("AlipayTradeFastpayRefundQueryRequest -> data = " + JSON.toJSONString(response));
log.info("AlipayTradeFastpayRefundQueryRequest -> data = " + JSON.toJSONString(response));
if (response.isSuccess()) {
try {
NotifyUrlDto dto = new NotifyUrlDto();
if (response.getMsg().equalsIgnoreCase("SUCCESS")) {
dto.setStatus(1);
......@@ -444,8 +496,7 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
dto.setRefundAt(callBackDto.getGmtRefund());
dto.setRefundPrice(response.getRefundAmount());
dto.setRefundError("");
log.debug("SEND ALIPAY NOTIFTURL = " + JSON.toJSONString(dto));
sendNotifyUrl(dto);
sendNotifyUrl(dto, null);
mqHandleUtil.sendMySqlRedis(
SqlMapping.get("dragon_order_refund_log.insert"),
......@@ -476,7 +527,7 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
}
}
private void sendNotifyUrl(NotifyUrlDto notifyUrlDto) {
private void sendNotifyUrl(NotifyUrlDto notifyUrlDto, String url) {
LocalDateTime nowTime = LocalDateTime.now();
MultiValueMap<String, String> params = new LinkedMultiValueMap();
params.add("orderRefundCode", notifyUrlDto.getOrderRefundCode());
......@@ -485,8 +536,8 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
params.add("refundError", notifyUrlDto.getRefundError());
params.add("refundPrice", notifyUrlDto.getRefundPrice());
params.add("status", notifyUrlDto.getStatus().toString());
String response = HttpUtil.post(dataUtils.getRefundNotifyUrl(DragonConstant.REFUND_REDIS_KET + notifyUrlDto.getOrderRefundCode()), params);
log.debug("RETURN RESPONSE=" + response);
String response = HttpUtil.post(url == null ? dataUtils.getRefundNotifyUrl(notifyUrlDto.getOrderRefundCode()) : url, params);
log.info("RETURN RESPONSE=" + response);
if (response.equals("success")) {
mqHandleUtil.sendMySqlRedis(
SqlMapping.get("dragon_order_refund_call_back.update"),
......@@ -501,4 +552,5 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
);
}
}
}
Markdown is supported
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