微信支付分前端开发流程

我们用的是【免确认模式】https://pay.weixin.qq.com/wiki/doc/apiv3/open/pay/chapter3_1_3.shtml


  1. 查询授权情况
    后端调用返回给你

在这里插入图片描述

  1. 拿支付分的预授权 token
    后端调用返回给你

在这里插入图片描述

  1. 去预授权
uni.navigateToMiniProgram({
	appId: 'wxd8f3793ea3b935b8', // 固定就这么写
	path: 'pages/use/enable', // 固定就这么写
	extraData: {
		apply_permissions_token: res.data  // res.data是第2步给的token
	},
	success() {
		// 此处是跳转支付分授权页面成功,不是授权成功
	}
});

贴出我的相关代码:
在这里插入图片描述

// 查询支付分授权情况
queryPayCreditAuthorization() {
	this.useElectricityBTNdisabled = true;
	this.usePayCredit = true;
	this.$request("/wechat/payScore/getPermissionsByOpenid", "POST", {
		userId: uni.getStorageSync("openId")
	}).then(res => {
		console.log("授权情况:", res);
		if (res.data.status === 200) {
			// 未授权
			if (res.data.returnStr.authorization_state === "UNAVAILABLE") {
				this.authorizationPayCredit();
			}
			// 已授权
			if (res.data.returnStr.authorization_state === "AVAILABLE") {
				this.portISUsed();
			}
		};
		// 无授权记录
		if (res.data.status === 404) {
			this.authorizationPayCredit();
		}
		if (res.data.status !== 200) {
			uni.showToast({
				title: res.data.returnStr.message,
				icon: "none"
			})
		}
	});
},
// 拿支付分的预授权 token
authorizationPayCredit() {
	const that = this;
	this.$request("/wechat/payScore/permissions", "POST", {
		userId: uni.getStorageSync("openId")
	}).then(res => {
		console.log(res);
		// 去预授权
		uni.navigateToMiniProgram({
			appId: 'wxd8f3793ea3b935b8', // 固定就这么写
			path: 'pages/use/enable', // 固定就这么写
			extraData: {
				apply_permissions_token: res.data
			},
			success() {
				that.useElectricityBTNdisabled = false;
			}
		});
	})
},

在这里插入图片描述


剩下就是解除授权、退款之类的,由后端调用微信的公共API,然后返回给你:
在这里插入图片描述
查看支付分订单详情需要前端调
在这里插入图片描述

uni.navigateToMiniProgram({
	appId: 'wxd8f3793ea3b935b8', // 固定就这么写
	path: 'pages/record/detail', // 固定就这么写
	extraData: res.data  // res.data是后端给的参数
});

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

美酒没故事°

谢谢看官

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值