vipPurchase.js 951 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. Page({
  2. data: {
  3. navbarData: {
  4. showCapsule: 1,
  5. title: '内容会员',
  6. },
  7. },
  8. toBuy() {
  9. wx.request({
  10. url: 'https://yourdomain.com/get-payment-params',
  11. method: 'POST',
  12. data: {
  13. // 传递需要的参数,比如订单号等
  14. },
  15. success: (res) => {
  16. if (res.data && res.data.success) {
  17. const paymentParams = res.data.paymentParams;
  18. wx.requestPayment({
  19. ...paymentParams,
  20. success: (res) => {
  21. console.log('支付成功', res);
  22. // 支付成功后的处理
  23. },
  24. fail: (err) => {
  25. console.error('支付失败', err);
  26. // 支付失败后的处理
  27. }
  28. });
  29. } else {
  30. console.error('获取支付参数失败', res);
  31. }
  32. },
  33. fail: (err) => {
  34. console.error('请求支付参数失败', err);
  35. }
  36. });
  37. }
  38. });