uni-app编译微信小程序时 小程序间带参跳转 App.onshow接收参数正常 但调起微信支付完成后会再次触发App.onshow 且携带参数仍为跳转时参数

uni-app编译微信小程序时 小程序间带参跳转 App.onshow接收参数正常 但调起微信支付完成后会再次触发App.onshow 且携带参数仍为跳转时参数

开发环境 版本号 项目创建方式
Windows win10 HBuilderX

示例代码:

onShow: function(e) {  
    console.log("onShow",e)  
    // 隐藏原生tabbar  
    uni.hideTabBar();  
    let res = uni.getSystemInfoSync();  //获取系统信息同步接口  
    this.globalData.statusBarHeight = res.statusBarHeight;  //获取状态栏的高度  
    this.globalData.windowHeight = res.windowHeight;    //获取可使用窗口高度  
    this.globalData.windowWidth = res.windowWidth;  //获取可使用窗口宽度  
    // B端跳转c端  
    try{  
        if(e.referrerInfo.extraData.account_shop_id){  
            this.globalData.shopName = e.referrerInfo.extraData.shopName;  
            console.log('小程序跳转传参',e.referrerInfo.extraData.account_shop_id,e.referrerInfo.extraData.shopName)  
            uni.setStorageSync("nweShop_id",e.referrerInfo.extraData.account_shop_id);  
            uni.setStorageSync("isGoNweShop",true);//nweShop_id携带参数 跳转新店铺  
        }  
    }catch(e){}
}

操作步骤:

  1. 微信小程序之间携带参数跳转 A携带参数跳转到B
  2. B小程序里调起微信支付 并且成功支付
  3. 微信支付成功后返回回到B小程序 app级onShow再次执行 参数是步骤1中的参数

预期结果:

微信支付成功后返回回到B小程序 app级onShow再次执行 onshow参数是空

实际结果:

微信支付成功后返回回到B小程序 app级onShow再次执行 onshow参数是小程序之间跳转的参数

bug描述:

小程序之间携带参数跳转 进入小程序之后再APP级onShow里接受参数 但是当小程序调起微信支付 支付成功后点击完成后回到小程序app级onshow再次执行 接受的参数还是小程序跳转时候的参数


更多关于uni-app编译微信小程序时 小程序间带参跳转 App.onshow接收参数正常 但调起微信支付完成后会再次触发App.onshow 且携带参数仍为跳转时参数的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

看到你的描述,微信小程序设计如此,可以去微信社区反馈一下这个问题

更多关于uni-app编译微信小程序时 小程序间带参跳转 App.onshow接收参数正常 但调起微信支付完成后会再次触发App.onshow 且携带参数仍为跳转时参数的实战教程也可以访问 https://www.itying.com/category-93-b0.html


这是微信小程序平台的特性,不是uni-app的bug。

当小程序从其他小程序跳转过来时,App.onShowreferrerInfo参数会包含跳转来源信息。在支付完成后,小程序会重新触发App.onShow,此时微信小程序框架会重新传递之前存储的跳转参数。

解决方案:

  1. 使用全局变量标记支付状态
// app.js
let isPaymentReturn = false;

onShow: function(e) {
    if (isPaymentReturn) {
        isPaymentReturn = false;
        // 支付返回逻辑,忽略referrerInfo
        return;
    }
    
    // 正常跳转逻辑
    if(e.referrerInfo && e.referrerInfo.extraData) {
        // 处理跳转参数
    }
}

// 支付页面
uni.requestPayment({
    success: () => {
        getApp().isPaymentReturn = true;
        // 其他支付成功逻辑
    }
});
回到顶部