pay.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. var app = getApp();
  2. var util = require('../../utils/util.js');
  3. var api = require('../../config/api.js');
  4. Page({
  5. data: {
  6. orderId: 0,
  7. actualPrice: 0.00
  8. },
  9. onLoad: function (options) {
  10. // 页面初始化 options为页面跳转所带来的参数
  11. this.setData({
  12. orderId: options.orderId,
  13. actualPrice: options.actualPrice
  14. })
  15. },
  16. onReady: function () {
  17. },
  18. onShow: function () {
  19. // 页面显示
  20. },
  21. onHide: function () {
  22. // 页面隐藏
  23. },
  24. onUnload: function () {
  25. // 页面关闭
  26. },
  27. //向服务请求支付参数
  28. requestPayParam() {
  29. let that = this;
  30. util.request(api.PayPrepayId, { orderId: that.data.orderId, payType: 1 }).then(function (res) {
  31. if (res.errno === 0) {
  32. let payParam = res.data;
  33. wx.requestPayment({
  34. 'timeStamp': payParam.timeStamp,
  35. 'nonceStr': payParam.timeStamp,
  36. 'package': payParam.nonceStr,
  37. 'signType': payParam.signType,
  38. 'paySign': payParam.paySign,
  39. 'success': function (res) {
  40. wx.redirectTo({
  41. url: '/pages/payResult/payResult?status=true',
  42. })
  43. },
  44. 'fail': function (res) {
  45. wx.redirectTo({
  46. url: '/pages/payResult/payResult?status=false',
  47. })
  48. }
  49. })
  50. }
  51. });
  52. },
  53. startPay() {
  54. this.requestPayParam();
  55. }
  56. })