pay.js 975 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * 支付相关服务
  3. */
  4. const util = require('../utils/util.js');
  5. const api = require('../config/api.js');
  6. /**
  7. * 判断用户是否登录
  8. */
  9. function payOrder(orderId) {
  10. return new Promise(function (resolve, reject) {
  11. util.request(api.PayPrepayId, {
  12. orderId: orderId
  13. }).then((res) => {
  14. console.log(res)
  15. if (res.errno === 0) {
  16. const payParam = res.data;
  17. wx.requestPayment({
  18. 'timeStamp': payParam.timeStamp,
  19. 'nonceStr': payParam.nonceStr,
  20. 'package': payParam.package,
  21. 'signType': payParam.signType,
  22. 'paySign': payParam.paySign,
  23. 'success': function (res) {
  24. resolve(res);
  25. },
  26. 'fail': function (res) {
  27. reject(res);
  28. },
  29. 'complete': function (res) {
  30. reject(res);
  31. }
  32. });
  33. } else {
  34. reject(res);
  35. }
  36. });
  37. });
  38. }
  39. module.exports = {
  40. payOrder,
  41. };