H5 微信支付

template:

<view style="margin-right: 10upx;">
                    <button v-if="isshow==0" @click="$noMultipleClicks(publish)" class="btn-or" style="width: 35vw;">支付并发布</button>
                    <button v-else @click="$noMultipleClicks(edit)" class="btn-or" style="width: 35vw;">编辑发布</button>
 </view>

methods:

async publish() {
                let that = this
                // let id = localStorage.getItem('id')
                // console.log(id)
                console.log(that.id,'idddddd')
                // return
                console.log(that.type)
                console.log(that.title)
                console.log(that.info)
                console.log(JSON.stringify(that.imgArr),'imgarr')
                if(that.title == '' || that.info == '' || that.imgArr == ''){
                    showToast('不可为空哦');
                    return
                }
                // return
                let params = {
                    'a_id': that.id,
                    'type': that.type,
                    'title': that.title,
                    'info': that.info,
                    'imgs': JSON.stringify(that.imgArr)
                }
                let request = await that.$api.myRequest({
                    url: '/api/activity_flow_user/add_item',
                    data: params,
                })
                console.log(request, '我是提交成功')
                // if()
                // if(request.surplus > 0){
                //     // showLoadingToast({
                //     //   message: '此单将消耗您',
                //     //   forbidClick: true,
                //     // });
                // }else{
                    
                // }
                
                let u = window.location.href
                console.log(u)
                let request1 = await that.$api.myRequest({
                    url: '/api/getwxconfig',
                    data: {
                        url: u
                    }
                })
                console.log(request1, 'share')
                // console.log(that.title, 'thatjinxing')
                // 微信分享授权
                wx.config(request1.data)
                let res = await that.$api.myRequest({
                    url: '/api/activity_flow_user/pay',
                    data: {
                        id: request.data
                    },
                })
                console.log(res,'ressssss pay isme')
                if(res.msg == '支付成功'){ //走这一步是因为余额的money够支付的钱
                    showToast('余额支付成功');
                    setTimeout(()=>{
                        uni.navigateTo({
                            url:'/pages/list/detail-zhengji?id='+that.id
                        })
                    },1000)
                    return
                }
                wx.ready(function() {//不够需要支付
                    console.log('111')
                    
                    wx.chooseWXPay({
                        // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。
                        // 但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
                        timestamp: res.data.timeStamp,
                        // 支付签名随机串,不长于 32 位
                        nonceStr: res.data.nonceStr,
                        package: res.data.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*)
                        signType: res.data.signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
                        paySign: res.data.paySign, // 支付签名
                        
                        success: (res)=>{
                            console.log('success',res)
                            // 支付成功后的回调函数
                            uni.navigateTo({
                                url:'/pages/list/detail-zhengji?id='+that.id
                            })
                        },
                        fail: function(res) {
                            console.log('支付失败',res)
                        },
                        complete: function(res) {
                            console.log(res, 'complete')
                        }
                    })
                })

                // let res = await this.$api.myRequest({
                //     url: '/api/activity_flow_user/pay',
                //     data: {id:request.data},
                // })

                // wx.chooseWXPay({
                //      // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。
                //      // 但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
                //     timestamp: res.data.timeStamp, 
                //     // 支付签名随机串,不长于 32 位
                //     nonceStr: res.data.nonceStr, 
                //     package: res.data.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*)
                //     signType: res.data.signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
                //     paySign: res.data.paySign, // 支付签名
                //     success: function(res) {
                //       // 支付成功后的回调函数
                //     },
                //     fail: function(res) {
                //       console.log('支付失败')
                //     },
                //     complete: function(res) {
                //       console.log(res, 'complete')
                //     }
                //   })
},

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值