微信APIV3支付之小程序调起微信支付

作者:超级无敌大飞   阅读 (1518)  |  收藏 (0)  |  点赞 (0)

摘要

本文讲述了使用APIVE支付时,小程序根据后端反馈的预支付订单调起微信支付的接口进行支付。


原文链接:微信APIV3支付之小程序调起微信支付

系列文章

最新技术文章,欢迎关注下方公众号

1663816073754016936.png

1、使用wechatpay-apache-httpclient接入微信ApiV3详细步骤

2、微信ApiV3支付结果回调实现

在上一篇文章中给大家讲解了后端如何生成预支付订单,现在就给大家讲解下小程序如何根据后端生成的预支付订单调起微信支付。

注意,小程序使用uniapp开发,因此本文展示的开发代码均是uniapp代码格式

this.$post({
	url: 'vip/vipSubmit',
	data,
	header: {
		'content-type': 'application/json',
		'X-token': uni.getStorageSync('token'),
	},
}).then(res => {
	
	console.log(res)
	// return;
	if (res.code == '00000') {
		uni.requestPayment({
			provider: this.payTypeList[this.payType].provider,
			timeStamp: res.data.currentTimeLong,
			nonceStr: res.data.nonceStr,
			package: res.data.packageExt,
			signType: res.data.signType,
			paySign: res.data.paySign,
			success: res => {
				console.log(res);
				this.$util.redirectTo('pages/userInfo/memberOrder', { }, '', 'redirectTo');
			},
			fail: res => {
				console.log(res);
				this.flag = false;
				if (res.errMsg == 'requestPayment:fail cancel') {										
					this.$util.showToast({ title: '您已取消支付' });										
				} else {
					uni.showModal({ content: '支付失败,失败原因: ' + res.errMsg, showCancel: false });
				}
				this.$util.redirectTo('pages/userInfo/memberOrder', { }, '', 'redirectTo');
			}
		});
	} else {
		this.$util.showToast({ title: res.data.msg });
		this.flag = false;
	}
});

上面代码注意:

1、vip/vipSubmit为后端生成预支付订单号的接口

2、由于本文采用的是JSAPI支付,因此类型不要传错


分类   Spring 管理
字数   1266

博客标签    小程序APIV3调起微信支付  

评论