|
|
|
@@ -12,29 +12,33 @@ import com.wechat.pay.java.core.notification.RequestParam;
|
|
|
|
import com.wechat.pay.java.service.partnerpayments.app.model.Transaction;
|
|
|
|
import com.wechat.pay.java.service.partnerpayments.app.model.Transaction;
|
|
|
|
import com.wechat.pay.java.service.refund.RefundService;
|
|
|
|
import com.wechat.pay.java.service.refund.RefundService;
|
|
|
|
import com.wechat.pay.java.service.refund.model.*;
|
|
|
|
import com.wechat.pay.java.service.refund.model.*;
|
|
|
|
|
|
|
|
import com.wechat.pay.java.service.refund.model.Refund;
|
|
|
|
import com.yxt.common.base.service.MybatisBaseService;
|
|
|
|
import com.yxt.common.base.service.MybatisBaseService;
|
|
|
|
import com.yxt.common.core.result.ResultBean;
|
|
|
|
import com.yxt.common.core.result.ResultBean;
|
|
|
|
import com.yxt.pay.api.order.PayOrder;
|
|
|
|
import com.yxt.pay.api.order.PayOrder;
|
|
|
|
import com.yxt.pay.api.refund.RefundOrder;
|
|
|
|
import com.yxt.pay.api.refund.*;
|
|
|
|
import com.yxt.pay.api.refund.RefundOrderDto;
|
|
|
|
|
|
|
|
import com.yxt.pay.api.refund.WXRefundOrderReqVo;
|
|
|
|
|
|
|
|
import com.yxt.pay.api.refund.WXRefundOrderRespVo;
|
|
|
|
|
|
|
|
import com.yxt.pay.api.wxpay.WxPayVo;
|
|
|
|
import com.yxt.pay.api.wxpay.WxPayVo;
|
|
|
|
import com.yxt.pay.biz.order.OrderService;
|
|
|
|
import com.yxt.pay.biz.order.OrderService;
|
|
|
|
import com.yxt.pay.utils.UrlComponent;
|
|
|
|
import com.yxt.pay.utils.UrlComponent;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.ServletInputStream;
|
|
|
|
import javax.servlet.ServletInputStream;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
import static com.wechat.pay.java.core.http.Constant.*;
|
|
|
|
import static com.wechat.pay.java.core.http.Constant.*;
|
|
|
|
|
|
|
|
import static java.math.BigDecimal.ROUND_DOWN;
|
|
|
|
|
|
|
|
import static java.math.BigDecimal.ROUND_UP;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @author wangpengfei
|
|
|
|
* @author wangpengfei
|
|
|
|
@@ -64,7 +68,7 @@ public class WxRefundService extends MybatisBaseService<WxRefundMapper,RefundOrd
|
|
|
|
public ResultBean createRefundOrder(RefundOrderDto refundOrderDto){
|
|
|
|
public ResultBean createRefundOrder(RefundOrderDto refundOrderDto){
|
|
|
|
ResultBean rb=new ResultBean();
|
|
|
|
ResultBean rb=new ResultBean();
|
|
|
|
RefundOrder refundOrder=new RefundOrder(refundOrderDto.getSource());
|
|
|
|
RefundOrder refundOrder=new RefundOrder(refundOrderDto.getSource());
|
|
|
|
BeanUtil.copyProperties(refundOrderDto,refundOrder,"id","sid");
|
|
|
|
BeanUtil.copyProperties(refundOrderDto,refundOrder,"id","sid","outTradeNo");
|
|
|
|
baseMapper.insert(refundOrder);
|
|
|
|
baseMapper.insert(refundOrder);
|
|
|
|
return rb.success().setData(refundOrder);
|
|
|
|
return rb.success().setData(refundOrder);
|
|
|
|
|
|
|
|
|
|
|
|
@@ -77,6 +81,7 @@ public class WxRefundService extends MybatisBaseService<WxRefundMapper,RefundOrd
|
|
|
|
* @Author: whl
|
|
|
|
* @Author: whl
|
|
|
|
* @Date: 2023/10/12 15:46
|
|
|
|
* @Date: 2023/10/12 15:46
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
public ResultBean refund(String orderSid) throws Exception {
|
|
|
|
public ResultBean refund(String orderSid) throws Exception {
|
|
|
|
ResultBean rb = ResultBean.fireFail();
|
|
|
|
ResultBean rb = ResultBean.fireFail();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
@@ -103,19 +108,22 @@ public class WxRefundService extends MybatisBaseService<WxRefundMapper,RefundOrd
|
|
|
|
AmountReq amountReq = new AmountReq();
|
|
|
|
AmountReq amountReq = new AmountReq();
|
|
|
|
// PayOrder payOrder=orderService.getOne(new QueryWrapper<PayOrder>().eq("sid",orderSid));
|
|
|
|
// PayOrder payOrder=orderService.getOne(new QueryWrapper<PayOrder>().eq("sid",orderSid));
|
|
|
|
RefundOrder refundOrder=baseMapper.selectOne(new QueryWrapper<RefundOrder>().eq("orderSid",payOrder.getSid()));
|
|
|
|
RefundOrder refundOrder=baseMapper.selectOne(new QueryWrapper<RefundOrder>().eq("orderSid",payOrder.getSid()));
|
|
|
|
|
|
|
|
BigDecimal b=new BigDecimal(refundOrder.getAmount());
|
|
|
|
|
|
|
|
BigDecimal a =new BigDecimal(100);
|
|
|
|
|
|
|
|
String aoum=String.valueOf(b.multiply(a).setScale(0,ROUND_DOWN));
|
|
|
|
//退款金额
|
|
|
|
//退款金额
|
|
|
|
amountReq.setRefund(Long.valueOf(payOrder.getTotalTee()));
|
|
|
|
amountReq.setRefund(Long.valueOf(aoum));
|
|
|
|
// amountReq.setRefund(Long.valueOf("1"));
|
|
|
|
// amountReq.setRefund(Long.valueOf("1"));
|
|
|
|
//原订单金额
|
|
|
|
//原订单金额
|
|
|
|
amountReq.setTotal(Long.valueOf(payOrder.getTotalTee()));
|
|
|
|
amountReq.setTotal(Long.valueOf(aoum));
|
|
|
|
// amountReq.setTotal(Long.valueOf("1"));
|
|
|
|
// amountReq.setTotal(Long.valueOf("1"));
|
|
|
|
//货币类型(默认人民币)
|
|
|
|
//货币类型(默认人民币)
|
|
|
|
amountReq.setCurrency("CNY");
|
|
|
|
amountReq.setCurrency("CNY");
|
|
|
|
request.setAmount(amountReq);
|
|
|
|
request.setAmount(amountReq);
|
|
|
|
//商户退款单号
|
|
|
|
//商户退款单号
|
|
|
|
request.setOutRefundNo(String.valueOf(payOrder.getOutTradeNo()));
|
|
|
|
request.setOutRefundNo(refundOrder.getOutTradeNo());
|
|
|
|
// request.setOutRefundNo(String.valueOf("ceshi"));
|
|
|
|
// request.setOutRefundNo(String.valueOf("ceshi"));
|
|
|
|
request.setOutTradeNo(refundOrder.getOutTradeNo());
|
|
|
|
request.setOutTradeNo(payOrder.getOutTradeNo());
|
|
|
|
// request.setOutTradeNo("ceshi");
|
|
|
|
// request.setOutTradeNo("ceshi");
|
|
|
|
request.setReason(refundOrder.getReason());
|
|
|
|
request.setReason(refundOrder.getReason());
|
|
|
|
// request.setReason("ceshi");
|
|
|
|
// request.setReason("ceshi");
|
|
|
|
@@ -132,10 +140,15 @@ public class WxRefundService extends MybatisBaseService<WxRefundMapper,RefundOrd
|
|
|
|
if (refundResponse.getStatus().equals(Status.SUCCESS)){
|
|
|
|
if (refundResponse.getStatus().equals(Status.SUCCESS)){
|
|
|
|
//说明退款成功,开始接下来的业务操作
|
|
|
|
//说明退款成功,开始接下来的业务操作
|
|
|
|
// WXRefundOrderRespVo refundOrderRespVO = new WXRefundOrderRespVo();
|
|
|
|
// WXRefundOrderRespVo refundOrderRespVO = new WXRefundOrderRespVo();
|
|
|
|
|
|
|
|
payOrder.setState(2);
|
|
|
|
|
|
|
|
orderService.updateById(payOrder);
|
|
|
|
|
|
|
|
refundOrder.setState(2);
|
|
|
|
|
|
|
|
baseMapper.updateById(refundOrder);
|
|
|
|
//你的业务代码
|
|
|
|
//你的业务代码
|
|
|
|
return rb.success().setData(refund);
|
|
|
|
return rb.success().setData(refund);
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
|
|
|
|
payOrder.setState(3);
|
|
|
|
|
|
|
|
orderService.updateById(payOrder);
|
|
|
|
return rb.setMsg("申请退款失败").setData(refund);
|
|
|
|
return rb.setMsg("申请退款失败").setData(refund);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}catch (Exception e){
|
|
|
|
}catch (Exception e){
|
|
|
|
@@ -166,6 +179,7 @@ public class WxRefundService extends MybatisBaseService<WxRefundMapper,RefundOrd
|
|
|
|
stringBuffer.append(s);
|
|
|
|
stringBuffer.append(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String s1 = stringBuffer.toString();
|
|
|
|
String s1 = stringBuffer.toString();
|
|
|
|
|
|
|
|
log.info("退款回调"+s1);
|
|
|
|
String timestamp = request.getHeader(WECHAT_PAY_TIMESTAMP);
|
|
|
|
String timestamp = request.getHeader(WECHAT_PAY_TIMESTAMP);
|
|
|
|
String nonce = request.getHeader(WECHAT_PAY_NONCE);
|
|
|
|
String nonce = request.getHeader(WECHAT_PAY_NONCE);
|
|
|
|
String signType = request.getHeader("Wechatpay-Signature-Type");
|
|
|
|
String signType = request.getHeader("Wechatpay-Signature-Type");
|
|
|
|
@@ -192,14 +206,23 @@ public class WxRefundService extends MybatisBaseService<WxRefundMapper,RefundOrd
|
|
|
|
.body(s1)
|
|
|
|
.body(s1)
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
RefundNotification parse = parser.parse(requestParam, RefundNotification.class);
|
|
|
|
RefundNotification parse = parser.parse(requestParam, RefundNotification.class);
|
|
|
|
|
|
|
|
RefundOrder refundOrder=baseMapper.selectOne(new QueryWrapper<RefundOrder>().eq("outRefundNo",parse.getOutRefundNo()));
|
|
|
|
System.out.println("退款回调结果: " + parse);
|
|
|
|
System.out.println("退款回调结果: " + parse);
|
|
|
|
//parse.getRefundStatus().equals("SUCCESS");说明退款成功
|
|
|
|
//parse.getRefundStatus().equals("SUCCESS");说明退款成功
|
|
|
|
|
|
|
|
RefundBusinessQuery query=new RefundBusinessQuery();
|
|
|
|
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
|
if (parse.getRefundStatus().equals(Transaction.TradeStateEnum.SUCCESS)){
|
|
|
|
if (parse.getRefundStatus().equals(Transaction.TradeStateEnum.SUCCESS)){
|
|
|
|
//你的业务代码
|
|
|
|
//你的业务代码
|
|
|
|
|
|
|
|
map.put("mainSid",refundOrder.getOrderSid());
|
|
|
|
|
|
|
|
map.put("aBoolean",true);
|
|
|
|
|
|
|
|
System.out.println("退款回调结果: " + parse);
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
|
|
|
|
map.put("mainSid",refundOrder.getOrderSid());
|
|
|
|
|
|
|
|
map.put("aBoolean",false);
|
|
|
|
|
|
|
|
System.out.println("退款回调结果: " + parse);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ResponseEntity<ResultBean> postForEntity = new RestTemplate().postForEntity(refundOrder.getReturnUrl(),map, ResultBean.class);
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|