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

Commit 4a5227f6 authored by 胡佳晨's avatar 胡佳晨

`提交支付宝 退款回调`

parent 00a50615
...@@ -18,6 +18,7 @@ import com.liquidnet.service.dragon.dto.DragonOrdersDto; ...@@ -18,6 +18,7 @@ import com.liquidnet.service.dragon.dto.DragonOrdersDto;
import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto; import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto;
import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto; import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto;
import com.liquidnet.service.dragon.dto.DragonPayOrderQueryRespDto; import com.liquidnet.service.dragon.dto.DragonPayOrderQueryRespDto;
import com.liquidnet.service.dragon.service.impl.DragonOrderRefundsServiceImpl;
import com.liquidnet.service.dragon.utils.DataUtils; import com.liquidnet.service.dragon.utils.DataUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -52,6 +53,9 @@ public class PayChannelStrategyAlipayImpl implements IPayChannelStrategy { ...@@ -52,6 +53,9 @@ public class PayChannelStrategyAlipayImpl implements IPayChannelStrategy {
@Autowired @Autowired
private AlipayBiz alipayBiz; private AlipayBiz alipayBiz;
@Autowired
private DragonOrderRefundsServiceImpl dragonOrderRefundsService;
@Value("${liquidnet.dragon.wepay.partnerKey}") @Value("${liquidnet.dragon.wepay.partnerKey}")
private String partnerKey; private String partnerKey;
...@@ -66,7 +70,9 @@ public class PayChannelStrategyAlipayImpl implements IPayChannelStrategy { ...@@ -66,7 +70,9 @@ public class PayChannelStrategyAlipayImpl implements IPayChannelStrategy {
Map<String, String> notifyMap = new HashMap<String, String>(); Map<String, String> notifyMap = new HashMap<String, String>();
notifyMap = alipayBiz.parseNotifyMsg(requestParams); notifyMap = alipayBiz.parseNotifyMsg(requestParams);
log.info("dragonNotify-->alipay json : {}", JSON.toJSONString(notifyMap)); log.info("dragonNotify-->alipay json : {}", JSON.toJSONString(notifyMap));
if(notifyMap.containsKey("refund_fee") || notifyMap.containsKey("gmt_refund") || notifyMap.containsKey("out_biz_no")) {
dragonOrderRefundsService.aliPayRefundCallBack(JSON.toJSONString(notifyMap));
}
log.info("接收到{}支付结果{}", payType, notifyMap); log.info("接收到{}支付结果{}", payType, notifyMap);
String returnStr = null; String returnStr = null;
......
package com.liquidnet.service.dragon.controller; package com.liquidnet.service.dragon.controller;
import com.liquidnet.service.dragon.service.IDragonOrderRefundsService;
import com.liquidnet.service.dragon.service.IDragonOrdersService; import com.liquidnet.service.dragon.service.IDragonOrdersService;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
......
package com.liquidnet.service.dragon.service.impl; package com.liquidnet.service.dragon.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alipay.api.request.AlipayTradeFastpayRefundQueryRequest;
import com.alipay.api.request.AlipayTradeRefundRequest; import com.alipay.api.request.AlipayTradeRefundRequest;
import com.alipay.api.response.AlipayTradeFastpayRefundQueryResponse;
import com.alipay.api.response.AlipayTradeRefundResponse; import com.alipay.api.response.AlipayTradeRefundResponse;
import com.liquidnet.common.cache.redis.util.RedisUtil; import com.liquidnet.common.cache.redis.util.RedisUtil;
import com.liquidnet.commons.lang.util.DateUtil; import com.liquidnet.commons.lang.util.DateUtil;
...@@ -28,6 +30,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -28,6 +30,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.DateUtils;
import org.apache.http.entity.StringEntity; import org.apache.http.entity.StringEntity;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -411,46 +414,50 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -411,46 +414,50 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
try { try {
AliPayRefundReturnCallBackDto callBackDto = JsonUtils.fromJson(jsonStr, AliPayRefundReturnCallBackDto.class); AliPayRefundReturnCallBackDto callBackDto = JsonUtils.fromJson(jsonStr, AliPayRefundReturnCallBackDto.class);
log.debug("DATA = " + callBackDto); log.debug("DATA = " + callBackDto);
if (callBackDto.getNotifyType().equalsIgnoreCase("SUCCESS")) { AlipayTradeFastpayRefundQueryRequest request = new AlipayTradeFastpayRefundQueryRequest();//创建API对应的request类
String outRefundNo = callBackDto.getOutBizNo(); log.debug("AlipayTradeFastpayRefundQueryRequest -> data = " + JSON.toJSONString(request));
String refundAt = callBackDto.getGmtRefund(); request.setBizContent("{" +
String outTradeNo = callBackDto.getOutTradeNo(); "\"out_trade_no\":\"" + callBackDto.getOutTradeNo() + "\"," +
String refundFee = callBackDto.getRefundFee(); "\"trade_no\":\"" + callBackDto.getTradeNo() + "\"," +
"\"out_request_no\":\"" + callBackDto.getOutBizNo() + "\"}"); //设置业务参数
AlipayTradeFastpayRefundQueryResponse response = PayAlipayUtils.getInstance().getHttpClient().execute(request);
if (response.getRefundChannelStatus().equalsIgnoreCase("SUCCESS")) {
try { try {
sendMySqlRedis( sendMySqlRedis(
SqlMapping.get("dragon_order_refund_log.insert"), SqlMapping.get("dragon_order_refund_log.insert"),
new Object[]{outRefundNo, "退款原因", jsonStr, nowTime, nowTime} new Object[]{response.getOutRequestNo(), response.getRefundReason(), jsonStr, nowTime, nowTime}
); );
sendMySqlRedis( sendMySqlRedis(
SqlMapping.get("dragon_order_refund_success.update"), SqlMapping.get("dragon_order_refund_success.update"),
new Object[]{nowTime, refundAt, DragonConstant.RefundStatusEnum.STATUS_REFUNDED.getCode(), outRefundNo} new Object[]{nowTime, response.getGmtRefundPay(), DragonConstant.RefundStatusEnum.STATUS_REFUNDED.getCode(), response.getOutRequestNo()}
); );
NotifyUrlDto dto = new NotifyUrlDto(); NotifyUrlDto dto = new NotifyUrlDto();
if (callBackDto.getNotifyType().equalsIgnoreCase("SUCCESS")) { if (response.getRefundChannelStatus().equalsIgnoreCase("SUCCESS")) {
dto.setStatus(1); dto.setStatus(1);
} else { } else {
dto.setStatus(0); dto.setStatus(0);
} }
dto.setOrderRefundCode(outRefundNo); dto.setOrderRefundCode(response.getOutRequestNo());
dto.setRefundCode(outTradeNo); dto.setRefundCode(response.getOutTradeNo());
dto.setRefundPrice(refundFee); dto.setRefundPrice(response.getRefundAmount());
dto.setRefundAt(refundAt); dto.setRefundAt(DateUtil.format(response.getGmtRefundPay(), DateUtil.Formatter.yyyyMMddHHmmss));
dto.setRefundError("退款失败"); dto.setRefundPrice(response.getRefundAmount());
dto.setRefundError(response.getSubMsg());
sendNotifyUrl(dto); sendNotifyUrl(dto);
return "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>"; return "success";
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error(""); log.error("");
return "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[ERROR]]></return_msg></xml>"; return "fail";
} }
} else { } else {
return "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[ERROR]]></return_msg></xml>"; return "fail";
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error(""); log.error("");
return "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[ERROR]]></return_msg></xml>"; return "fail";
} }
} }
...@@ -497,7 +504,7 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -497,7 +504,7 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
params.add("refundCode", notifyUrlDto.getRefundCode()); params.add("refundCode", notifyUrlDto.getRefundCode());
params.add("refundError", notifyUrlDto.getRefundError()); params.add("refundError", notifyUrlDto.getRefundError());
// params.add("refundId", notifyUrlDto.getRefundId()); // params.add("refundId", notifyUrlDto.getRefundId());
params.add("refundPrice", notifyUrlDto.getRefundPrice()); // params.add("refundPrice", notifyUrlDto.getRefundPrice());
params.add("status", notifyUrlDto.getStatus().toString()); params.add("status", notifyUrlDto.getStatus().toString());
String response = HttpUtil.post((String) redisUtil.get(DragonConstant.REFUND_REDIS_KET + notifyUrlDto.getOrderRefundCode()), params); String response = HttpUtil.post((String) redisUtil.get(DragonConstant.REFUND_REDIS_KET + notifyUrlDto.getOrderRefundCode()), params);
log.debug("RETURN RESPONSE=" + response); log.debug("RETURN RESPONSE=" + response);
......
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