收藏
回答

微信公众号调用V3版JSAPI无法调起支付页面

前端使用Vue2进行开发,JSAPI下单可以正常调用并返回结果,但是无法调起支付界面。

import WeixinJSBridge from 'weixin-js-sdk'

actionJSAPI() {

      toActionJSAPI(this.param)

        .then((res) => {

          if (typeof WeixinJSBridge === 'undefined') {

            if (document.addEventListener) {

              document.addEventListener(

                'WeixinJSBridgeReady',

                this.onBridgeReady(res.data),

                false

              )

            } else if (document.attachEvent) {

              document.attachEvent(

                'WeixinJSBridgeReady',

                this.onBridgeReady(res.data)

              )

              document.attachEvent(

                'onWeixinJSBridgeReady',

                this.onBridgeReady(res.data)

              )

            }

          } else {

            this.onBridgeReady(res.data)

          }

        })

        .catch((err) => {})

    },

    onBridgeReady(param) {

      WeixinJSBridge.invoke(

        'getBrandWCPayRequest',

        {

          appId: param.appId, //公众号ID

          timeStamp: param.timeStamp, //时间戳,自1970年以来的秒数

          nonceStr: param.nonceStr, //随机串

          package: param.package,

          signType: param.signType, //微信签名方式:

          paySign: param.paySign, //微信签名

        },

        function (res) {

          if (res.err_msg === 'get_brand_wcpay_request:ok') {

            this.$toast('支付成功')

            return false

          } else if (res.err_msg === 'get_brand_wcpay_request:cancel') {

            this.$toast('支付取消')

            return false

          } else if (res.err_msg === 'get_brand_wcpay_request:fail') {

            this.$toast('支付失败')

            return false

          }

        }

      )

    },

回答关注问题邀请回答
收藏

2 个回答

登录 后发表内容