【uniapp+vue2】小程序充值实现微信支付和余额支付

布局

<view class="coin-pay" @click="handlerPayCoin">
			<text>充值</text>
		</view>
		<!-- 充值弹框 -->
		<view class="">
			<uni-popup ref="choosePay" type="bottom">
				<view class="orderPay">
					<view class="orderPay-pay">
						<view class="orderPay-pay-item" v-for="(l, i) in payList" :key="i" @click="changePay(i)">
							<view class="item-label">
								<image :src="l.icon" mode=""></image>
								<text>{{ l.text }}</text>
							</view>
							<view class="item-value">
								<image v-if="l.status"
									src="http://zxh-auth.oss-cn-beijing.aliyuncs.com/c3e5694259c242fe872d2974add1bbce.png"
									mode=""></image>
								<view v-else class="item-value-false"></view>
							</view>
						</view>
					</view>
					<view class="orderPay-btn" @click="payTotalMoney">
						<text>确认</text>
					</view>
				</view>
			</uni-popup>
		</view>

js

//js
payList: [{
					icon: 'http://young-czx.oss-cn-hangzhou.aliyuncs.com/61e653b7826a43d4ac957b46ef11cba3.png',
					text: '微信支付',
					status: true,
					payFrom: 'WEIXIN_MP'
},
{
					icon: 'https://zxh-user-file.oss-cn-shenzhen.aliyuncs.com/wx_mall_%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20230613114451.png',
					text: '余额支付',
					status: false,
					payFrom: 'YUE_PAY'
}],

async changePay(i) {
				if (i == 1) {
					this.payList[1].status = true
					this.payList[0].status = false
				} else {
					this.payList[0].status = true
					this.payList[1].status = false
				}
			},
payTotalMoney() {
					this.$refs.choosePay.close()
					if (this.payList[1].status) {
						let postData = {
						userId:this.userInfo.userId,
						rechargeId: this.amountObject.id,
						payCode:this.code,
						payFrom: 'YUE_PAY'
					}
					Recharge(postData).then(res=>{
						console.log(res);
							if (res.status == '0') {
								uni.showToast({
									title: "支付成功",
									duration: 1500
								})
							} else {
								uni.showToast({
									title: `${res.errMsg}`,
									duration: 1500,
									icon: "none"
								})
							}
							setTimeout(() => {
								this.getUserInfo()
							}, 500)
					})
				} else {
					let weixinData = {
						userId:this.userInfo.userId,
						rechargeId: this.amountObject.id,
						payCode:this.code,
						payFrom: 'WEIXIN_MP'
					}
					Recharge(weixinData).then(res=>{
						if(res){
							let payData = JSON.parse(res.payData)
							let that = this
							uni.requestPayment({
									provider: 'wxpay',
									timeStamp: payData.timeStamp,
									nonceStr: payData.nonceStr,
									package: payData.package,
									signType: payData.signType,
									paySign: payData.paySign,
									success: (() => {
										uni.showToast({
											title: "支付成功",
											duration: 1500
										})
										setTimeout(() => {
											that.getUserInfo()
										}, 500)
									}),
									fail() {
										uni.showToast({
											title: "取消支付",
											duration: 1500,
											icon: "none"
										})
									}
								})
							
						}else{
							uni.showToast({
								title: `${res.errMsg}`,
								duration: 1500,
								icon: "none"
							})
						}
					})
					
				}
},

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值