小说小程序前端代码仓库(小程序)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.2 KiB

7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
  1. // #ifdef H5
  2. import jWeixin from './lib/jweixin-module.js'
  3. // #endif
  4. /**
  5. * 调用微信支付 - Promise版本
  6. * @param {Object} res - 支付参数对象包含appIdtimeStampnonceStr等必要信息
  7. * @returns {Promise} 返回Promise对象成功时resolve失败时reject
  8. */
  9. export function wxPay(res) {
  10. return new Promise((resolve, reject) => {
  11. // JSSDK配置成功后的回调
  12. jWeixin.ready(function() {
  13. // 调用微信支付接口
  14. jWeixin.chooseWXPay({
  15. appId: res.result.appId,
  16. timestamp: res.result.timeStamp, // 支付签名时间戳
  17. nonceStr: res.result.nonceStr, // 支付签名随机串
  18. package: res.result.packageValue, // 统一支付接口返回的prepay_id参数值
  19. signType: res.result.signType, // 签名类型,默认为MD5
  20. paySign: res.result.paySign, // 支付签名
  21. success: function(result) {
  22. resolve(result);
  23. },
  24. fail: function(error) {
  25. reject(error);
  26. },
  27. cancel: function(cancelResult) {
  28. reject({ type: 'cancel', data: cancelResult });
  29. }
  30. });
  31. });
  32. // JSSDK配置失败处理
  33. jWeixin.error(function(error) {
  34. reject({ type: 'config_error', data: error });
  35. });
  36. });
  37. }