记录一下微信公众号H5支付
封装到了一个js内
import wx from 'weixin-js-sdk'
import router from '@/router/index'
const handlePayment = res => {
if (res.errMsg === 'chooseWXPay:ok') {
router.replace('/success')
} else if (res.errMsg === 'chooseWXPay:cancel') {
router.replace({
path: '/fail',
query: {
failure: '用户取消支付'
}
})
} else {
router.replace({
path: '/fail',
query: {
failure: '支付失败'
}
})
}
}
export const callWxPay = (config) => {
wx.config({
debug: false, // true:调试时候弹窗
appId: config.appId // 微信appid
})
wx.ready(function () {
wx.chooseWXPay({
appId: config.appId, // 微信appid
timestamp: config.timestamp, // 时间戳
nonceStr: config.nonceStr, // 随机字符串
package: config.package, //
signType: config.signType, // 签名
paySign: config.paySign, // 支付签名
success: handlePayment,
cancel: handlePayment,
fail: handlePayment
})
})
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。