美文网首页
app第三方支付(微信),微信小程序支付

app第三方支付(微信),微信小程序支付

作者: 谁的小羊跑了 | 来源:发表于2023-01-18 10:04 被阅读0次

最近公司开发一个app,需要从app跳转到小程序去微信支付,当时在网上看了好长时间没有看到适合自己的,在这里记录一下,也方便自己以后可以再复习一下,毕竟本人脑子不太好使,只能记下来。

小程序微信支付:

 // #ifdef MP
 //小程序 微信
uni.requestPayment({
    // timeStamp,nonceStr,package,signType,paySign皆为后端返回
    provider: type, // type:wxpay
    timeStamp: data.timeStamp, 
    nonceStr: data.nonceStr, 
    package: data.package,
    signType: data.signType,
    paySign: data.paySign,
    success: (e) => {
        uni.redirectTo({
            url: "/pagesB/payment/paySuccess?orderNos="+this.payIds+"&price="+this.price
        })
    },
    fail: (e) => {
        //用户取消支付 不做处理
        console.log("fail", e);
        this.subLoading = false;
        this.subDisabled = false;
    },
    complete: (e) => {
        console.log(e)
    }
})
// #endif

app跳转小程序微信支付

  • app跳转页面携带参数到小程序
data() {
    return {
        weixin: null,
    };
},
onLoad(options) {
    // #ifdef APP-PLUS  
        plus.share.getServices((s) => {
            console.log(s)
            let shares = {};
            for (let i = 0; i < s.length; i++) {
                let t = s[i];
                shares[t.id] = t;
            }
                let sweixin = shares['weixin'];
                this.weixin = sweixin
                console.log(this.weixin)
        }, function(e) {
                console.log("获取分享服务列表失败:" + e.message);
            });
    //#endif
},
methods:{
    // 确认支付
    payment() {
        ......... 
        // #ifdef APP-PLUS
        this.weixin ? this.weixin.launchMiniProgram({
            path: `pagesB/payment/pay?price=${this.price}`, 
            type: 2, //可取值: 0-正式版; 1-测试版; 2-体验版。 默认值为0。
            id: '............', //小程序的原始id
            success(res) {
                console.log('成功')
            }
        }) : plus.nativeUI.alert('当前环境不支持微信操作!');
                return
            // #endife
    }
    // path里面的是路径由自己决定需要跳转到小程序哪一个页面,此处也可以传参哦!
}
  • 小程序接收参数,拉起微信支付
onLoad(option) {
// #ifdef MP
// app跳转小程序支付 判断
    this.weixinFlag = options.weixinFlag
        if (this.weixinFlag == '1') { 
            console.log('app跳转小程序支付')
            let data = res.data
            //小程序 微信
            uni.requestPayment({
                provider: 'wxpay',
                timeStamp: data.time_stamp,
                nonceStr: data.nonce_str,
                package: data.package,
                signType: data.sign_type,
                paySign: data.pay_sign,
                success: (e) => {
                    console.log('支付成功')
                },
                fail: (e) => {
                    //用户取消支付 不做处理
                    console.log("fail", e);
                },
                complete: (e) => {
                    console.log(e)
                }
            })
        }
     // #endif
}

相关文章

网友评论

      本文标题:app第三方支付(微信),微信小程序支付

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