微信小程序开通无感支付(微信支付分)--uni-app版

1、打开微信支付分页面:首先需要将这个小程序绑定的商户号开通微信支付分服务,然后使用navigateTominiProgram跳转微信支付分小程序,跳转时需要传参,其中appId和path是固定的(为要跳转的小程序的参数,此时使用的是微信支付分的参数),然后在extraData中设置的是当前小程序的一些参数。

    uni.navigateToMiniProgram({
        appId: 'wxbcad394b3d99dac9',
        path: '/pages/auth-creditpay/auth-creditpay',
        extraData: {
            mchid: uni.config.mchid,
            openid: uni.getStorageSync('openId'),
            plate_number: plateNumber, // 车牌号
            plate_color: plateColor, // 车牌颜色
            trade_scene: 'PARKING' // 使用场景
        }
    }); 

2、开通后会返回自身的小程序,在App.vue中的onShow中获取参数referrerInfo中的appId,判断是否从微信支付分页面返回,然后存储标识。

 onShow: function(res) {
    if (res.scene === 1038) { // 场景值1038:从被打开的小程序返回
        const { appId, extraData } = res.referrerInfo;
        if (appId == 'wxbcad394b3d99dac9') { // appId为wxbcad394b3d99dac9:从车主小程序跳转回来
        uni.setStorageSync('isWeixinBack', true);
        return;
        }
    }    
  }

3、最后在需要跳转微信支付分的页面的onShow中判断标识是否为true,如果是说明是从微信支付分小程序返回,可以进行编写开通后的一些接口调用代码。

  onShow() {
    if (uni.getStorageSync('isWeixinBack')) {
       // 可进行开通后的一些操作                        
       uni.removeStorageSync('isWeixinBack');
    }
  }

 

posted @ 2022-10-27 16:35  王浅浅  阅读(1976)  评论(1编辑  收藏  举报