payResult.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. var util = require('../../utils/util.js');
  2. var api = require('../../config/api.js');
  3. var app = getApp();
  4. Page({
  5. data: {
  6. status: false,
  7. orderId: 0
  8. },
  9. onLoad: function(options) {
  10. // 页面初始化 options为页面跳转所带来的参数
  11. this.setData({
  12. orderId: options.orderId,
  13. status: options.status === '1' ? true : false
  14. })
  15. },
  16. onReady: function() {
  17. },
  18. onShow: function() {
  19. // 页面显示
  20. },
  21. onHide: function() {
  22. // 页面隐藏
  23. },
  24. onUnload: function() {
  25. // 页面关闭
  26. },
  27. payOrder() {
  28. let that = this;
  29. // 模拟支付成功,同理,后台也仅仅是返回一个成功的消息而已
  30. // wx.showModal({
  31. // title: '目前不能微信支付',
  32. // content: '点击确定模拟支付成功,点击取消模拟未支付成功',
  33. // success: function (res) {
  34. // if (res.confirm) {
  35. // util.request(api.OrderPrepay, { orderId: that.data.orderId }, 'POST').then(res => {
  36. // if (res.errno === 0) {
  37. // that.setData({
  38. // status: true
  39. // });
  40. // }
  41. // else {
  42. // util.showErrorToast('支付失败');
  43. // }
  44. // });
  45. // }
  46. // else if (res.cancel) {
  47. // util.showErrorToast('支付失败');
  48. // }
  49. // }
  50. // });
  51. util.request(api.OrderPrepay, {
  52. orderId: that.data.orderId
  53. }, 'POST').then(function(res) {
  54. if (res.errno === 0) {
  55. const payParam = res.data;
  56. console.log("支付过程开始")
  57. wx.requestPayment({
  58. 'timeStamp': payParam.timeStamp,
  59. 'nonceStr': payParam.nonceStr,
  60. 'package': payParam.packageValue,
  61. 'signType': payParam.signType,
  62. 'paySign': payParam.paySign,
  63. 'success': function(res) {
  64. console.log("支付过程成功")
  65. that.setData({
  66. status: true
  67. });
  68. },
  69. 'fail': function(res) {
  70. console.log("支付过程失败")
  71. util.showErrorToast('支付失败');
  72. },
  73. 'complete': function(res) {
  74. console.log("支付过程结束")
  75. }
  76. });
  77. }
  78. });
  79. }
  80. })