Java微信支付接入(7) - API V3 Native 商户定时查询本地订单

后端定义商户查单接口

支付成功后,商户侧查询本地数据库,订单是否支付成功

java 复制代码
/**
 * 查询本地订单状态
 */
@ApiOperation("查询本地订单状态")
@GetMapping("/query-order-status/{orderNo}")
public R queryOrderStatus(@PathVariable String orderNo) {
    String orderStatus = orderInfoService.getOrderStatus(orderNo);
    if (OrderStatus.SUCCESS.getType().equals(orderStatus)) {//支付成功
        return R.ok();
   }
    return R.ok().setCode(101).setMessage("支付中...");
}

前端定时轮询查单

在二维码展示页面,前端定时轮询查询订单是否已支付,如果支付成功则跳转到订单页面

javascript 复制代码
//启动定时器
this.timer = setInterval(() => {
    //查询订单是否支付成功
    this.queryOrderStatus()
}, 3000)
javascript 复制代码
// 查询订单状态
queryOrderStatus() {
    orderInfoApi.queryOrderStatus(this.orderNo).then(response => {
        console.log('查询订单状态:' + response.code)
        // 支付成功后的页面跳转
        if (response.code === 0) {
            console.log('清除定时器')
            clearInterval(this.timer)
            // 三秒后跳转到订单列表
            setTimeout(() => {
                this.$router.push({ path: '/success' })
           }, 3000)
       }
   })
}
相关推荐
代码游侠5 小时前
C语言核心概念复习——C语言基础阶段
linux·开发语言·c++·学习
㓗冽5 小时前
60题之内难题分析
开发语言·c++·算法
dingdingfish5 小时前
Bash学习 - 第3章:Basic Shell Features,第5节:Shell Expansions
开发语言·学习·bash
rainbow68895 小时前
C++开源库dxflib解析DXF文件实战
开发语言·c++·开源
不倒翁玩偶5 小时前
IDEA导入新的SpringBoot项目没有启动按钮
java·spring boot·intellij-idea
deepxuan5 小时前
Day7--python
开发语言·python
小小小米粒5 小时前
Maven Tools
java
禹凕5 小时前
Python编程——进阶知识(多线程)
开发语言·爬虫·python
蜡笔小马5 小时前
10.Boost.Geometry R-tree 空间索引详解
开发语言·c++·算法·r-tree
IOsetting5 小时前
金山云主机添加开机路由
运维·服务器·开发语言·网络·php