怎么在小程序支付完成后,传递数据给url后台?
发布于 6 年前 作者 liaoqiang 1864 次浏览 来自 官方Issues

支付可以正常运行,但是无法传递数据url到后台

button: function(e) {
   let orderId = Date.now();
   wx.cloud.callFunction({
     name: "getOpenid"
     data: {
       orderid: orderId,
       totalPrice: 0.1
     },
     success(res) {
       console.log("提交成功101", res.result)
       that.getOpenid(res.result)
     },
     fail(res) {
       console.log("提交失败101", res)
     },
     complete: function () {
       var uphone = wx.getStorageSync('uphone'); 
       wx.request({
         url: app.globalData.baseUrl + '/buyer/order/create'
         method: "POST"
         header: {
           "Content-Type": "application/x-www-form-urlencoded"
         },
         data: {
           openid: app.globalData.openid,
           name: app.globalData.userInfo.nickName
           phone: uphone,     
         },
         success: function (res) {
           console.log("支付成功10001:", res.data)
           if (res && res.data && res.data.data) {
             // 支付方式关闭动画
             that.animation.translate(, 285).step();
             that.setData({
               animationData: that.animation.export()
             });
             that.setData({
               maskFlag: true
             });           
             wx.setStorageSync('cart', ""
             wx.switchTab({
               url: '../index/index'
             })
           } else {
             // 支付方式关闭动画
             that.animation.translate(, 285).step();
             that.setData({
               animationData: that.animation.export()
             });
             that.setData({
               maskFlag: true
             });           
           }
         }
       })
     }
   })
 },
getOpenid(payData) {
    //console.log("入口支付成功11", res)
    wx.requestPayment({
      timeStamp: payData.timeStamp,
      nonceStr: payData.nonceStr,
      package: payData.package,
      signType: 'MD5',
      paySign: payData.paySign,
      success(res) {
        console.log("入口支付成功11", res.data)
      },
      fail(res) {
              console.log("入口支付失败11", res)
      }
    })
}

求大佬

8 回复
报错很明显了:that.animation.translate中的that.animation是undefined。
 我猜你这里应该是that.data.animation或者直接animation,看你这个animation变量是怎么定义的了

支付接口不是有个notify_url吗,在notify_url的程序逻辑里根据订单id去获取对应的openid,name和phone

--↓↓👍点赞是回答的动力哦!!

你的接口500了 去问问后台 接口坏了 先解决500 再解决关闭动画问题 500就是让你不能传输过去的原因

--↓↓👍点赞是回答的动力哦

把wx.request({})放到 wx.cloud.callFunction({})外面,就不会报错;

但是是在支付完成前就已经传递参数到后台url了


button: function) {
   let orderId = Date.now();
   wx.cloud.callFunction({
     name: "getOpenid"
     data: {
       orderid: orderId,
       totalPrice: 0.1
     },
     success(res) {
       console.log("提交成功101", res.result)
       that.getOpenid(res.result)
     },
     fail(res) {
       console.log("提交失败101", res)
     },
   })
  var uphone = wx.getStorageSync('uphone'); 
  wx.request({
         url: app.globalData.baseUrl + '/buyer/order/create'
         method: "POST"
         header: {
           "Content-Type": "application/x-www-form-urlencoded"
         },
         data: {
           openid: app.globalData.openid,
           name: app.globalData.userInfo.nickName
           phone: uphone,     
         },
         success: function (res) {
           console.log("支付成功10001:", res.data)
           if (res && res.data && res.data.data) {
             // 支付方式关闭动画
             that.animation.translate(, 285).step();
             that.setData({
               animationData: that.animation.export()
             });
             that.setData({
               maskFlag: true
             });           
             wx.setStorageSync('cart', ""
             wx.switchTab({
               url: '../index/index'
             })
           } else {
             // 支付方式关闭动画
             that.animation.translate(, 285).step();
             that.setData({
               animationData: that.animation.export()
             });
             that.setData({
               maskFlag: true
             });           
           }
         }
    })
 },
  getOpenid(payData) {
    //console.log("入口支付成功11", res)
    wx.requestPayment({
      timeStamp: payData.timeStamp,
      nonceStr: payData.nonceStr,
      package: payData.package,
      signType: 'MD5',
      paySign: payData.paySign,
      success(res) {
        console.log("入口支付成功11", res.data)
      },
      fail(res) {
              console.log("入口支付失败11", res)
      }
    })

}

支付成功,后端处理数据,走的支付回调接口,不需要前端传什么东西啊

--↓↓👍如果觉得有帮助的话请点个【赞】吧

你这关闭动画的代码有问题啊

亲,你的代码报错啦

为什么不把wx.request({ 写到 getOpenid 的success里 感觉是同步异步的问题
回到顶部