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.

77 lines
1.8 KiB

3 years ago
  1. function wxpay (orderInfo) {
  2. if(typeof orderInfo !== 'object') throw new Error('orderInfo must object type')
  3. return new Promise((resolve, reject) => {
  4. uni.requestPayment({
  5. 'provider': 'wxpay',
  6. 'orderInfo': {
  7. 'appid': orderInfo.appid,
  8. 'noncestr': orderInfo.noncestr,
  9. 'package': 'Sign=WXPay',
  10. 'partnerid': orderInfo.partnerid,
  11. 'prepayid': orderInfo.prepayid,
  12. 'timestamp': orderInfo.timestamp,
  13. 'sign': orderInfo.sign
  14. },
  15. success(res) {
  16. setTimeout(resolve(res), 500)
  17. },
  18. fail(e) {
  19. reject(e)
  20. }
  21. })
  22. })
  23. }
  24. function alipay(orderInfo) {
  25. if(typeof orderInfo !== 'string') throw new Error('orderInfo must string type')
  26. return new Promise((resolve, reject) => {
  27. uni.requestPayment({
  28. provider: 'alipay',
  29. orderInfo,
  30. success: function (res) {
  31. setTimeout(resolve(res), 500)
  32. },
  33. fail: function (err) {
  34. reject(err)
  35. }
  36. })
  37. })
  38. }
  39. function wxmini(orderInfo) {
  40. if(typeof orderInfo !== 'object') throw new Error('orderInfo must object type')
  41. return new Promise((resolve, reject) => {
  42. uni.requestPayment({
  43. provider: 'wxpay',
  44. timeStamp: String(Date.now()),
  45. nonceStr: orderInfo.nonceStr,
  46. package: orderInfo.package,
  47. signType: 'MD5',
  48. paySign: orderInfo.paySign,
  49. success: function (res) {
  50. setTimeout(resolve(res), 500)
  51. },
  52. fail: function (err) {
  53. reject(err)
  54. }
  55. })
  56. })
  57. }
  58. function paymentAuto(orderInfo, type) {
  59. // #ifdef APP-PLUS
  60. if(type == 'wxpay') return wxpay(orderInfo)
  61. if(type == 'alipay') return alipay(orderInfo)
  62. // #endif
  63. // #ifdef MP-WEIXIN
  64. return wxmini(orderInfo)
  65. // #endif
  66. }
  67. export {
  68. paymentAuto as default,
  69. wxpay,
  70. wxmini,
  71. alipay
  72. }