微信小程序防止重复支付、超时支付逻辑

1、防止重复支付:给重复支付加锁,默认锁4秒,在4秒内在支付完成、遇见异常去除锁

2、超时支付:支付方法默认锁4秒

3、支付逻辑

clearBookFlag() {
    this._booking = false;
    if(!this._bookTimer) return;
    clearTimeout(this._bookTimer);
    this._bookTimer = null;
  }

4、锁逻辑

/**
  * 下单逻辑
  */
 book() {
    if(this._booking) return;
    this._booking = true;
    this._bookTimer = setTimeout(() => {
      this.clearBookFlag();
    }, 4000);
    // 接口请求
    .catch((err) => {
      this.clearBookFlag();
      toast({
        title: err.message || ''
      })
    }).finally(() => {
      this.clearBookFlag();
    })

  },

你可能感兴趣的:(微信小程序,小程序)