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

Commit 02d557b9 authored by anjiabin's avatar anjiabin

Merge branch 'dev' of http://gitlab.zhengzai.tv/dongjingwei/liquidnet-bus-v1 into dev

 Conflicts:
	liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/service/impl/DragonOrderRefundsServiceImpl.java
parents f0aa407c a4c37a06
...@@ -18,7 +18,7 @@ public interface IDragonOrderRefundsService { ...@@ -18,7 +18,7 @@ public interface IDragonOrderRefundsService {
* @param price 退款金额 * @param price 退款金额
* @param paymentType 支付类型 * @param paymentType 支付类型
*/ */
ResponseDto<DragonRefundAppDto> dragonRefund(String orderCode, String tradeNo, String outTradeNo, String reason, String returnUrl, BigDecimal price, String paymentType,String paymentId); ResponseDto<DragonRefundAppDto> dragonRefund(String orderCode, String tradeNo, String outTradeNo, String reason, String returnUrl, BigDecimal price, String paymentType,String paymentId,BigDecimal priceTotal);
ResponseDto<DragonRefundAppDto> wePayRefundCallBack(); ResponseDto<DragonRefundAppDto> wePayRefundCallBack();
......
package com.liquidnet.service.dragon.channel.wepay.resp;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.Data;
@Data
@XStreamAlias("xml")
public class WePayRefundReturnDto {
@XStreamAlias("return_code")
private String returnCode;
@XStreamAlias("return_msg")
private String returnMsg;
@XStreamAlias("appid")
private String appId;
@XStreamAlias("mch_id")
private String mchId;
@XStreamAlias("nonce_str")
private String nonceStr;
@XStreamAlias("sign")
private String sign;
@XStreamAlias("result_code")
private String resultCode;
@XStreamAlias("transaction_id")
private String transactionId;
@XStreamAlias("out_trade_no")
private String outTradeNo;
@XStreamAlias("out_refund_no")
private String outRefundNo;
@XStreamAlias("refund_id")
private String refundId;
@XStreamAlias("refund_channel")
private String refundChannel;
@XStreamAlias("refund_fee")
private String refundFee;
@XStreamAlias("coupon_refund_fee")
private String couponRefundFee;
@XStreamAlias("total_fee")
private String totalFee;
@XStreamAlias("cash_fee")
private String cashFee;
@XStreamAlias("coupon_refund_count")
private String couponRefundCount;
@XStreamAlias("cash_refund_fee")
private String cashRefundFee;
}
...@@ -41,9 +41,10 @@ public class RefundController { ...@@ -41,9 +41,10 @@ public class RefundController {
@RequestParam(value = "orderRefundCode") @NotNull(message = "退款单号不能为空") String orderRefundCode, @RequestParam(value = "orderRefundCode") @NotNull(message = "退款单号不能为空") String orderRefundCode,
@RequestParam(value = "reason") @NotNull(message = "退款原因不能为空") String reason, @RequestParam(value = "reason") @NotNull(message = "退款原因不能为空") String reason,
@RequestParam(value = "notifyUrl") @NotNull(message = "回调地址不能为空") String returnUrl, @RequestParam(value = "notifyUrl") @NotNull(message = "回调地址不能为空") String returnUrl,
@RequestParam(value = "price") @NotNull(message = "价格不能为空") BigDecimal price, @RequestParam(value = "price") @NotNull(message = "退款价格不能为空") BigDecimal price,
@RequestParam(value = "priceTotal") @NotNull(message = "订单价格不能为空") BigDecimal priceTotal,
@RequestParam(value = "paymentType") @NotNull(message = "支付类型不能为空") String paymentType, @RequestParam(value = "paymentType") @NotNull(message = "支付类型不能为空") String paymentType,
@RequestParam(value = "paymentId") @NotNull(message = "支付订单号不能为空") String paymentId) { @RequestParam(value = "paymentId") @NotNull(message = "支付订单号不能为空") String paymentId) {
return orderRefundsService.dragonRefund(orderCode, code, orderRefundCode, reason, returnUrl, price, paymentType, paymentId); return orderRefundsService.dragonRefund(orderCode, code, orderRefundCode, reason, returnUrl, price, paymentType, paymentId, priceTotal);
} }
} }
...@@ -11,9 +11,11 @@ import com.liquidnet.service.dragon.constant.DragonConstant; ...@@ -11,9 +11,11 @@ import com.liquidnet.service.dragon.constant.DragonConstant;
import com.liquidnet.service.dragon.dto.DragonRefundAppDto; import com.liquidnet.service.dragon.dto.DragonRefundAppDto;
import com.liquidnet.service.dragon.dto.DragonRefundChannelDto; import com.liquidnet.service.dragon.dto.DragonRefundChannelDto;
import com.liquidnet.service.dragon.dto.RefundContentDto; import com.liquidnet.service.dragon.dto.RefundContentDto;
import com.liquidnet.service.dragon.channel.wepay.resp.WePayRefundReturnDto;
import com.liquidnet.service.dragon.service.IDragonOrderRefundsService; import com.liquidnet.service.dragon.service.IDragonOrderRefundsService;
import com.liquidnet.service.dragon.utils.PayAlipayUtils; import com.liquidnet.service.dragon.utils.PayAlipayUtils;
import com.liquidnet.service.dragon.utils.PayWepayUtils; import com.liquidnet.service.dragon.utils.PayWepayUtils;
import com.liquidnet.service.dragon.utils.XmlUtil;
import lombok.extern.slf4j.Slf4j; 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;
...@@ -28,10 +30,7 @@ import org.springframework.stereotype.Service; ...@@ -28,10 +30,7 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.HashMap; import java.util.*;
import java.util.LinkedList;
import java.util.SortedMap;
import java.util.TreeMap;
@Slf4j @Slf4j
@Service @Service
...@@ -42,47 +41,11 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -42,47 +41,11 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
@Override @Override
public void sendRedisQueue() { public void sendRedisQueue() {
try {
// PayWepayUtils payWepayUtils = new PayWepayUtils();
String nonceStr = PayWepayUtils.getInstance().getNonceStr();
SortedMap<Object, Object> parameters = new TreeMap<>();
parameters.put("mch_id", PayWepayUtils.getInstance().getMerchantId());
parameters.put("appid", PayWepayUtils.getInstance().getAppId());
parameters.put("nonce_str", nonceStr);
parameters.put("out_refund_no", "20210710140233163870197466289T");
parameters.put("out_trade_no", "20210710140233163870197466289P");
parameters.put("refund_fee", "1");
parameters.put("total_fee", "1");
parameters.put("notify_url", "https://www.baidu.com");
parameters.put("refund_desc", "测试退款");
String sign = PayWepayUtils.getInstance().createSign(parameters);
parameters.put("sign", sign);
String data = PayWepayUtils.getInstance().getRequestXml(parameters);
try {
HttpPost httpost = new HttpPost("https://api.mch.weixin.qq.com/secapi/pay/refund");
httpost.setEntity(new StringEntity(data, "UTF-8"));
CloseableHttpResponse response = PayWepayUtils.getInstance().getHttpClient().execute(httpost);
try {
HttpEntity entity = response.getEntity();
//接受到返回信息
String jsonStr = EntityUtils.toString(response.getEntity(), "UTF-8");
EntityUtils.consume(entity);
System.out.println(jsonStr);
} finally {
response.close();
}
} finally {
PayWepayUtils.getInstance().getHttpClient().close();
}
} catch (Exception e) {
e.printStackTrace();
}
} }
@Override @Override
public ResponseDto<DragonRefundAppDto> dragonRefund(String orderCode, String code, String orderRefundCode, String reason, String notifyUrl, BigDecimal price, String paymentType, String paymentId) { public ResponseDto<DragonRefundAppDto> dragonRefund(String orderCode, String code, String orderRefundCode, String reason, String notifyUrl, BigDecimal price, String paymentType, String paymentId, BigDecimal priceTotal) {
try {
LocalDateTime nowTime = LocalDateTime.now(); LocalDateTime nowTime = LocalDateTime.now();
String refundCode = IDGenerator.refundCode(); String refundCode = IDGenerator.refundCode();
String orderRefundId = IDGenerator.nextSnowId(); String orderRefundId = IDGenerator.nextSnowId();
...@@ -91,18 +54,45 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -91,18 +54,45 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
SqlMapping.get("dragon_order_refund.insert"), SqlMapping.get("dragon_order_refund.insert"),
new Object[]{orderRefundId, refundCode, orderRefundCode, price, reason, notifyUrl, paymentType, nowTime, nowTime} new Object[]{orderRefundId, refundCode, orderRefundCode, price, reason, notifyUrl, paymentType, nowTime, nowTime}
); );
DragonRefundChannelDto dto = null;
if (insertResult) { if (insertResult) {
switch (paymentType) { switch (paymentType) {
case DragonConstant.REFUND_TYPE_APP_ALIPAY: case DragonConstant.REFUND_TYPE_APP_ALIPAY:
aliPayRefund(orderRefundId, orderRefundCode, code, reason, price, paymentId, paymentType, nowTime); dto = aliPayRefund(orderRefundId, orderRefundCode, code, reason, price, paymentId, paymentType, nowTime);
break; break;
case DragonConstant.REFUND_TYPE_WAP_ALIPAY: case DragonConstant.REFUND_TYPE_WAP_ALIPAY:
aliPayRefund(orderRefundId, orderRefundCode, code, reason, price, paymentId, paymentType, nowTime); dto = aliPayRefund(orderRefundId, orderRefundCode, code, reason, price, paymentId, paymentType, nowTime);
break; break;
case DragonConstant.REFUND_TYPE_WEB_ALIPAY: case DragonConstant.REFUND_TYPE_WEB_ALIPAY:
aliPayRefund(orderRefundId, orderRefundCode, code, reason, price, paymentId, paymentType, nowTime); dto = aliPayRefund(orderRefundId, orderRefundCode, code, reason, price, paymentId, paymentType, nowTime);
break;
case DragonConstant.REFUND_TYPE_APP_WEPAY:
dto = weyPayRefund(orderRefundId, orderRefundCode, code, reason, price, priceTotal, paymentId, paymentType, notifyUrl, nowTime);
break;
case DragonConstant.REFUND_TYPE_WAP_WEPAY:
dto = weyPayRefund(orderRefundId, orderRefundCode, code, reason, price, priceTotal, paymentId, paymentType, notifyUrl, nowTime);
break; break;
case DragonConstant.REFUND_TYPE_WEB_WEPAY:
dto = weyPayRefund(orderRefundId, orderRefundCode, code, reason, price, priceTotal, paymentId, paymentType, notifyUrl, nowTime);
break;
case DragonConstant.REFUND_TYPE_JS_WEPAY:
dto = weyPayRefund(orderRefundId, orderRefundCode, code, reason, price, priceTotal, paymentId, paymentType, notifyUrl, nowTime);
break;
}
if (dto.getResult().equalsIgnoreCase("refunding")) {
log.info("");
} else if (dto.getResult().equalsIgnoreCase("refunded")) {
//调用回调
log.info("");
} else if (dto.getResult().equalsIgnoreCase("error")) {
//调用回调
log.error("");
} else if (dto.getResult().equalsIgnoreCase("exception")) {
log.error("");
} }
DragonRefundAppDto refundAppDto = new DragonRefundAppDto(); DragonRefundAppDto refundAppDto = new DragonRefundAppDto();
refundAppDto.setOrderCode(orderCode); refundAppDto.setOrderCode(orderCode);
refundAppDto.setCode(code); refundAppDto.setCode(code);
...@@ -112,6 +102,11 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -112,6 +102,11 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
} else { } else {
return ResponseDto.failure("退款失败"); return ResponseDto.failure("退款失败");
} }
} catch (Exception e) {
e.printStackTrace();
log.error("");
return ResponseDto.failure("退款失败:" + e.getMessage());
}
} }
@Override @Override
...@@ -119,84 +114,110 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -119,84 +114,110 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
return null; return null;
} }
public void weyPayRefund() { public DragonRefundChannelDto weyPayRefund(String orderRefundId, String refundCode, String code, String reason, BigDecimal price, BigDecimal priceTotal, String paymentId, String paymentType, String notifyUrl, LocalDateTime nowTime) {
try {
} String refundStatus = DragonConstant.RefundStatusEnum.STATUS_ERROR.getCode();
public void wepaySomeThing(){
DragonRefundChannelDto channelDto = new DragonRefundChannelDto(); DragonRefundChannelDto channelDto = new DragonRefundChannelDto();
RefundContentDto contentDto = new RefundContentDto(); RefundContentDto contentDto = new RefundContentDto();
String xml = "<xml><result_code>SUCCESS</result_code></xml>"; String nonceStr = PayWepayUtils.getInstance().getNonceStr();
SortedMap<Object, Object> parameters = new TreeMap<>();
// if (response.getFundChange().equals("N") || response.getFundChange() == null) { parameters.put("mch_id", PayWepayUtils.getInstance().getMerchantId());
// try { parameters.put("appid", PayWepayUtils.getInstance().getAppId());
// String refundError = ""; parameters.put("nonce_str", nonceStr);
// refundStatus = DragonConstant.RefundStatusEnum.STATUS_ERROR.getCode(); parameters.put("out_refund_no", refundCode);
// if (null == response.getSubMsg()) { parameters.put("out_trade_no", code);
// refundError = "退款失败,原因未知"; parameters.put("refund_fee", price.doubleValue() * 100);
// } else { parameters.put("total_fee", priceTotal.doubleValue() * 100);
// refundError = response.getSubMsg(); parameters.put("notify_url", notifyUrl);
// } parameters.put("refund_desc", reason);
// // 修改退款订单 String sign = PayWepayUtils.getInstance().createSign(parameters);
// sendMySqlRedis( parameters.put("sign", sign);
// SqlMapping.get("dragon_order_refund_error.update"), String data = PayWepayUtils.getInstance().getRequestXml(parameters);
// new Object[]{nowTime, refundError, refundStatus, orderRefundId} try {
// ); HttpPost httpost = new HttpPost("https://api.mch.weixin.qq.com/secapi/pay/refund");
// } catch (Exception e) { httpost.setEntity(new StringEntity(data, "UTF-8"));
// e.printStackTrace(); CloseableHttpResponse response = PayWepayUtils.getInstance().getHttpClient().execute(httpost);
// //保存错误信息 try {
// log.error(""); HttpEntity entity = response.getEntity();
// channelDto.setResult("exception"); entity.getContent();
// channelDto.setMessage("update order refund with db error: " + e.getMessage()); String jsonStr = EntityUtils.toString(entity, "UTF-8");
// contentDto.setRequest(JSON.toJSONString(response.getParams())); WePayRefundReturnDto wePayRefundReturnDto = XmlUtil.toBean(jsonStr, WePayRefundReturnDto.class);
// contentDto.setResponse(response.getBody());
// channelDto.setContent(contentDto);
// return channelDto;
// }
// channelDto.setResult("error");
// channelDto.setMessage(paymentType + " refund error: ");
// contentDto.setRequest(JSON.toJSONString(response.getParams()));
// contentDto.setResponse(response.getBody());
// channelDto.setContent(contentDto);
// return channelDto;
// }
//
// // 创建退款日志
// sendMySqlRedis(
// SqlMapping.get("dragon_order_refund_log.insert"),
// new Object[]{orderRefundId, paymentType, JSON.toJSONString(response.getBody()), nowTime, nowTime}
// );
// try {
// String refundAt = "";
// if (response.getFundChange().equals("Y")) {
// refundStatus = DragonConstant.RefundStatusEnum.STATUS_REFUNDED.getCode();
// refundAt = DateUtil.format(response.getGmtRefundPay(), DateUtil.Formatter.yyyyMMddHHmmss);
// } else {
// refundStatus = DragonConstant.RefundStatusEnum.STATUS_REFUNDING.getCode();
// }
// sendMySqlRedis(
// SqlMapping.get("dragon_order_refund_success.update"),
// new Object[]{nowTime, refundAt, refundStatus, orderRefundId}
// );
// } 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()));
// contentDto.setResponse(response.getBody());
// channelDto.setContent(contentDto);
// return channelDto;
// }
// channelDto.setResult("refunded");
// channelDto.setMessage(paymentType + " refund info: ");
// contentDto.setRequest(JSON.toJSONString(response.getParams()));
// contentDto.setResponse(response.getBody());
// channelDto.setContent(contentDto);
// return channelDto;
if (!wePayRefundReturnDto.getResultCode().equalsIgnoreCase("SUCCESS") || wePayRefundReturnDto.getResultCode() == null) {
try {
String refundError = "";
refundStatus = DragonConstant.RefundStatusEnum.STATUS_ERROR.getCode();
if (null == wePayRefundReturnDto.getReturnMsg()) {
refundError = "退款失败,原因未知";
} else {
refundError = wePayRefundReturnDto.getReturnMsg();
}
// 修改退款订单
sendMySqlRedis(
SqlMapping.get("dragon_order_refund_error.update"),
new Object[]{nowTime, refundError, refundStatus, orderRefundId}
);
} catch (Exception e) {
e.printStackTrace();
//保存错误信息
log.error("");
channelDto.setResult("exception");
channelDto.setMessage("update order refund with db error: " + e.getMessage());
contentDto.setRequest(data);
contentDto.setResponse(jsonStr);
channelDto.setContent(contentDto);
return channelDto;
}
channelDto.setResult("error");
channelDto.setMessage(paymentType + " refund error: ");
contentDto.setRequest(data);
contentDto.setResponse(jsonStr);
channelDto.setContent(contentDto);
return channelDto;
} }
// 创建退款日志
sendMySqlRedis(
SqlMapping.get("dragon_order_refund_log.insert"),
new Object[]{orderRefundId, paymentType, data, nowTime, nowTime}
);
try {
if (wePayRefundReturnDto.getResultCode().equalsIgnoreCase("SUCCESS")) {
refundStatus = DragonConstant.RefundStatusEnum.STATUS_REFUNDED.getCode();
}
sendMySqlRedis(
SqlMapping.get("dragon_order_refund_success.update"),
new Object[]{nowTime, null, refundStatus, orderRefundId}
);
} catch (Exception e) {
e.printStackTrace();
log.error("");
channelDto.setResult("exception");
channelDto.setMessage("update order refund with db error: " + e.getMessage());
contentDto.setRequest(data);
contentDto.setResponse(jsonStr);
channelDto.setContent(contentDto);
return channelDto;
}
channelDto.setResult("refunded");
channelDto.setMessage(paymentType + " refund info: ");
contentDto.setRequest(data);
contentDto.setResponse(jsonStr);
channelDto.setContent(contentDto);
EntityUtils.consume(entity);
return channelDto;
} finally {
response.close();
}
} finally {
PayWepayUtils.getInstance().getHttpClient().close();
}
} catch (Exception e) {
e.printStackTrace();
log.error("");
return null;
}
}
public DragonRefundChannelDto aliPayRefund(String orderRefundId, String refundCode, String code, String reason, BigDecimal price, String paymentId, String paymentType, LocalDateTime nowTime) { public DragonRefundChannelDto aliPayRefund(String orderRefundId, String refundCode, String code, String reason, BigDecimal price, String paymentId, String paymentType, LocalDateTime nowTime) {
String refundStatus; String refundStatus;
...@@ -210,8 +231,7 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -210,8 +231,7 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
"\"out_request_no\":\"" + refundCode + "\"," + "\"out_request_no\":\"" + refundCode + "\"," +
"\"refund_reason\":\"" + reason + "\"," + "\"refund_reason\":\"" + reason + "\"," +
"\"refund_amount\":\"" + price.doubleValue() + "\"}"); //设置业务参数 "\"refund_amount\":\"" + price.doubleValue() + "\"}"); //设置业务参数
AlipayTradeRefundResponse response = PayAlipayUtils.getInstance().getHttpClient().execute(request);//通过alipayClient调用API,获得对应的response类 AlipayTradeRefundResponse response = PayAlipayUtils.getInstance().getHttpClient().execute(request);
System.out.print(response.getBody());
if (response.getFundChange().equals("N") || response.getFundChange() == null) { if (response.getFundChange().equals("N") || response.getFundChange() == null) {
try { try {
String refundError = ""; String refundError = "";
......
...@@ -2,10 +2,12 @@ package com.liquidnet.service.dragon.utils; ...@@ -2,10 +2,12 @@ package com.liquidnet.service.dragon.utils;
import com.alipay.api.internal.util.file.IOUtils; import com.alipay.api.internal.util.file.IOUtils;
import com.liquidnet.commons.lang.util.MD5Utils; import com.liquidnet.commons.lang.util.MD5Utils;
import com.liquidnet.service.dragon.channel.wepay.resp.WePayRefundReturnDto;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts; import org.apache.http.ssl.SSLContexts;
import org.dom4j.DocumentException;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
......
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