This commit is contained in:
Dftre 2024-06-06 17:19:05 +08:00
parent bbceb171eb
commit 63cf1fee47
11 changed files with 67 additions and 35 deletions

View File

@ -1,5 +1,6 @@
pay: pay:
sqb: sqb:
enabled: false
apiDomain: "apiDomain" apiDomain: "apiDomain"
terminalSn: "terminalSn" terminalSn: "terminalSn"
terminalKey: "terminalKey" terminalKey: "terminalKey"
@ -7,13 +8,15 @@ pay:
vendorSn: "vendorSn" vendorSn: "vendorSn"
vendorKey: "vendorKey" vendorKey: "vendorKey"
alipay: alipay:
enabled: false
appId: appId appId: appId
appPrivateKey: appPrivateKey #classpath:pay/alipay/alipay_private_key.pem appPrivateKey: appPrivateKey #classpath:pay/alipay/alipay_private_key.pem
alipayPublicKey: alipayPublicKey #classpath:pay/alipay/alipay_public_key.pem alipayPublicKey: alipayPublicKey #classpath:pay/alipay/alipay_public_key.pem
notifyUrl: http://www.sdaizy.com/prod-api/alipay/notify notifyUrl: http://www.sdaizy.com/prod-api/alipay/notify
wechat: wechat:
enabled: false
merchantId: merchantId merchantId: merchantId
privateKeyPath: privateKeyPath privateKeyPath: privateKeyPath # classpath:pay/wx/apiclient_key.pem
merchantSerialNumber: merchantSerialNumber merchantSerialNumber: merchantSerialNumber
apiV3Key: apiV3Key apiV3Key: apiV3Key
appId: appId appId: appId

View File

@ -7,6 +7,7 @@ import java.util.stream.Collectors;
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.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -18,6 +19,7 @@ import com.alipay.easysdk.kernel.Config;
* @author zlh * @author zlh
*/ */
@Configuration @Configuration
@ConditionalOnProperty(prefix = "pay.alipay", name = "enabled", havingValue = "true")
public class AliPayConfig { public class AliPayConfig {
@Value("${pay.alipay.appId}") @Value("${pay.alipay.appId}")
private String appId; private String appId;

View File

@ -4,6 +4,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
@ -22,11 +23,13 @@ import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
/** /**
* @author zlh * @author zlh
*/ */
@RestController @RestController
@RequestMapping("/alipay") @RequestMapping("/alipay")
@ConditionalOnProperty(prefix = "pay.alipay", name = "enabled", havingValue = "true")
@Tag(name = "【支付宝】管理") @Tag(name = "【支付宝】管理")
public class AliPayController { public class AliPayController {
@ -44,8 +47,11 @@ public class AliPayController {
PayOrder aliPay = payOrderService.selectPayOrderByOrderNumber(orderNumber); PayOrder aliPay = payOrderService.selectPayOrderByOrderNumber(orderNumber);
try { try {
// 发起API调用以创建当面付收款二维码为例 // 发起API调用以创建当面付收款二维码为例
response = Factory.Payment.Page() response = Factory.Payment.Page().pay(
.pay(aliPay.getOrderContent(), aliPay.getOrderNumber(), aliPay.getTotalAmount(), ""); aliPay.getOrderContent(),
aliPay.getOrderNumber(),
aliPay.getActualAmount(),
"");
} catch (Exception e) { } catch (Exception e) {
System.err.println("调用遭遇异常,原因:" + e.getMessage()); System.err.println("调用遭遇异常,原因:" + e.getMessage());
throw new RuntimeException(e.getMessage(), e); throw new RuntimeException(e.getMessage(), e);

View File

@ -42,6 +42,11 @@ public class PayOrder extends BaseEntity {
@Excel(name = "订单总金额") @Excel(name = "订单总金额")
private String totalAmount; private String totalAmount;
/** 订单总金额 */
@Schema(title = "实际支付金额")
@Excel(name = "实际支付金额")
private String actualAmount;
/** 订单内容 */ /** 订单内容 */
@Schema(title = "订单内容") @Schema(title = "订单内容")
@Excel(name = "订单内容") @Excel(name = "订单内容")
@ -97,6 +102,14 @@ public class PayOrder extends BaseEntity {
return totalAmount; return totalAmount;
} }
public String getActualAmount() {
return actualAmount;
}
public void setActualAmount(String actualAmount) {
this.actualAmount = actualAmount;
}
public void setOrderContent(String orderContent) { public void setOrderContent(String orderContent) {
this.orderContent = orderContent; this.orderContent = orderContent;
} }
@ -129,6 +142,7 @@ public class PayOrder extends BaseEntity {
.append("orderNumber", getOrderNumber()) .append("orderNumber", getOrderNumber())
.append("orderStatus", getOrderStatus()) .append("orderStatus", getOrderStatus())
.append("totalAmount", getTotalAmount()) .append("totalAmount", getTotalAmount())
.append("actualAmount", getActualAmount())
.append("orderContent", getOrderContent()) .append("orderContent", getOrderContent())
.append("orderRemark", getOrderRemark()) .append("orderRemark", getOrderRemark())
.append("orderMessage", getOrderMessage()) .append("orderMessage", getOrderMessage())

View File

@ -8,6 +8,7 @@
<result property="orderNumber" column="order_number" /> <result property="orderNumber" column="order_number" />
<result property="orderStatus" column="order_status" /> <result property="orderStatus" column="order_status" />
<result property="totalAmount" column="total_amount" /> <result property="totalAmount" column="total_amount" />
<result property="actualAmount" column="actual_amount" />
<result property="orderContent" column="order_content" /> <result property="orderContent" column="order_content" />
<result property="orderRemark" column="order_remark" /> <result property="orderRemark" column="order_remark" />
<result property="orderMessage" column="order_message" /> <result property="orderMessage" column="order_message" />
@ -23,12 +24,10 @@
<if test="orderNumber != null and orderNumber != ''"> and order_number = #{orderNumber}</if> <if test="orderNumber != null and orderNumber != ''"> and order_number = #{orderNumber}</if>
<if test="orderStatus != null and orderStatus != ''"> and order_status = #{orderStatus}</if> <if test="orderStatus != null and orderStatus != ''"> and order_status = #{orderStatus}</if>
<if test="totalAmount != null and totalAmount != ''"> and total_amount = #{totalAmount}</if> <if test="totalAmount != null and totalAmount != ''"> and total_amount = #{totalAmount}</if>
<if test="orderContent != null and orderContent != ''"> and order_content = <if test="actualAmount != null and actualAmount != ''"> and actual_amount = #{actualAmount}</if>
#{orderContent}</if> <if test="orderContent != null and orderContent != ''"> and order_content = #{orderContent}</if>
<if test="orderRemark != null and orderRemark != ''"> and order_remark <if test="orderRemark != null and orderRemark != ''"> and order_remark = #{orderRemark}</if>
= #{orderRemark}</if> <if test="orderMessage != null and orderMessage != ''"> and order_message = #{orderMessage}</if>
<if test="orderMessage != null and orderMessage != ''"> and
order_message = #{orderMessage}</if>
</where> </where>
</select> </select>
@ -47,9 +46,9 @@
<if test="orderId != null">order_id,</if> <if test="orderId != null">order_id,</if>
<if test="userId != null">user_id,</if> <if test="userId != null">user_id,</if>
<if test="orderNumber != null">order_number,</if> <if test="orderNumber != null">order_number,</if>
<if test="orderStatus != null"> <if test="orderStatus != null">order_status,</if>
order_status,</if>
<if test="totalAmount != null">total_amount,</if> <if test="totalAmount != null">total_amount,</if>
<if test="actualAmount != null">actual_amount,</if>
<if test="orderContent != null">order_content,</if> <if test="orderContent != null">order_content,</if>
<if test="orderRemark != null"> <if test="orderRemark != null">
order_remark,</if> order_remark,</if>
@ -59,12 +58,11 @@
<if test="orderId != null">#{orderId},</if> <if test="orderId != null">#{orderId},</if>
<if test="userId != null">#{userId},</if> <if test="userId != null">#{userId},</if>
<if test="orderNumber != null">#{orderNumber},</if> <if test="orderNumber != null">#{orderNumber},</if>
<if test="orderStatus != null"> <if test="orderStatus != null">#{orderStatus},</if>
#{orderStatus},</if>
<if test="totalAmount != null">#{totalAmount},</if> <if test="totalAmount != null">#{totalAmount},</if>
<if test="actualAmount != null">#{actualAmount},</if>
<if test="orderContent != null">#{orderContent},</if> <if test="orderContent != null">#{orderContent},</if>
<if test="orderRemark != null"> <if test="orderRemark != null">#{orderRemark},</if>
#{orderRemark},</if>
<if test="orderMessage != null">#{orderMessage},</if> <if test="orderMessage != null">#{orderMessage},</if>
</trim> </trim>
</insert> </insert>
@ -72,10 +70,10 @@
<update id="updatePayOrder" parameterType="PayOrder"> update pay_order <update id="updatePayOrder" parameterType="PayOrder"> update pay_order
<trim prefix="SET" suffixOverrides=","> <trim prefix="SET" suffixOverrides=",">
<if test="userId != null">user_id = #{userId},</if> <if test="userId != null">user_id = #{userId},</if>
<if test="orderNumber != null">order_number <if test="orderNumber != null">order_number = #{orderNumber},</if>
= #{orderNumber},</if>
<if test="orderStatus != null">order_status = #{orderStatus},</if> <if test="orderStatus != null">order_status = #{orderStatus},</if>
<if test="totalAmount != null">total_amount = #{totalAmount},</if> <if test="totalAmount != null">total_amount = #{totalAmount},</if>
<if test="actualAmount != null">actual_amount = #{actualAmount},</if>
<if test="orderContent != null">order_content = #{orderContent},</if> <if test="orderContent != null">order_content = #{orderContent},</if>
<if test="orderRemark != null">order_remark = #{orderRemark},</if> <if test="orderRemark != null">order_remark = #{orderRemark},</if>
<if test="orderMessage != null">order_message = #{orderMessage},</if> <if test="orderMessage != null">order_message = #{orderMessage},</if>

View File

@ -1,10 +1,12 @@
package com.ruoyi.pay.sqb.constant; package com.ruoyi.pay.sqb.config;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
public class SqbConstant { @ConditionalOnProperty(prefix = "pay.sqb", name = "enabled", havingValue = "true")
public class SqbConfig {
@Value("${pay.sqb.apiDomain}") @Value("${pay.sqb.apiDomain}")
private String apiDomain; private String apiDomain;

View File

@ -1,6 +1,7 @@
package com.ruoyi.pay.sqb.controller; package com.ruoyi.pay.sqb.controller;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -24,6 +25,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
@Tag(name = "sqb支付") @Tag(name = "sqb支付")
@RestController @RestController
@RequestMapping("/pay/sql") @RequestMapping("/pay/sql")
@ConditionalOnProperty(prefix = "pay.sqb", name = "enabled", havingValue = "true")
public class SQBController extends BaseController { public class SQBController extends BaseController {
@Autowired @Autowired
private SQBServiceImpl sqbServiceImpl; private SQBServiceImpl sqbServiceImpl;

View File

@ -4,6 +4,7 @@ import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLEncoder;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
@ -11,13 +12,14 @@ import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.sign.Md5Utils; import com.ruoyi.common.utils.sign.Md5Utils;
import com.ruoyi.pay.domain.PayOrder; import com.ruoyi.pay.domain.PayOrder;
import com.ruoyi.pay.sqb.constant.SqbConstant; import com.ruoyi.pay.sqb.config.SqbConfig;
import com.ruoyi.pay.sqb.utils.HttpUtil; import com.ruoyi.pay.sqb.utils.HttpUtil;
@Service @Service
@ConditionalOnProperty(prefix = "pay.sqb", name = "enabled", havingValue = "true")
public class SQBServiceImpl { public class SQBServiceImpl {
@Autowired @Autowired
private SqbConstant sqbConstant; private SqbConfig sqbConstant;
/** /**
* 计算字符串的MD5值 * 计算字符串的MD5值
@ -107,7 +109,7 @@ public class SQBServiceImpl {
try { try {
params.put("terminal_sn", sqbConstant.getTerminalSn()); // 收钱吧终端ID params.put("terminal_sn", sqbConstant.getTerminalSn()); // 收钱吧终端ID
params.put("client_sn", payOrder.getOrderNumber()); // 商户系统订单号,必须在商户系统内唯一且长度不超过64字节 params.put("client_sn", payOrder.getOrderNumber()); // 商户系统订单号,必须在商户系统内唯一且长度不超过64字节
params.put("refund_amount", payOrder.getTotalAmount()); // 退款金额 params.put("refund_amount", payOrder.getActualAmount()); // 退款金额
params.put("refund_request_no", "1"); // 商户退款所需序列号,表明是第几次退款 params.put("refund_request_no", "1"); // 商户退款所需序列号,表明是第几次退款
params.put("operator", "kay"); // 门店操作员 params.put("operator", "kay"); // 门店操作员
@ -156,14 +158,14 @@ public class SQBServiceImpl {
"&return_url=" + "https://www.shouqianba.com/" + "&return_url=" + "https://www.shouqianba.com/" +
"&subject=" + payOrder.getRemark() + "&subject=" + payOrder.getRemark() +
"&terminal_sn=" + sqbConstant.getTerminalSn() + "&terminal_sn=" + sqbConstant.getTerminalSn() +
"&total_amount=" + payOrder.getTotalAmount(); "&total_amount=" + payOrder.getActualAmount();
String urlParam = "" + String urlParam = "" +
"client_sn=" + payOrder.getOrderNumber() + "client_sn=" + payOrder.getOrderNumber() +
"&operator=" + URLEncoder.encode("admin", "UTF-8") + "&operator=" + URLEncoder.encode("admin", "UTF-8") +
"&return_url=" + "https://www.shouqianba.com/" + "&return_url=" + "https://www.shouqianba.com/" +
"&subject=" + URLEncoder.encode(payOrder.getRemark(), "UTF-8") + "&subject=" + URLEncoder.encode(payOrder.getRemark(), "UTF-8") +
"&terminal_sn=" + sqbConstant.getTerminalSn() + "&terminal_sn=" + sqbConstant.getTerminalSn() +
"&total_amount=" + payOrder.getTotalAmount(); "&total_amount=" + payOrder.getActualAmount();
String sign = getSign(param + "&key=" + sqbConstant.getTerminalKey()); String sign = getSign(param + "&key=" + sqbConstant.getTerminalKey());
return "https://qr.shouqianba.com/gateway?" + urlParam + "&sign=" + sign.toUpperCase(); return "https://qr.shouqianba.com/gateway?" + urlParam + "&sign=" + sign.toUpperCase();
} }
@ -179,7 +181,7 @@ public class SQBServiceImpl {
try { try {
params.put("terminal_sn", sqbConstant.getTerminalSn()); // 收钱吧终端ID params.put("terminal_sn", sqbConstant.getTerminalSn()); // 收钱吧终端ID
params.put("client_sn", payOrder.getOrderNumber()); // 商户系统订单号,必须在商户系统内唯一且长度不超过32字节 params.put("client_sn", payOrder.getOrderNumber()); // 商户系统订单号,必须在商户系统内唯一且长度不超过32字节
params.put("total_amount", payOrder.getTotalAmount()); // 交易总金额 params.put("total_amount", payOrder.getActualAmount()); // 交易总金额
// params.put("payway", payway); // 支付方式 // params.put("payway", payway); // 支付方式
params.put("subject", "无简介"); // 交易简介 params.put("subject", "无简介"); // 交易简介
params.put("operator", SecurityUtils.getUsername()); // 门店操作员 params.put("operator", SecurityUtils.getUsername()); // 门店操作员

View File

@ -7,7 +7,7 @@ import java.nio.file.StandardCopyOption;
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.boot.context.properties.ConfigurationProperties; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -23,8 +23,8 @@ import com.wechat.pay.java.service.payments.nativepay.NativePayService;
* @author ZlH * @author ZlH
*/ */
@Configuration @Configuration
@ConfigurationProperties(prefix = "wechat") @ConditionalOnProperty(prefix = "pay.wechat", name = "enabled", havingValue = "true")
public class WxPayAppConfig { public class WxPayConfig {
@Value("${pay.wechat.merchantId}") @Value("${pay.wechat.merchantId}")
private String wxchantId; private String wxchantId;

View File

@ -4,6 +4,7 @@ import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.util.StreamUtils; import org.springframework.util.StreamUtils;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
@ -16,7 +17,7 @@ import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.pay.domain.PayOrder; import com.ruoyi.pay.domain.PayOrder;
import com.ruoyi.pay.service.IPayOrderService; import com.ruoyi.pay.service.IPayOrderService;
import com.ruoyi.pay.wx.config.WxPayAppConfig; import com.ruoyi.pay.wx.config.WxPayConfig;
import com.wechat.pay.java.core.exception.ValidationException; import com.wechat.pay.java.core.exception.ValidationException;
import com.wechat.pay.java.core.notification.NotificationParser; import com.wechat.pay.java.core.notification.NotificationParser;
import com.wechat.pay.java.core.notification.RequestParam; import com.wechat.pay.java.core.notification.RequestParam;
@ -38,10 +39,11 @@ import lombok.extern.slf4j.Slf4j;
*/ */
@Slf4j @Slf4j
@RestController @RestController
@ConditionalOnProperty(prefix = "pay.wechat", name = "enabled", havingValue = "true")
@RequestMapping("/wxPay") @RequestMapping("/wxPay")
public class WxAppPayController extends BaseController { public class WxPayController extends BaseController {
@Autowired @Autowired
private WxPayAppConfig wxPayAppConfig; private WxPayConfig wxPayAppConfig;
@Autowired @Autowired
private IPayOrderService payOrderService; private IPayOrderService payOrderService;
@ -57,7 +59,7 @@ public class WxAppPayController extends BaseController {
@GetMapping("/pay/{orderNumber}") @GetMapping("/pay/{orderNumber}")
public AjaxResult pay(@PathVariable String orderNumber) throws Exception { public AjaxResult pay(@PathVariable String orderNumber) throws Exception {
PayOrder aliPay = payOrderService.selectPayOrderByOrderNumber(orderNumber); PayOrder aliPay = payOrderService.selectPayOrderByOrderNumber(orderNumber);
String amountStr = aliPay.getTotalAmount(); String amountStr = aliPay.getActualAmount();
double amountDouble = Double.parseDouble(amountStr); double amountDouble = Double.parseDouble(amountStr);
int totalAmountInt = (int) (amountDouble * 100); int totalAmountInt = (int) (amountDouble * 100);
PrepayRequest request = new PrepayRequest(); PrepayRequest request = new PrepayRequest();

View File

@ -8,6 +8,7 @@ CREATE TABLE `pay_order` (
`order_number` varchar(255) NULL DEFAULT NULL COMMENT '订单号', `order_number` varchar(255) NULL DEFAULT NULL COMMENT '订单号',
`order_status` varchar(255) NULL DEFAULT NULL COMMENT '订单状态', `order_status` varchar(255) NULL DEFAULT NULL COMMENT '订单状态',
`total_amount` varchar(255) NULL DEFAULT NULL COMMENT '订单总金额', `total_amount` varchar(255) NULL DEFAULT NULL COMMENT '订单总金额',
`actual_amount` varchar(255) NULL DEFAULT NULL COMMENT '实际支付金额',
`order_content` varchar(255) NULL DEFAULT NULL COMMENT '订单内容', `order_content` varchar(255) NULL DEFAULT NULL COMMENT '订单内容',
`order_remark` varchar(255) NULL DEFAULT NULL COMMENT '订单备注', `order_remark` varchar(255) NULL DEFAULT NULL COMMENT '订单备注',
`order_message` varchar(255) NULL DEFAULT NULL COMMENT '负载信息', `order_message` varchar(255) NULL DEFAULT NULL COMMENT '负载信息',