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)
       }
   })
}
相关推荐
qq_5470261791 小时前
Flowable 工作流引擎
java·服务器·前端
鼓掌MVP2 小时前
Java框架的发展历程体现了软件工程思想的持续进化
java·spring·架构
编程爱好者熊浪3 小时前
两次连接池泄露的BUG
java·数据库
lllsure3 小时前
【Spring Cloud】Spring Cloud Config
java·spring·spring cloud
鬼火儿3 小时前
SpringBoot】Spring Boot 项目的打包配置
java·后端
NON-JUDGMENTAL4 小时前
Tomcat 新手避坑指南:环境配置 + 启动问题 + 乱码解决全流程
java·tomcat
大佬,救命!!!4 小时前
C++多线程同步与互斥
开发语言·c++·学习笔记·多线程·互斥锁·同步与互斥·死锁和避免策略
chxii4 小时前
Maven 详解(上)
java·maven
李少兄4 小时前
IntelliJ IDEA 远程调试(Remote Debugging)教程
java·ide·intellij-idea
Kuo-Teng4 小时前
Leetcode438. 找到字符串中所有字母异位词
java·算法·leetcode