pay.js 846 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. var url = require('../constant/url.js')
  2. var businessT = require('../tool/business-tool.js')
  3. import Net from './../tool/net.js'
  4. var net = new Net()
  5. function prepay(obj) {
  6. wx.login({
  7. success: res => {
  8. // res.code 可以到后台换取 openId, sessionKey, unionId
  9. net.connectNeedLogin({
  10. url: url.app_host + url.prepay,
  11. data: { code: res.code },
  12. success: obj.success,
  13. fail: obj.fail
  14. })
  15. },
  16. fail: obj.fail
  17. })
  18. }
  19. function wxPay (obj) {
  20. if (businessT.isDebug()) {
  21. obj.success()
  22. return
  23. }
  24. wx.requestPayment({
  25. timeStamp: obj.data.wx.timestamp,
  26. nonceStr: obj.data.wx.noncestr,
  27. package: obj.data.wx.package,
  28. signType: 'MD5',
  29. paySign: obj.data.wx.sign,
  30. success: obj.success,
  31. fail: obj.fail
  32. })
  33. }
  34. module.exports = {
  35. prepay: prepay,
  36. wxPay: wxPay
  37. }