springboot实现沙箱支付退款

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>商城与订单管理</title>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/uuid/8.3.2/uuid.min.js"></script>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f0f2f5;
        }
        #app {
            width: 100%;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            align-items: center;
        }
        .page-header {
            background-color: #409EFF;
            color: white;
            padding: 20px;
            text-align: center;
            width: 100%;
            box-sizing: border-box;
        }
        .page-title {
            margin: 0;
        }
        .content-wrapper {
            width: 100%;
            display: flex;
            justify-content: center;
            padding: 20px;
            box-sizing: border-box;
        }
        .content-area {
            width: 1080px;
            background-color: #fff;
            padding: 20px;
            box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
        }
        .nav-buttons {
            margin-bottom: 20px;
        }
        .el-table {
            margin-top: 20px;
        }
    </style>
</head>
<body>
<div id="app">
    <header class="page-header">
        <h1 class="page-title">基于内存_SpringBoot实现沙箱支付退款_商城与订单管理系统</h1>
    </header>
    <div class="content-wrapper">
        <div class="content-area">
            <div class="nav-buttons">
                <el-button @click="showProducts" type="primary" :plain="!isProductView">商品列表</el-button>
                <el-button @click="showOrders" type="primary" :plain="isProductView">订单管理</el-button>
            </div>
            <div v-if="isProductView">
                <el-table :data="products" style="width: 100%">
                    <el-table-column prop="id" label="商品编号" width="120"></el-table-column>
                    <el-table-column prop="name" label="商品名称"></el-table-column>
                    <el-table-column prop="total" label="金额" width="120"></el-table-column>
                    <el-table-column label="操作" width="120" align="center">
                        <template slot-scope="scope">
                            <el-button @click="buy(scope.row)" type="primary" size="small">购买</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <div v-else>
                <el-table :data="orders" style="width: 100%">
                    <el-table-column prop="traceNo" label="订单号" width="180"></el-table-column>
                    <el-table-column prop="subject" label="商品名称"></el-table-column>
                    <el-table-column prop="totalAmount" label="金额" width="120"></el-table-column>
                    <el-table-column prop="status" label="状态" width="120"></el-table-column>
                    <el-table-column label="操作" width="120" align="center">
                        <template slot-scope="scope">
                            <el-button
                                    v-if="scope.row.status === '已支付'"
                                    @click="refund(scope.row)"
                                    type="danger"
                                    size="small">退款
                            </el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
        </div>
    </div>
</div>

<script>
    new Vue({
        el: '#app',
        data: {
            isProductView: true,
            products: [
                { id: '001', name: 'Apple iPhone 14', total: 7999 },
                { id: '002', name: 'Dell XPS 13', total: 10999 },
                { id: '003', name: 'Sony WH-1000XM4', total: 2499 },
            ],
            orders: []
        },
        methods: {
            showProducts() {
                this.isProductView = true;
            },
            showOrders() {
                this.isProductView = false;
                this.fetchOrders();
            },
            buy(product) {
                const traceNo = uuid.v4();  // 实际项目中,一般后端生成订单号然后入库
                const url = `http://localhost:9090/alipay/pay?subject=${encodeURIComponent(product.name)}&traceNo=${traceNo}&totalAmount=${product.total}`;
                window.open(url);
            },
            fetchOrders() {
                axios.get('http://localhost:9090/alipay/orders')
                    .then(response => {
                        this.orders = response.data.data;
                    })
                    .catch(error => {
                        console.error('获取订单失败:', error);
                        this.$message.error('获取订单失败,请稍后重试');
                    });
            },
            refund(order) {
                const url = `http://localhost:9090/alipay/return?traceNo=${order.traceNo}&alipayTraceNo=${order.alipayTradeNo}&totalAmount=${order.totalAmount}`;
                axios.get(url)
                    .then(response => {
                        if (response.data.code == "200") {
                            this.fetchOrders();
                            this.$message.success("退款成功");
                        } else {
                            this.$message.error("退款失败:" + response.data.message);
                        }
                    })
                    .catch(error => {
                        console.error('退款请求失败:', error);
                        this.$message.error("退款失败,请稍后重试");
                    });
            }
        }
    });
</script>
</body>
</html>

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

要使用Spring Boot实现沙箱支付缓存,你可以按照以下步骤进行操作: 1. 首先需要创建一个Spring Boot项目,并在pom.xml文件中添加以下依赖: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cache</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> ``` 2. 接下来需要配置Redis缓存,可以在application.properties文件中添加以下配置: ```properties # Redis配置 spring.redis.host=127.0.0.1 spring.redis.port=6379 spring.redis.password= spring.redis.database=0 ``` 3. 然后需要在代码中使用缓存注解来实现缓存的操作,比如使用@Cacheable注解来缓存支付订单信息,示例代码如下: ```java @Service public class PaymentService { @Autowired private PaymentMapper paymentMapper; @Cacheable(value = "paymentCache", key = "#orderId") public Payment getPayment(String orderId) { return paymentMapper.getPayment(orderId); } @CachePut(value = "paymentCache", key = "#payment.orderId") public int savePayment(Payment payment) { return paymentMapper.savePayment(payment); } @CacheEvict(value = "paymentCache", key = "#orderId") public void deletePayment(String orderId) { paymentMapper.deletePayment(orderId); } } ``` 4. 最后需要在启动类上添加@EnableCaching注解来启用缓存功能: ```java @SpringBootApplication @EnableCaching public class SandboxPaymentApplication { public static void main(String[] args) { SpringApplication.run(SandboxPaymentApplication.class, args); } } ``` 这样就可以使用Spring Boot和Redis来实现沙箱支付缓存了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值