|
|
@@ -0,0 +1,168 @@
|
|
|
+/*
|
|
|
+ * Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
|
|
+ *
|
|
|
+ * Redistribution and use in source and binary forms, with or without
|
|
|
+ * modification, are permitted provided that the following conditions are met:
|
|
|
+ *
|
|
|
+ * Redistributions of source code must retain the above copyright notice,
|
|
|
+ * this list of conditions and the following disclaimer.
|
|
|
+ * Redistributions in binary form must reproduce the above copyright
|
|
|
+ * notice, this list of conditions and the following disclaimer in the
|
|
|
+ * documentation and/or other materials provided with the distribution.
|
|
|
+ * Neither the name of the dreamlu.net developer nor the names of its
|
|
|
+ * contributors may be used to endorse or promote products derived from
|
|
|
+ * this software without specific prior written permission.
|
|
|
+ * Author: Chill 庄骞 (smallchill@163.com)
|
|
|
+ */
|
|
|
+package org.springblade.salesPart.payMethod;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springblade.core.secure.utils.AuthUtil;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.pay.tonglianPayment.dto.PaymentDTO;
|
|
|
+import org.springblade.pay.tonglianPayment.entity.Parameters;
|
|
|
+import org.springblade.pay.tonglianPayment.fegin.IPaymentClient;
|
|
|
+import org.springblade.pay.tonglianPayment.fegin.ITongLianPaymentClient;
|
|
|
+import org.springblade.salesPart.entity.PjOrder;
|
|
|
+import org.springblade.salesPart.order.service.IOrderService;
|
|
|
+import org.springblade.system.user.entity.User;
|
|
|
+import org.springblade.system.user.feign.IUserClient;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.TreeMap;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 通联支付实现类
|
|
|
+ *
|
|
|
+ * @author jixinyuan
|
|
|
+ * @since 2023-05-17
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+@Slf4j
|
|
|
+public class PayServiceImpl implements PayService {
|
|
|
+
|
|
|
+ private final ITongLianPaymentClient tongLianPaymentClient;
|
|
|
+
|
|
|
+ private final IPaymentClient paymentClient;
|
|
|
+
|
|
|
+ private final IOrderService orderService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取用户信息
|
|
|
+ */
|
|
|
+ private IUserClient userClient;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R<Map<Object, Object>> payPrepay(Long id, BigDecimal amount, String serialNumber, int status, String goodsNames) {
|
|
|
+ if (null == id) {
|
|
|
+ throw new RuntimeException("未找到订单信息,订单已取消");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (status > 1) {
|
|
|
+ throw new RuntimeException("订单已支付,请不要重复操作");
|
|
|
+ }
|
|
|
+
|
|
|
+ Parameters parameters = tongLianPaymentClient.getParametersOne();
|
|
|
+
|
|
|
+ if (ObjectUtils.isNull(parameters)) {
|
|
|
+ throw new RuntimeException("未找到支付信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ R<User> r = userClient.userInfoById(AuthUtil.getUserId());
|
|
|
+ if (r.isSuccess() && ObjectUtils.isNull(r.getData())) {
|
|
|
+ throw new RuntimeException("未找到用户信息");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ PaymentDTO paymentDTO = new PaymentDTO();
|
|
|
+ paymentDTO.setTrxamt(amount.multiply(new BigDecimal(100)).intValue());
|
|
|
+ paymentDTO.setReqsn(serialNumber);
|
|
|
+ paymentDTO.setPaytype(parameters.getPayType());
|
|
|
+ paymentDTO.setBody("商品-" + goodsNames);
|
|
|
+ paymentDTO.setRemark("");
|
|
|
+ paymentDTO.setAcct(r.getData().getOpenId());
|
|
|
+ paymentDTO.setValidtime(parameters.getValidtime());
|
|
|
+ paymentDTO.setNotify_url(parameters.getNotifyUrl() + "/api/blade-pay/tongLianPayment/callbackNotify");
|
|
|
+ paymentDTO.setLimit_pay("");
|
|
|
+ paymentDTO.setIdno("");
|
|
|
+ paymentDTO.setTruename("");
|
|
|
+ paymentDTO.setAsinfo("");
|
|
|
+ paymentDTO.setSub_appid(parameters.getSubAppid());
|
|
|
+ paymentDTO.setGoods_tag("");
|
|
|
+ paymentDTO.setBenefitdetail("");
|
|
|
+ paymentDTO.setChnlstoreid("");
|
|
|
+ paymentDTO.setSubbranch("");
|
|
|
+ paymentDTO.setExtendparams("");
|
|
|
+ paymentDTO.setCusip(parameters.getCusIp());
|
|
|
+ paymentDTO.setFqnum("");
|
|
|
+ paymentDTO.setCusId(parameters.getCusId());
|
|
|
+ paymentDTO.setAppId(parameters.getAppId());
|
|
|
+ if (ObjectUtils.isEmpty(parameters.getOrgid())) {
|
|
|
+ paymentDTO.setOrgid("");
|
|
|
+ } else {
|
|
|
+ paymentDTO.setOrgid(parameters.getOrgid());
|
|
|
+ }
|
|
|
+ //交易类型
|
|
|
+ paymentDTO.setTransactionType(parameters.getTransactionType());
|
|
|
+ //MD5交易密钥
|
|
|
+ paymentDTO.setSybMdAppkey(parameters.getSybMdAppkey());
|
|
|
+ //RSA公钥
|
|
|
+ paymentDTO.setSybRsacusprikey(parameters.getSybRsacusprikey());
|
|
|
+ //RSA2公钥
|
|
|
+ paymentDTO.setSybRsatlpubkey(parameters.getSybRsatlpubkey());
|
|
|
+ //商户sm2私钥
|
|
|
+ paymentDTO.setSybSmpprivatekey(parameters.getSybSmpprivatekey());
|
|
|
+ //通联平台sm2公钥
|
|
|
+ paymentDTO.setSybSmtlpubkey(parameters.getSybSmtlpubkey());
|
|
|
+ //支付
|
|
|
+ R<Map<Object, Object>> res = paymentClient.payPrepay(paymentDTO);
|
|
|
+ if (res.isSuccess() && ObjectUtils.isNotNull(res.getData())) {
|
|
|
+ PjOrder order = new PjOrder();
|
|
|
+ // 付款
|
|
|
+ order.setActualPaymentStatus(1);
|
|
|
+ order.setPaymentAmountTl(amount.multiply(new BigDecimal(100)));
|
|
|
+ order.setOldTrxId(res.getData().get("trxid").toString());
|
|
|
+ //更新订单表
|
|
|
+ orderService.updateById(order);
|
|
|
+ res.getData().put("id", id);
|
|
|
+ return R.data(res.getData());
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("下单失败");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new RuntimeException("下单失败,error=" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R<Map<String, String>> refund(Long id, BigDecimal amount, String refundSerialNumber, String paySerialNumber, String trxId) {
|
|
|
+ if (null == id) {
|
|
|
+ throw new RuntimeException("未找到订单信息,订单已取消");
|
|
|
+ }
|
|
|
+ Parameters parameters = tongLianPaymentClient.getParametersOne();
|
|
|
+ if (ObjectUtils.isNull(parameters)) {
|
|
|
+ throw new RuntimeException("未找到支付信息");
|
|
|
+ }
|
|
|
+ //微信退款
|
|
|
+ PaymentDTO paymentDTO = new PaymentDTO();
|
|
|
+ paymentDTO.setTrxamt(amount.multiply(new BigDecimal(100)).intValue());
|
|
|
+ paymentDTO.setReqsn(paySerialNumber);
|
|
|
+ paymentDTO.setOldreqsn(refundSerialNumber);
|
|
|
+ paymentDTO.setOldtrxid(trxId);
|
|
|
+ paymentDTO.setCusId(parameters.getCusId());
|
|
|
+ paymentDTO.setAppId(parameters.getAppId());
|
|
|
+ paymentDTO.setOrgid(parameters.getOrgid());
|
|
|
+ paymentDTO.setTransactionType(parameters.getTransactionType());
|
|
|
+ paymentDTO.setSybMdAppkey(parameters.getSybMdAppkey());
|
|
|
+ paymentDTO.setSybRsacusprikey(parameters.getSybRsacusprikey());
|
|
|
+ paymentDTO.setSybRsatlpubkey(parameters.getSybRsatlpubkey());
|
|
|
+ paymentDTO.setSybSmpprivatekey(parameters.getSybSmpprivatekey());
|
|
|
+ paymentDTO.setSybSmtlpubkey(parameters.getSybSmtlpubkey());
|
|
|
+ return paymentClient.refund(paymentDTO);
|
|
|
+ }
|
|
|
+}
|