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

Commit 4f030082 authored by zhengfuxin's avatar zhengfuxin

抖音退款回调

parent 2bf2ba2d
......@@ -24,4 +24,6 @@ public interface IDragonOrderRefundsService {
String aliPayRefundCodeStatus(String outTradeNo ,String tradeNo ,String outBizNo,String callBackUrl);
String douYinPayRefundCallBack(HttpServletRequest request , HttpServletResponse response);
}
......@@ -57,5 +57,12 @@ public class RefundController {
return orderRefundsService.aliPayRefundCodeStatus(orderCode, paymentId, orderRefundCode, callBackUrl);
}
@PostMapping("callBack/douyinpay")
@ApiOperation("抖音退款回调")
@ApiResponse(code = 200, message = "接口返回对象参数")
public String douYinCallBack(HttpServletRequest request, HttpServletResponse response) {
return orderRefundsService.douYinPayRefundCallBack(request, response);
}
}
package com.liquidnet.service.dragon.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.request.AlipayTradeFastpayRefundQueryRequest;
import com.alipay.api.request.AlipayTradeRefundRequest;
import com.alipay.api.response.AlipayTradeFastpayRefundQueryResponse;
import com.alipay.api.response.AlipayTradeRefundResponse;
import com.liquidnet.common.exception.LiquidnetServiceException;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.commons.lang.util.HttpUtil;
import com.liquidnet.commons.lang.util.IDGenerator;
......@@ -16,6 +18,7 @@ import com.liquidnet.service.dragon.channel.wepay.resp.WePayRefundReturnCallBack
import com.liquidnet.service.dragon.channel.wepay.resp.WePayRefundReturnCallBackInfoDto;
import com.liquidnet.service.dragon.channel.wepay.resp.WePayRefundReturnDto;
import com.liquidnet.service.dragon.constant.DragonConstant;
import com.liquidnet.service.dragon.constant.DragonErrorCodeEnum;
import com.liquidnet.service.dragon.dto.DragonRefundAppDto;
import com.liquidnet.service.dragon.dto.DragonRefundChannelDto;
import com.liquidnet.service.dragon.dto.NotifyUrlDto;
......@@ -40,7 +43,9 @@ import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.SortedMap;
import java.util.TreeMap;
......@@ -345,6 +350,61 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
return null;
}
}
/**
* @author zhangfuxin
* @Description: 抖音退款回调
* @date 2021/11/11 上午10:55
*/
public String douYinPayRefundCallBack(HttpServletRequest request, HttpServletResponse response){
try {
LocalDateTime nowTime = LocalDateTime.now();
JSONObject jsonObject=PayDouYinpayUtils.getJsonObject(request);
log.info("接收到的抖音退款回调请求参数{}",JSON.toJSONString(jsonObject));
//再次验证是退款的回调
if(!jsonObject.getString("type").equals("refund")){
throw new LiquidnetServiceException(DragonErrorCodeEnum.TRADE_PARAM_ERROR.getCode(),DragonErrorCodeEnum.TRADE_PARAM_ERROR.getMessage());
}
JSONObject msg=jsonObject.getJSONObject("msg");
NotifyUrlDto dto = new NotifyUrlDto();
// 验签
if (PayDouYinpayUtils.getInstance().notifySign(msg.get("msg_signature").toString(),jsonObject)) {// 根据配置信息验证签名
//查看退款状态 (退款状态 PROCESSING-处理中|SUCCESS-成功|FAIL-失败)
if(msg.getString("status").equals("SUCCESS")){
dto.setStatus(1);
}else{
dto.setStatus(0);
}
//开发者自定义的退款单号
dto.setOrderRefundCode(msg.getString("cp_refundno"));
// 没有订单号
dto.setRefundCode("");
dto.setRefundPrice(msg.getBigDecimal("refund_amount").divide(BigDecimal.valueOf(100)).toString());
SimpleDateFormat sdf = new SimpleDateFormat( " yyyy年MM月dd日 " );
// 抖音没有传回时间
dto.setRefundAt(sdf.format(new Date()));
//抖音回调没有写错误原因
dto.setRefundError("");
log.info("SEND DOUYINPAY NOTIFTURL = " + JSON.toJSONString(dto));
sendNotifyUrl(dto, null);
//创建退款订单日志
mqHandleUtil.sendMySqlRedis(
SqlMapping.get("dragon_order_refund_log.insert"),
new Object[]{msg.getString("cp_refundno"), "", JSON.toJSONString(jsonObject), nowTime, nowTime},
DragonConstant.MysqlRedisQueueEnum.DRAGON_REFUND_KEY.getCode()
);
//修改订单 状态
mqHandleUtil.sendMySqlRedis(
SqlMapping.get("dragon_order_refund_success.update"),
new Object[]{nowTime, dto.getRefundAt(), DragonConstant.RefundStatusEnum.STATUS_REFUNDED.getCode(), msg.getString("cp_refundno")},
DragonConstant.MysqlRedisQueueEnum.DRAGON_REFUND_KEY.getCode()
);
}
}catch (Exception e) {
e.printStackTrace();
}
return "";
}
@Override
public String wePayRefundCallBack(HttpServletRequest request, HttpServletResponse response) {
......
......@@ -45,5 +45,11 @@ public class RefundController {
HttpServletResponse response) {
return orderRefundsService.wePayRefundCallBack(request, response);
}
@PostMapping("callBack/douyinpay")
@ApiOperation("抖音退款回调")
@ApiResponse(code = 200, message = "接口返回对象参数")
public String douYinCallBack(HttpServletRequest request, HttpServletResponse response) {
return orderRefundsService.douYinPayRefundCallBack(request, response);
}
}
package com.liquidnet.service.dragon.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.request.AlipayTradeFastpayRefundQueryRequest;
import com.alipay.api.request.AlipayTradeRefundRequest;
import com.alipay.api.response.AlipayTradeFastpayRefundQueryResponse;
import com.alipay.api.response.AlipayTradeRefundResponse;
import com.liquidnet.common.exception.LiquidnetServiceException;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.commons.lang.util.HttpUtil;
import com.liquidnet.commons.lang.util.IDGenerator;
......@@ -16,6 +18,7 @@ import com.liquidnet.service.dragon.channel.wepay.resp.WePayRefundReturnCallBack
import com.liquidnet.service.dragon.channel.wepay.resp.WePayRefundReturnCallBackInfoDto;
import com.liquidnet.service.dragon.channel.wepay.resp.WePayRefundReturnDto;
import com.liquidnet.service.dragon.constant.DragonConstant;
import com.liquidnet.service.dragon.constant.DragonErrorCodeEnum;
import com.liquidnet.service.dragon.dto.DragonRefundAppDto;
import com.liquidnet.service.dragon.dto.DragonRefundChannelDto;
import com.liquidnet.service.dragon.dto.NotifyUrlDto;
......@@ -40,11 +43,9 @@ import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.*;
@Slf4j
@Service
......@@ -73,7 +74,7 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
dataUtils.setRefundNotifyUrl(orderRefundCode, notifyUrl);
DragonRefundChannelDto dto = null;
String localWePayCallBackUrl = url + "/refund/callBack/wepay";
String localDouYinCallBackUrl = url + "/refund/callBack/douYinPay";
String localDouYinCallBackUrl = url + "/refund/callBack/douyinpay";
if (insertResult) {
switch (paymentType) {
case DragonConstant.REFUND_TYPE_APP_ALIPAY:
......@@ -458,6 +459,61 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
}
}
/**
* @author zhangfuxin
* @Description: 抖音退款回调
* @date 2021/11/11 上午10:55
*/
public String douYinPayRefundCallBack(HttpServletRequest request, HttpServletResponse response){
try {
LocalDateTime nowTime = LocalDateTime.now();
JSONObject jsonObject=PayDouYinpayUtils.getJsonObject(request);
log.info("接收到的抖音退款回调请求参数{}",JSON.toJSONString(jsonObject));
//再次验证是退款的回调
if(!jsonObject.getString("type").equals("refund")){
throw new LiquidnetServiceException(DragonErrorCodeEnum.TRADE_PARAM_ERROR.getCode(),DragonErrorCodeEnum.TRADE_PARAM_ERROR.getMessage());
}
JSONObject msg=jsonObject.getJSONObject("msg");
NotifyUrlDto dto = new NotifyUrlDto();
// 验签
if (PayDouYinpayUtils.getInstance().notifySign(msg.get("msg_signature").toString(),jsonObject)) {// 根据配置信息验证签名
//查看退款状态 (退款状态 PROCESSING-处理中|SUCCESS-成功|FAIL-失败)
if(msg.getString("status").equals("SUCCESS")){
dto.setStatus(1);
}else{
dto.setStatus(0);
}
//开发者自定义的退款单号
dto.setOrderRefundCode(msg.getString("cp_refundno"));
// 没有订单号
dto.setRefundCode("");
dto.setRefundPrice(msg.getBigDecimal("refund_amount").divide(BigDecimal.valueOf(100)).toString());
SimpleDateFormat sdf = new SimpleDateFormat( " yyyy年MM月dd日 " );
// 抖音没有传回时间
dto.setRefundAt(sdf.format(new Date()));
//抖音回调没有写错误原因
dto.setRefundError("");
log.info("SEND DOUYINPAY NOTIFTURL = " + JSON.toJSONString(dto));
sendNotifyUrl(dto, null);
//创建退款订单日志
mqHandleUtil.sendMySqlRedis(
SqlMapping.get("dragon_order_refund_log.insert"),
new Object[]{msg.getString("cp_refundno"), "", JSON.toJSONString(jsonObject), nowTime, nowTime},
DragonConstant.MysqlRedisQueueEnum.DRAGON_REFUND_KEY.getCode()
);
//修改订单 状态
mqHandleUtil.sendMySqlRedis(
SqlMapping.get("dragon_order_refund_success.update"),
new Object[]{nowTime, dto.getRefundAt(), DragonConstant.RefundStatusEnum.STATUS_REFUNDED.getCode(), msg.getString("cp_refundno")},
DragonConstant.MysqlRedisQueueEnum.DRAGON_REFUND_KEY.getCode()
);
}
}catch (Exception e) {
e.printStackTrace();
}
return "";
}
@Override
public String wePayRefundCallBack(HttpServletRequest request, HttpServletResponse response) {
InputStream inStream;
......
package com.liquidnet.service.dragon.utils;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.internal.util.file.IOUtils;
import com.liquidnet.commons.lang.util.MD5Utils;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
......@@ -14,8 +15,11 @@ import org.dom4j.io.SAXReader;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import javax.net.ssl.SSLContext;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.security.KeyStore;
import java.security.MessageDigest;
......@@ -139,16 +143,20 @@ public class PayDouYinpayUtils {
return httpClient;
}
//生成随机字符串nonce_str
public String getNonceStr() {
String base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
Random random = new Random();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < 32; i++) {
int number = random.nextInt(base.length());
sb.append(base.charAt(number));
public static JSONObject getJsonObject(HttpServletRequest request) {
String param= null;
JSONObject jsonObject=null;
try {
BufferedReader streamReader = new BufferedReader( new InputStreamReader(request.getInputStream(), "UTF-8"));
StringBuilder responseStrBuilder = new StringBuilder();
String inputStr;
while ((inputStr = streamReader.readLine()) != null)
responseStrBuilder.append(inputStr);
jsonObject = JSONObject.parseObject(responseStrBuilder.toString());
} catch (Exception e) {
e.printStackTrace();
}
return sb.toString();
return jsonObject;
}
public String createSign(SortedMap<String, Object> parameters) {
......@@ -233,14 +241,17 @@ public class PayDouYinpayUtils {
return this.partnerKey;
}
public boolean notifySign(Map<String, String> result, String sign) {
String argNotifySign = getStringByStringMap(result) + "&key=" + this.partnerKey;
String notifySign = MD5Utils.md5(argNotifySign).toUpperCase();
if (notifySign.equals(sign)) {
public boolean notifySign(String sign, JSONObject jsonObject) {
Map<String, Object> map = new HashMap<>();
//循环转换
for (Map.Entry<String, Object> entry : jsonObject.entrySet()) {
map.put(entry.getKey(), entry.getValue());
}
String signBack=PayDouYinpayUtils.getInstance().createSign(map);
if(sign.equals(signBack))
return true;
} else {
else
return false;
}
}
public static String getStringByStringMap(Map<String, String> map) {
......
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