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

本文介绍了如何在App中调用小程序进行微信支付,包括从App跳转到小程序的参数传递,以及小程序接收参数并启动微信支付的过程。主要涉及uni.requestPayment接口和plus.share.getServices方法。
摘要由CSDN通过智能技术生成

最近公司开发一个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
}

 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值