当前位置: 首页 > Web前端 > vue.js

vue微信公众号H5页面支付

时间:2023-03-31 21:23:13 vue.js

记录微信公众号H5支付打包成jsimportwxfrom'weixin-js-sdk'importrouterfrom'@/router/index'consthandlePayment=res=>{if(res.errMsg==='chooseWXPay:ok'){router.replace('/success')}elseif(res.errMsg==='chooseWXPay:cancel'){router.replace({path:'/fail',query:{failure:'用户取消支付'}})}else{router.replace({path:'/fail',query:{failure:'支付失败'}})}}exportconstcallWxPay=(config)=>{wx.config({debug:false,//true:调试时弹出appId:config.appId//微信appid})wx.ready(function(){wx.chooseWXPay({appId:config.appId,//微信appidtimestamp:config.timestamp,//timestampnonceStr:config.nonceStr,//随机字符串package:config.package,//signType:config.signType,//signaturepaySign:config.paySign,//支付签名成功:handlePayment,取消:handlePayment,失败:handlePayment})})}