vue模式下h5调用支付宝支付

1.vue模式下直接跳转支付宝APP支付
main.js里面全局设置

function plusReady() {
    checkUpdate()
        // 设置一个全局plusready状态
    store.state.isplusReady = true
    store.state.storageEngine = plus.storage
    plus.screen.lockOrientation('portrait')
    plus.navigator.setFullscreen(false)

    // 设置一个全局plusready状态
    store.state.isplusReady = true
    store.state.storageEngine = plus.storage

    // 监听返回按键
    let now = false
    let time = null
    plus.key.addEventListener('backbutton', function() {
        // 如果是首页则执行退出操作
        if (
            router.currentRoute.path === '/home' ||
            router.currentRoute.path === '/my-center'
        ) {
            time = null
            if (now) {
                now = false
                plus.runtime.quit()
            } else {
                now = true
                plus.nativeUI.toast('再按一次退出', { duration: 'short' })
                time = setTimeout(() => {
                    now = false
                }, 1000)
            }
            // 如果是内页则执行路由返回操作
        } else {
            router.go(-1)
        }
    })

    if (process.env.NODE_ENV === 'production') {
        //初始化数据库 就是当登录的时候拉取缓存在本地的信息
        db.syncDb2Memory()
            //初始化登录信息
        initUserInfo()

        let app = new Vue({
            router,
            store,
            created() {
                wsStart()
            },
            render: h => h(App)
        }).$mount('#app')
    }
}
Vue.mixin({
    computed: {
        plusReady() {
            return this.$store.state.isplusReady
        }
    }
})

组件中调用支付

在export default上面写
let aliChannel;
let wxChannel;
window.plus && plus.payment.getChannels(function(channels) {
  for(var i = 0; i < channels.length; i++) {
    if (channels[i].id == "wxpay") {
      wxChannel=channels[i];
    }else{
      aliChannel=channels[i];
    }
  }
})
支付宝支付
            plus.payment.request(
              wxChannel,
              payConfig,
              result=> {
                plus.nativeUI.alert("支付成功!", ()=> {
                  _this.$router.replace({ name: "lotterydraw" })
                });
              },
              function(error) {
                console.log(JSON.stringify(error))
                plus.nativeUI.alert("支付未成功");
              }
           
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值