|
@@ -17,9 +17,7 @@ import com.ijpay.core.utils.DateTimeZoneUtil;
|
|
|
import com.ijpay.wxpay.WxPayApi;
|
|
|
import com.ijpay.wxpay.enums.WxDomainEnum;
|
|
|
import com.ijpay.wxpay.enums.v3.BasePayApiEnum;
|
|
|
-import com.ijpay.wxpay.model.v3.Amount;
|
|
|
-import com.ijpay.wxpay.model.v3.Payer;
|
|
|
-import com.ijpay.wxpay.model.v3.UnifiedOrderModel;
|
|
|
+import com.ijpay.wxpay.model.v3.*;
|
|
|
import com.ylx.common.config.WechatAccountConfig;
|
|
|
import com.ylx.common.config.WxPayConfig;
|
|
|
import com.ylx.common.core.domain.R;
|
|
@@ -43,6 +41,8 @@ import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.security.cert.X509Certificate;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import static com.ylx.common.constant.HttpStatus.SUCCESS;
|
|
@@ -174,6 +174,73 @@ public class TRechargeServiceImpl extends ServiceImpl<TRechargeMapper, TRecharge
|
|
|
return R.ok(JSONUtil.toJsonStr(response));
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String refund(String outRefundNo, String transactionId, String outTradeNo, BigDecimal amount) {
|
|
|
+ try {
|
|
|
+
|
|
|
+ int i = amount.multiply(new BigDecimal(100)).intValue();
|
|
|
+
|
|
|
+ log.info("商户退款单号: {}", outRefundNo);
|
|
|
+ //退款商品
|
|
|
+ List<RefundGoodsDetail> list = new ArrayList<>();
|
|
|
+ RefundGoodsDetail refundGoodsDetail = new RefundGoodsDetail()
|
|
|
+ //商户侧商品编码
|
|
|
+ .setMerchant_goods_id("123")
|
|
|
+ //商品名称
|
|
|
+ .setGoods_name("IJPay 测试")
|
|
|
+ //商品单价
|
|
|
+ .setUnit_price(1)
|
|
|
+ //商品退款金额
|
|
|
+ .setRefund_amount(1)
|
|
|
+ //商品退货数量
|
|
|
+ .setRefund_quantity(1);
|
|
|
+ list.add(refundGoodsDetail);
|
|
|
+
|
|
|
+ RefundModel refundModel = new RefundModel()
|
|
|
+ //商户退款单号
|
|
|
+ .setOut_refund_no(outRefundNo)
|
|
|
+ //退款原因
|
|
|
+ //.setReason("IJPay 测试退款")
|
|
|
+ //回调地址
|
|
|
+ .setNotify_url(wxPayProperties.getRefundNotify())
|
|
|
+ //金额信息
|
|
|
+ .setAmount(new RefundAmount().setRefund(i).setTotal(i).setCurrency("CNY"));
|
|
|
+ //退款商品
|
|
|
+ //.setGoods_detail(list);
|
|
|
+
|
|
|
+ //商户订单号
|
|
|
+ if (StrUtil.isNotEmpty(transactionId)) {
|
|
|
+ refundModel.setTransaction_id(transactionId);
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotEmpty(outTradeNo)) {
|
|
|
+ refundModel.setOut_trade_no(outTradeNo);
|
|
|
+ }
|
|
|
+ log.info("退款参数 {}", JSONUtil.toJsonStr(refundModel));
|
|
|
+ IJPayHttpResponse response = WxPayApi.v3(
|
|
|
+ RequestMethodEnum.POST,
|
|
|
+ WxDomainEnum.CHINA.toString(),
|
|
|
+ BasePayApiEnum.REFUND.toString(),
|
|
|
+ wxPayProperties.getMchId(),
|
|
|
+ getSerialNumber(),
|
|
|
+ null,
|
|
|
+ wxPayProperties.getCertKeyPath(),
|
|
|
+ JSONUtil.toJsonStr(refundModel)
|
|
|
+ );
|
|
|
+ // 根据证书序列号查询对应的证书来验证签名结果
|
|
|
+ boolean verifySignature = WxPayKit.verifySignature(response, wxPayProperties.getPlatFormPath());
|
|
|
+ log.info("verifySignature: {}", verifySignature);
|
|
|
+ log.info("退款响应 {}", response);
|
|
|
+
|
|
|
+ if (verifySignature) {
|
|
|
+ return response.getBody();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("系统异常", e);
|
|
|
+ return e.getMessage();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
private String getSerialNumber() {
|
|
|
if (StrUtil.isEmpty(serialNo)) {
|
|
|
// 获取证书序列号
|