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:
sqb:
enabled: false
apiDomain: "apiDomain"
terminalSn: "terminalSn"
terminalKey: "terminalKey"
@ -7,13 +8,15 @@ pay:
vendorSn: "vendorSn"
vendorKey: "vendorKey"
alipay:
enabled: false
appId: appId
appPrivateKey: appPrivateKey #classpath:pay/alipay/alipay_private_key.pem
alipayPublicKey: alipayPublicKey #classpath:pay/alipay/alipay_public_key.pem
notifyUrl: http://www.sdaizy.com/prod-api/alipay/notify
wechat:
enabled: false
merchantId: merchantId
privateKeyPath: privateKeyPath
privateKeyPath: privateKeyPath # classpath:pay/wx/apiclient_key.pem
merchantSerialNumber: merchantSerialNumber
apiV3Key: apiV3Key
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.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -18,6 +19,7 @@ import com.alipay.easysdk.kernel.Config;
* @author zlh
*/
@Configuration
@ConditionalOnProperty(prefix = "pay.alipay", name = "enabled", havingValue = "true")
public class AliPayConfig {
@Value("${pay.alipay.appId}")
private String appId;

View File

@ -4,6 +4,7 @@ import java.util.HashMap;
import java.util.Map;
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.PathVariable;
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.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
/**
* @author zlh
*/
@RestController
@RequestMapping("/alipay")
@ConditionalOnProperty(prefix = "pay.alipay", name = "enabled", havingValue = "true")
@Tag(name = "【支付宝】管理")
public class AliPayController {
@ -44,8 +47,11 @@ public class AliPayController {
PayOrder aliPay = payOrderService.selectPayOrderByOrderNumber(orderNumber);
try {
// 发起API调用以创建当面付收款二维码为例
response = Factory.Payment.Page()
.pay(aliPay.getOrderContent(), aliPay.getOrderNumber(), aliPay.getTotalAmount(), "");
response = Factory.Payment.Page().pay(
aliPay.getOrderContent(),
aliPay.getOrderNumber(),
aliPay.getActualAmount(),
"");
} catch (Exception e) {
System.err.println("调用遭遇异常,原因:" + e.getMessage());
throw new RuntimeException(e.getMessage(), e);

View File

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

View File

@ -8,6 +8,7 @@
<result property="orderNumber" column="order_number" />
<result property="orderStatus" column="order_status" />
<result property="totalAmount" column="total_amount" />
<result property="actualAmount" column="actual_amount" />
<result property="orderContent" column="order_content" />
<result property="orderRemark" column="order_remark" />
<result property="orderMessage" column="order_message" />
@ -23,12 +24,10 @@
<if test="orderNumber != null and orderNumber != ''"> and order_number = #{orderNumber}</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="orderContent != null and orderContent != ''"> and order_content =
#{orderContent}</if>
<if test="orderRemark != null and orderRemark != ''"> and order_remark
= #{orderRemark}</if>
<if test="orderMessage != null and orderMessage != ''"> and
order_message = #{orderMessage}</if>
<if test="actualAmount != null and actualAmount != ''"> and actual_amount = #{actualAmount}</if>
<if test="orderContent != null and orderContent != ''"> and order_content = #{orderContent}</if>
<if test="orderRemark != null and orderRemark != ''"> and order_remark = #{orderRemark}</if>
<if test="orderMessage != null and orderMessage != ''"> and order_message = #{orderMessage}</if>
</where>
</select>
@ -47,9 +46,9 @@
<if test="orderId != null">order_id,</if>
<if test="userId != null">user_id,</if>
<if test="orderNumber != null">order_number,</if>
<if test="orderStatus != null">
order_status,</if>
<if test="orderStatus != null">order_status,</if>
<if test="totalAmount != null">total_amount,</if>
<if test="actualAmount != null">actual_amount,</if>
<if test="orderContent != null">order_content,</if>
<if test="orderRemark != null">
order_remark,</if>
@ -59,12 +58,11 @@
<if test="orderId != null">#{orderId},</if>
<if test="userId != null">#{userId},</if>
<if test="orderNumber != null">#{orderNumber},</if>
<if test="orderStatus != null">
#{orderStatus},</if>
<if test="orderStatus != null">#{orderStatus},</if>
<if test="totalAmount != null">#{totalAmount},</if>
<if test="actualAmount != null">#{actualAmount},</if>
<if test="orderContent != null">#{orderContent},</if>
<if test="orderRemark != null">
#{orderRemark},</if>
<if test="orderRemark != null">#{orderRemark},</if>
<if test="orderMessage != null">#{orderMessage},</if>
</trim>
</insert>
@ -72,10 +70,10 @@
<update id="updatePayOrder" parameterType="PayOrder"> update pay_order
<trim prefix="SET" suffixOverrides=",">
<if test="userId != null">user_id = #{userId},</if>
<if test="orderNumber != null">order_number
= #{orderNumber},</if>
<if test="orderNumber != null">order_number = #{orderNumber},</if>
<if test="orderStatus != null">order_status = #{orderStatus},</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="orderRemark != null">order_remark = #{orderRemark},</if>
<if test="orderMessage != null">order_message = #{orderMessage},</if>
@ -91,13 +89,13 @@
</delete>
<delete id="deletePayOrderByOrderIds" parameterType="String">
delete from pay_order where order_id in
delete from pay_order where order_id in
<foreach item="orderId" collection="array" open="(" separator="," close=")">
#{orderId}
#{orderId}
</foreach>
</delete>
<update id="updateStatus" parameterType="String">
update pay_order set order_status = #{orderStatus} where order_number = #{orderNumber}
update pay_order set order_status = #{orderStatus} where order_number = #{orderNumber}
</update>
</mapper>

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.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
@Component
public class SqbConstant {
@ConditionalOnProperty(prefix = "pay.sqb", name = "enabled", havingValue = "true")
public class SqbConfig {
@Value("${pay.sqb.apiDomain}")
private String apiDomain;

View File

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

View File

@ -4,6 +4,7 @@ import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
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.sign.Md5Utils;
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;
@Service
@ConditionalOnProperty(prefix = "pay.sqb", name = "enabled", havingValue = "true")
public class SQBServiceImpl {
@Autowired
private SqbConstant sqbConstant;
private SqbConfig sqbConstant;
/**
* 计算字符串的MD5值
@ -107,7 +109,7 @@ public class SQBServiceImpl {
try {
params.put("terminal_sn", sqbConstant.getTerminalSn()); // 收钱吧终端ID
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("operator", "kay"); // 门店操作员
@ -156,14 +158,14 @@ public class SQBServiceImpl {
"&return_url=" + "https://www.shouqianba.com/" +
"&subject=" + payOrder.getRemark() +
"&terminal_sn=" + sqbConstant.getTerminalSn() +
"&total_amount=" + payOrder.getTotalAmount();
"&total_amount=" + payOrder.getActualAmount();
String urlParam = "" +
"client_sn=" + payOrder.getOrderNumber() +
"&operator=" + URLEncoder.encode("admin", "UTF-8") +
"&return_url=" + "https://www.shouqianba.com/" +
"&subject=" + URLEncoder.encode(payOrder.getRemark(), "UTF-8") +
"&terminal_sn=" + sqbConstant.getTerminalSn() +
"&total_amount=" + payOrder.getTotalAmount();
"&total_amount=" + payOrder.getActualAmount();
String sign = getSign(param + "&key=" + sqbConstant.getTerminalKey());
return "https://qr.shouqianba.com/gateway?" + urlParam + "&sign=" + sign.toUpperCase();
}
@ -179,7 +181,7 @@ public class SQBServiceImpl {
try {
params.put("terminal_sn", sqbConstant.getTerminalSn()); // 收钱吧终端ID
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("subject", "无简介"); // 交易简介
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.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -23,8 +23,8 @@ import com.wechat.pay.java.service.payments.nativepay.NativePayService;
* @author ZlH
*/
@Configuration
@ConfigurationProperties(prefix = "wechat")
public class WxPayAppConfig {
@ConditionalOnProperty(prefix = "pay.wechat", name = "enabled", havingValue = "true")
public class WxPayConfig {
@Value("${pay.wechat.merchantId}")
private String wxchantId;

View File

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

View File

@ -8,6 +8,7 @@ CREATE TABLE `pay_order` (
`order_number` varchar(255) NULL DEFAULT NULL COMMENT '订单号',
`order_status` 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_remark` varchar(255) NULL DEFAULT NULL COMMENT '订单备注',
`order_message` varchar(255) NULL DEFAULT NULL COMMENT '负载信息',