update sqb pay

This commit is contained in:
D 2024-03-05 12:06:16 +08:00
parent da51c58c19
commit 3b4c920ab7
9 changed files with 265 additions and 101 deletions

View File

@ -1,27 +1,31 @@
package com.ruoyi.pay.controller;
import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.pay.domain.PayOrder;
import com.ruoyi.pay.service.IPayOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.ruoyi.pay.utils.SnowflakeIdWorker;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
/**
* 订单Controller
@ -37,6 +41,9 @@ public class PayOrderController extends BaseController
@Autowired
private IPayOrderService payOrderService;
@Autowired
private SnowflakeIdWorker snowflakeidworker;
/**
* 查询订单列表
*/
@ -84,6 +91,8 @@ public class PayOrderController extends BaseController
@PostMapping
public AjaxResult add(@RequestBody PayOrder payOrder)
{
payOrder.setUserId(getUserId());
payOrder.setOrderNumber(snowflakeidworker.nextId().toString());
return toAjax(payOrderService.insertPayOrder(payOrder));
}

View File

@ -1,6 +1,7 @@
package com.ruoyi.pay.mapper;
import java.util.List;
import com.ruoyi.pay.domain.PayOrder;
/**
@ -19,6 +20,14 @@ public interface PayOrderMapper
*/
public PayOrder selectPayOrderByOrderId(Long orderId);
/**
* 查询订单
*
* @param orderNumber 订单号
* @return 订单集合
*/
public PayOrder selectPayOrderByOrderNumber(String orderNumber);
/**
* 查询订单列表
*

View File

@ -1,6 +1,7 @@
package com.ruoyi.pay.service;
import java.util.List;
import com.ruoyi.pay.domain.PayOrder;
/**
@ -9,8 +10,7 @@ import com.ruoyi.pay.domain.PayOrder;
* @author ruoyi
* @date 2024-02-15
*/
public interface IPayOrderService
{
public interface IPayOrderService {
/**
* 查询订单
*
@ -19,6 +19,14 @@ public interface IPayOrderService
*/
public PayOrder selectPayOrderByOrderId(Long orderId);
/**
* 查询订单
*
* @param orderNumber 订单号
* @return 订单集合
*/
public PayOrder selectPayOrderByOrderNumber(String orderNumber);
/**
* 查询订单列表
*

View File

@ -1,10 +1,12 @@
package com.ruoyi.pay.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.pay.mapper.PayOrderMapper;
import com.ruoyi.pay.domain.PayOrder;
import com.ruoyi.pay.mapper.PayOrderMapper;
import com.ruoyi.pay.service.IPayOrderService;
/**
@ -14,8 +16,7 @@ import com.ruoyi.pay.service.IPayOrderService;
* @date 2024-02-15
*/
@Service
public class PayOrderServiceImpl implements IPayOrderService
{
public class PayOrderServiceImpl implements IPayOrderService {
@Autowired
private PayOrderMapper payOrderMapper;
@ -26,11 +27,21 @@ public class PayOrderServiceImpl implements IPayOrderService
* @return 订单
*/
@Override
public PayOrder selectPayOrderByOrderId(Long orderId)
{
public PayOrder selectPayOrderByOrderId(Long orderId) {
return payOrderMapper.selectPayOrderByOrderId(orderId);
}
/**
* 查询订单
*
* @param orderNumber 订单号
* @return 订单集合
*/
@Override
public PayOrder selectPayOrderByOrderNumber(String orderNumber) {
return payOrderMapper.selectPayOrderByOrderNumber(orderNumber);
}
/**
* 查询订单列表
*
@ -38,8 +49,7 @@ public class PayOrderServiceImpl implements IPayOrderService
* @return 订单
*/
@Override
public List<PayOrder> selectPayOrderList(PayOrder payOrder)
{
public List<PayOrder> selectPayOrderList(PayOrder payOrder) {
return payOrderMapper.selectPayOrderList(payOrder);
}
@ -50,8 +60,7 @@ public class PayOrderServiceImpl implements IPayOrderService
* @return 结果
*/
@Override
public int insertPayOrder(PayOrder payOrder)
{
public int insertPayOrder(PayOrder payOrder) {
return payOrderMapper.insertPayOrder(payOrder);
}
@ -62,8 +71,7 @@ public class PayOrderServiceImpl implements IPayOrderService
* @return 结果
*/
@Override
public int updatePayOrder(PayOrder payOrder)
{
public int updatePayOrder(PayOrder payOrder) {
return payOrderMapper.updatePayOrder(payOrder);
}
@ -74,8 +82,7 @@ public class PayOrderServiceImpl implements IPayOrderService
* @return 结果
*/
@Override
public int deletePayOrderByOrderIds(Long[] orderIds)
{
public int deletePayOrderByOrderIds(Long[] orderIds) {
return payOrderMapper.deletePayOrderByOrderIds(orderIds);
}
@ -86,8 +93,7 @@ public class PayOrderServiceImpl implements IPayOrderService
* @return 结果
*/
@Override
public int deletePayOrderByOrderId(Long orderId)
{
public int deletePayOrderByOrderId(Long orderId) {
return payOrderMapper.deletePayOrderByOrderId(orderId);
}
}

View File

@ -0,0 +1,79 @@
package com.ruoyi.pay.utils;
import org.springframework.stereotype.Component;
@Component
public class SnowflakeIdWorker {
// 开始时间戳2015-01-01
private final long twepoch = 1420041600000L;
// 机器id所占的位数
private final long workerIdBits = 5L;
// 数据标识id所占的位数
private final long datacenterIdBits = 5L;
// 支持的最大机器id结果是31二进制11111
private final long maxWorkerId = -1L ^ (-1L << workerIdBits);
// 支持的最大数据标识id结果是31二进制11111
private final long maxDatacenterId = -1L ^ (-1L << datacenterIdBits);
// 序列在id中占的位数
private final long sequenceBits = 12L;
// 机器ID向左移12位
private final long workerIdShift = sequenceBits;
// 数据标识id向左移17位12+5
private final long datacenterIdShift = sequenceBits + workerIdBits;
// 时间戳向左移22位5+5+12
private final long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;
// 生成序列的掩码这里为4095二进制111111111111
private final long sequenceMask = -1L ^ (-1L << sequenceBits);
// 工作机器ID0~31
private long workerId;
// 数据中心ID0~31
private long datacenterId;
// 毫秒内序列0~4095
private long sequence = 0L;
// 上次生成ID的时间戳
private long lastTimestamp = -1L;
public SnowflakeIdWorker() {
this(0,0);
}
public SnowflakeIdWorker(long workerId, long datacenterId) {
if (workerId > maxWorkerId || workerId < 0) {
throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", maxWorkerId));
}
if (datacenterId > maxDatacenterId || datacenterId < 0) {
throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId));
}
this.workerId = workerId;
this.datacenterId = datacenterId;
}
public synchronized Long nextId() {
long timestamp = timeGen();
if (timestamp < lastTimestamp) {
throw new RuntimeException(String.format("Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
}
if (lastTimestamp == timestamp) {
sequence = (sequence + 1) & sequenceMask;
if (sequence == 0) {
timestamp = tilNextMillis(lastTimestamp);
}
} else {
sequence = 0L;
}
lastTimestamp = timestamp;
return ((timestamp - twepoch) << timestampLeftShift) | (datacenterId << datacenterIdShift) | (workerId << workerIdShift) | sequence;
}
protected Long tilNextMillis(long lastTimestamp) {
long timestamp = timeGen();
while (timestamp <= lastTimestamp) {
timestamp = timeGen();
}
return timestamp;
}
protected long timeGen() {
return System.currentTimeMillis();
}
}

View File

@ -1,7 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.pay.mapper.PayOrderMapper">
<resultMap type="PayOrder" id="PayOrderResult">
@ -15,74 +13,89 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="orderMessage" column="order_message" />
</resultMap>
<sql id="selectPayOrderVo">
select order_id, user_id, order_number, order_status, total_amount, order_content, order_remark, order_message from pay_order
</sql>
<sql id="selectPayOrderVo"> select order_id, user_id, order_number, order_status, total_amount,
order_content, order_remark, order_message from pay_order </sql>
<select id="selectPayOrderList" parameterType="PayOrder" resultMap="PayOrderResult">
<include refid="selectPayOrderVo"/>
<include refid="selectPayOrderVo" />
<where>
<if test="userId != null "> and user_id = #{userId}</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="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="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>
</where>
</select>
<select id="selectPayOrderByOrderId" parameterType="Long" resultMap="PayOrderResult">
<include refid="selectPayOrderVo"/>
where pay_order.order_id = #{orderId}
</select>
<include refid="selectPayOrderVo" /> where pay_order.order_id = #{orderId} </select>
<insert id="insertPayOrder" parameterType="PayOrder">
insert into pay_order
<trim prefix="(" suffix=")" suffixOverrides=",">
<select id="selectPayOrderByOrderNumber" parameterType="String" resultMap="PayOrderResult">
<include refid="selectPayOrderVo" /> where pay_order.order_number = #{orderNumber} </select>
<insert id="insertPayOrder" parameterType="PayOrder"> insert into pay_order <trim prefix="("
suffix=")" suffixOverrides=",">
<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="orderNumber != null">order_number,</if>
<if test="orderStatus != null">
order_status,</if>
<if test="totalAmount != null">total_amount,</if>
<if test="orderContent != null">order_content,</if>
<if test="orderRemark != null">order_remark,</if>
<if
test="orderContent != null">order_content,</if>
<if test="orderRemark != null">
order_remark,</if>
<if test="orderMessage != null">order_message,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<trim
prefix="values (" suffix=")" suffixOverrides=",">
<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="orderNumber != null">#{orderNumber},</if>
<if test="orderStatus != null">
#{orderStatus},</if>
<if test="totalAmount != null">#{totalAmount},</if>
<if test="orderContent != null">#{orderContent},</if>
<if test="orderRemark != null">#{orderRemark},</if>
<if
test="orderContent != null">#{orderContent},</if>
<if test="orderRemark != null">
#{orderRemark},</if>
<if test="orderMessage != null">#{orderMessage},</if>
</trim>
</insert>
<update id="updatePayOrder" parameterType="PayOrder">
update pay_order
<trim prefix="SET" suffixOverrides=",">
<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="orderContent != null">order_content = #{orderContent},</if>
<if test="orderRemark != null">order_remark = #{orderRemark},</if>
<if test="orderMessage != null">order_message = #{orderMessage},</if>
<if
test="totalAmount != null">total_amount = #{totalAmount},</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>
</trim>
where pay_order.order_id = #{orderId}
</update>
where pay_order.order_id = #{orderId} </update>
<delete id="deletePayOrderByOrderId" parameterType="Long">
delete from pay_order where order_id = #{orderId}
</delete>
<delete id="deletePayOrderByOrderId" parameterType="Long"> delete from pay_order where order_id
= #{orderId} </delete>
<delete id="deletePayOrderByOrderIds" parameterType="String">
delete from pay_order where order_id in
<foreach item="orderId" collection="array" open="(" separator="," close=")">
#{orderId}
</foreach>
<delete id="deletePayOrderByOrderIds" parameterType="String"> delete from pay_order where
order_id in <foreach item="orderId" collection="array" open="(" separator="," close=")">
#{orderId} </foreach>
</delete>
</mapper>

View File

@ -23,6 +23,12 @@
<artifactId>ruoyi-common</artifactId>
</dependency>
<!-- 支付基础模块-->
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-pay-common</artifactId>
</dependency>
<!--httpclient-->
<dependency>
<groupId>org.apache.httpcomponents</groupId>

View File

@ -0,0 +1,33 @@
package com.ruoyi.pay.sqb.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Anonymous;
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.sqb.service.Impl.SQBServiceImpl;
@RestController
@RequestMapping("/pay/sql")
public class SQBController extends BaseController {
@Autowired
private SQBServiceImpl sqbServiceImpl;
@Autowired
private IPayOrderService payOrderServicer;
@PostMapping("/payUrl")
@Anonymous
public AjaxResult postMethodName(@RequestParam("id") String orderNumber) throws Exception {
PayOrder payOrder = payOrderServicer.selectPayOrderByOrderNumber(orderNumber);
String url = sqbServiceImpl.payUrl(payOrder);
AjaxResult ajaxResult = new AjaxResult(200,url,"操作成功");
return ajaxResult;
}
}

View File

@ -9,6 +9,7 @@ import org.springframework.stereotype.Service;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
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.utils.HttpUtil;
@ -99,8 +100,7 @@ public class SQBServiceImpl {
*
* @return
*/
public String refund(String clientSn, String total, String payway, String subject, String operator,
String terminalSn) {
public String refund(String clientSn, String total, String payway, String subject, String operator) {
String url = sqbConstant.getApiDomain() + "/upay/v2/refund";
JSONObject params = new JSONObject();
try {
@ -125,8 +125,7 @@ public class SQBServiceImpl {
* @return
*/
public String query(String clientSn, String total, String payway, String subject, String operator,
String terminalSn) {
public String query(String clientSn, String total, String payway, String subject, String operator) {
String url = sqbConstant.getApiDomain() + "/upay/v2/query";
JSONObject params = new JSONObject();
try {
@ -146,22 +145,24 @@ public class SQBServiceImpl {
}
}
public String payUrl(String clientSn, String total, String payway, String subject, String operator,
String terminalSn) throws UnsupportedEncodingException {
public String payUrl(PayOrder payOrder) throws UnsupportedEncodingException {
if(payOrder.getRemark() == null){
payOrder.setRemark("支付");
}
String param = "" +
"client_sn=" + clientSn +
"&operator=" + operator +
"client_sn=" + payOrder.getOrderNumber() +
"&operator=" + "admin" +
"&return_url=" + "https://www.shouqianba.com/" +
"&subject=" + subject +
"&terminal_sn=" + terminalSn +
"&total_amount=" + total;
"&subject=" + payOrder.getRemark() +
"&terminal_sn=" + sqbConstant.getTerminalSn() +
"&total_amount=" + payOrder.getTotalAmount();
String urlParam = "" +
"client_sn=" + clientSn +
"&operator=" + URLEncoder.encode(operator, "UTF-8") +
"client_sn=" + payOrder.getOrderNumber() +
"&operator=" + URLEncoder.encode("admin", "UTF-8") +
"&return_url=" + "https://www.shouqianba.com/" +
"&subject=" + URLEncoder.encode(subject, "UTF-8") +
"&terminal_sn=" + terminalSn +
"&total_amount=" + total;
"&subject=" + URLEncoder.encode(payOrder.getRemark(), "UTF-8") +
"&terminal_sn=" + sqbConstant.getTerminalSn() +
"&total_amount=" + payOrder.getTotalAmount();
String sign = getSign(param + "&key=" + sqbConstant.getTerminalKey());
return "https://qr.shouqianba.com/gateway?" + urlParam + "&sign=" + sign.toUpperCase();
}