Browse Source

添加工具

master
spirit2020 3 years ago
parent
commit
8aa94e8ac6
  1. 2
      README.md
  2. 0
      common/utils/mescroll-map.js
  3. 77
      common/utils/payment.js

2
README.md

@ -44,7 +44,7 @@ const app = new Vue({
- [uview-ui](https://v1.uviewui.com/components/intro.html) - [uview-ui](https://v1.uviewui.com/components/intro.html)
- [mescroll](https://www.mescroll.com/uni.html#mescrollbody) - [mescroll](https://www.mescroll.com/uni.html#mescrollbody)
``` ```
import {MescrollMixin, MescrollCompMixin} from '@/common/utils/MescrollMap'
import {MescrollMixin, MescrollCompMixin} from '@/common/utils/mescroll-map'
``` ```
### api ### api

0
common/utils/MescrollMap.js → common/utils/mescroll-map.js

77
common/utils/payment.js

@ -0,0 +1,77 @@
function wxpay (orderInfo) {
if(typeof orderInfo !== 'object') throw new Error('orderInfo must object type')
return new Promise((resolve, reject) => {
uni.requestPayment({
'provider': 'wxpay',
'orderInfo': {
'appid': orderInfo.appid,
'noncestr': orderInfo.noncestr,
'package': 'Sign=WXPay',
'partnerid': orderInfo.partnerid,
'prepayid': orderInfo.prepayid,
'timestamp': orderInfo.timestamp,
'sign': orderInfo.sign
},
success(res) {
setTimeout(resolve(res), 500)
},
fail(e) {
reject(e)
}
})
})
}
function alipay(orderInfo) {
if(typeof orderInfo !== 'string') throw new Error('orderInfo must string type')
return new Promise((resolve, reject) => {
uni.requestPayment({
provider: 'alipay',
orderInfo,
success: function (res) {
setTimeout(resolve(res), 500)
},
fail: function (err) {
reject(err)
}
})
})
}
function wxmini(orderInfo) {
if(typeof orderInfo !== 'object') throw new Error('orderInfo must object type')
return new Promise((resolve, reject) => {
uni.requestPayment({
provider: 'wxpay',
timeStamp: String(Date.now()),
nonceStr: orderInfo.nonceStr,
package: orderInfo.package,
signType: 'MD5',
paySign: orderInfo.paySign,
success: function (res) {
setTimeout(resolve(res), 500)
},
fail: function (err) {
reject(err)
}
})
})
}
function paymentAuto(orderInfo, type) {
// #ifdef APP-PLUS
if(type == 'wxpay') return wxpay(orderInfo)
if(type == 'alipay') return alipay(orderInfo)
// #endif
// #ifdef MP-WEIXIN
return wxmini(orderInfo)
// #endif
}
export {
paymentAuto as default,
wxpay,
wxmini,
alipay
}
Loading…
Cancel
Save