记录 uni-app x 微信支付 时间戳格式引起的 问题

56 阅读1分钟
let orderInfo = res.get('data') as UTSJSONObject;
						console.log('orderInfo: ', orderInfo)
						const appid = orderInfo.get('appid') as string;
						const noncestr = orderInfo.get('noncestr') as string;
						const package2 = orderInfo.get('package') as string;
						const partnerid = orderInfo.get('partnerid') as string;
						const prepayid = orderInfo.get('prepayid') as string;
						const timestamp = parseInt(orderInfo.get('timestamp') as string, 10);
						const sign = orderInfo.get('sign') as string;
						const payParams = {
							appid,
							noncestr,
							package: package2,
							partnerid,
							prepayid,
							timestamp,
							sign
						}

						uni.requestPayment({
							"provider": "wxpay",
							"orderInfo": JSON.stringify(payParams),
							fail: (res) => {
								console.log(JSON.stringify(res))
								if (res != null && res.errCode === 700601) {
									uni.showToast({ title: "用户取消支付" })
								} else {
									uni.showToast({
										icon: 'error',
										title: '支付失败:'
									});
								}

							},
							success: (res) => {
								console.log(JSON.stringify(res))
								uni.showToast({
									icon: 'success',
									title: '支付成功'
								});
							}
						})

这里一定要将时间戳转为数字类型,否则会报错

const timestamp = parseInt(orderInfo.get('timestamp') as string, 10);