小程序 微信支付 前端代码

时间:2024-03-18 15:59:30
  gotoPay: function () {
    let obj = this;
    if (obj.data.isPay) {
      //调用微信支付
      // http://121.40.112.2:8770/wepay/toorder?userId=&token=&iouId=&openid=
      util.ajax({
        url: API + \'wepay/toorder\',
        data: {
          userId: obj.data.userId,
          token: obj.data.token,
          iouId: obj.data.iouId,
          openid: wx.getStorageSync(\'openid\')
        }
      }).then(res => {
        wx.requestPayment({
          \'timeStamp\': res.data.data.timeStamp,
          \'nonceStr\': res.data.data.nonceStr,
          \'package\': res.data.data.package,
          \'signType\': res.data.data.signType,
          \'paySign\': res.data.data.sign,
          \'success\': function (res) {
            if (obj.data.spath == \'index\') {
              util.friendlyOperation({
                title: \'操作成功\',
                icon: \'success\',
                url: \'../index/index\',
              });
            } else {
              util.friendlyOperation({
                title: \'支付成功\',
                url: \'../share_view/share_view?iouId=\' + obj.data.iouId,
                icon: \'success\'
              })
              wx.navigateTo({
                url: \'../share_view/share_view?iouId=\' + obj.data.iouId
              })
              console.log(res)
            }
          },
          \'fail\': function (res) {
            wx.showToast({
              title: \'取消支付\',
              icon: \'none\'
            })
            console.log(res)
          }
        })
      })
    } else {
      wx.navigateTo({
        url: \'../share_view/share_view?iouId=\' + obj.data.iouId
      })
    }
  },