微信小程序调用支付接口返回订单号

一、获取支付参数准备调用支付api

wx.request({
url: ‘http://localhost:8010/pay/createOrder’, //上线的话必须是https,没有appId的本地请求貌似不受影响
method: ‘POST’, // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
header: {
‘Content-Type’: “application/json”
}, // 设置请求的 header ‘Content-Type’: “application/x-www-form-urlencoded”
data: {
“openid”: “o_KYs5Pa-INK7unYIiwp2rj4IGLs”,//openid
“deviceInfo”: “WEB”,
“body”: “跑腿-订单支付”,
“outTradeNo”: “201508061253100”,//订单号
“totalFee”: 1,//付款钱,单位(分)
“spbillCreateIp”: “192.168.3.107”,//ip地址
“notifyUrl”: “https://pt.lltt.info:8010/paotui/v1/wx/wxPayNotify”,
“tradeType”: “JSAPI”
},
success: function (res) {
//定义全局变量,赋值res.data

    console.log("请求数据成功");
  },
  fail: function (e) {
    console.log("请求数据失败");
    console.log(e)
  },
  complete: function () {
    // complete 
  }
})

二、存储订单号

wx.request({
  url: 'http://localhost:8010/paotui/v1/order/orderPayStatus/' +'"201508061253100"', //改订单号
  method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT 
  header: {
    'Content-Type': "application/x-www-form-urlencoded"
  }, // 设置请求的 header 'Content-Type': "application/x-www-form-urlencoded" application/json
  success: function (res) {

    console.log("请求数据成功");
    console.log(res)
  },
  fail: function (e) {
    console.log("请求数据失败");
    console.log(e)
  },
  complete: function () {
    // complete 
  }
})

三、调用支付接口

wx.requestPayment(
  {
    'timeStamp': $this.data.payData.timeStamp,//所有参数都存在之前定义的全局变量里,直接取
    'nonceStr': $this.data.payData.nonceStr,
    'package': $this.data.payData.packageValue,
    'signType': $this.data.payData.signType,
    'paySign': $this.data.payData.paySign,
    'success': function (res) {
      
      console.log(`success: ${res}`)
    },
    'fail': function (res) {
      
      console.log(`fail: ${res}`)
    },
    'complete': function (res) {
      
      console.log(`complete: ${res}`)

// 三、存储订单号
//debugger
wx.request({
url: ‘https://pt.lltt.info:8010/paotui/v1/order/orderPayStatus/’ + that.data.orderNum, //改订单号
method: ‘GET’, // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
header: {
‘Content-Type’: “application/x-www-form-urlencoded”
}, // 设置请求的 header ‘Content-Type’: “application/x-www-form-urlencoded” application/json
success: function (res) {

                            console.log("请求数据成功");
                            console.log(res)

                          },
                          fail: function (e) {
                            console.log("请求数据失败");
                            console.log(e)
                          },
                          complete: function () {
                            // complete 
                          }
                        })
















    }
  })
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值