美文网首页
支付过后,后端不能立即返回支付结果的前端处理

支付过后,后端不能立即返回支付结果的前端处理

作者: Yinzhishan | 来源:发表于2023-08-23 10:24 被阅读0次

使用倒计时,在倒计时的过程中,多次向后端接口轮询支付结果,如果倒计时结束,返回的结果还是未支付,者进入未支付状态,如果倒计时过程中,有结果为已支付,则停止倒计时,并返回成功状态;
代码如下

data() {
    return {
      orderIds: "",
      sts: 0, // 订单支付状态:  0失败; 1成功
      time: 10, //
      timer: "",
    };
  },
  onLoad(options) {
    console.log("options", options);
    this.orderIds = decodeURIComponent(options.orderIds).split(",");
    this.sts = options.sts;
    if (this.orderIds) {
      this.timer = setInterval(() => {
        this.time--;
        if(!(this.time%3)){
          this.getOrderInfo(this.orderIds);
        }
        if (this.time <= 0) {
          clearInterval(this.timer);
          // this.timer = 0;
        }
      }, 1000);
    }
  },
 methods: {
   async getOrderInfo(orderId) {
      http.request({
        url: "/zanmall_payment/pay/is_pay/0/" + orderId + "/0",
        method: "get",
        callBack: (res) => {
          if (res) {
            this.sts = 1;
            clearInterval(this.timer);
          } else {
            // this.sts = 2;
            if(this.time == 0){
              this.sts = 2;
            }
          }
        },
        errCallBack: (err) => {
          uni.showToast({
            title: err.msg,
            icon: "none",
          });
        },
      });
    }
}

相关文章

网友评论

      本文标题:支付过后,后端不能立即返回支付结果的前端处理

      本文链接:https://www.haomeiwen.com/subject/audpmdtx.html