uniapp----微信支付uni.requestPayment

1.展示
在这里插入图片描述

在这里插入图片描述
2.

<view class="btnWarp">
			<view class="mask_item mask_bottom">
				<view class="loginBtn btn" @click="submit">立即支付</view>
			</view>
		</view>

3.方法

data() {
			return {
				optionObj: {},
			}
		},
				methods: {
			//立即支付
			submit() {
				this.$utils.stopClick(null, 2000).then(res => {
					uni.showLoading({
						mask: true,
						title: '加载中...'
					})
					//支付成功跳转至订单详情
					uni.hideLoading();
					let that = this;
					uni.requestPayment({
						provider: 'wxpay',
						timeStamp: this.optionObj.data.result.jsConfig.timeStamp,//时间戳从1970年1月1日至今的秒数,即当前的时间。
						nonceStr: this.optionObj.data.result.jsConfig.nonceStr,//随机字符串,长度为32个字符以下。//统一下单接口返回的 prepay_id 参数值,提交格式如:prepay_id=xx
						package: this.optionObj.data.result.jsConfig.package,
						signType: this.optionObj.data.result.jsConfig.signType,//签名算法,应与后台下单时的值一致
						paySign: this.optionObj.data.result.jsConfig.paySign,//签名
						success: function(res) {
							// console.log('success:', that.optionObj);
							//跳转页面
							uni.showToast({
								title: '支付成功',
								icon: 'none'
							})
							   uni.removeStorageSync('optionObj');
								//返回订单详情
								uni.setStorageSync('optionObj',that.optionObj.data.result)
								uni.redirectTo({
									url: `/pagesA/myOrder/orderDetails?type=1`
								})
						},
						fail: function(err) {
							console.log("支付失败的原因", err);
							uni.showToast({
								title: '取消支付',
								icon: 'none'
							})
							var pages = getCurrentPages();
							var currPage = pages[pages.length - 1]; //当前页面
							var prevPage = pages[pages.length - 2]; //上一个页面
							prevPage.$vm.showCar = false;
							setTimeout(() => {
								uni.navigateBack({
									delta: -1
								})
							}, 800)
						}
					});
				})
			},
		}
  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值