- 小程序内打开webView 在webView内实现js支付报错?
[图片]<template> <view class="box"> <!-- <view class="top"> 获取地址栏目 </view> <button @click="query">支付</button> <view class=""> {{code}} {{searchObj}} </view> --> <view> {{ obj }} </view> <view style="margin: 20px 0; color: #333; font-size: 14px;"> <text v-for="(log, idx) in logList" :key="idx">{{ log }}<br/></text> </view> </view> </template> <script> import config from './config/config.js'; export default { data() { return { code: '', obj: {}, searchObj: { appId: '', openId: '', bizId: '' }, logList: [] }; }, onLoad(option) { this.code = option.code; this.getOpenId(this.code); }, onError(err) { // uni.showToast({ // title:`${JSON.stringify(err)}`, // icon:'' // }) }, mounted() { if (!/MicroMessenger/i.test(navigator.userAgent)) { alert('请在微信内置浏览器中打开'); } }, methods: { async getOpenId(e) { let info = uni.getStorageSync('billInfo'); let data = { code: e, appId: info.appId }; let res = await config.interfaces.getOpenId(data); console.log(res, '获取到的openid'); if (res.code == 200) { let data = { bizType: info.bizType, bizId: info.bizId, payChannel: 'WX_PUB', expend: { open_id: res.data } }; if (data.bizType == 'MANUAL') { data.billId = info.billId; } else if (data.bizType == 'CONTRACT') { data.submitAmount = info.submitAmount; } console.log(data, '参数'); this.getPayInfo(data); } else { uni.showToast({ title: res.msg, icon: 'none' }); } }, async getPayInfo(e) { let res = await config.interfaces.getPayInfo(e); if (res.code == 200) { console.log(res.data); this.pay(res.data); } else { uni.showToast({ title: res.msg, icon: 'none' }); } }, pay(res) { this.logList.push('准备调起支付...'); const onBridgeReady = () => { this.logList.push('WeixinJSBridgeReady 事件触发,开始调用支付API'); WeixinJSBridge.invoke( 'getBrandWCPayRequest', { appId: res.payInfo.appId, //公众号ID,由商户传入 timeStamp: res.payInfo.timeStamp, //时间戳,自1970年以来的秒数 nonceStr: res.payInfo.nonceStr, //随机串 package: res.payInfo.package, signType: res.payInfo.signType, //微信签名方式: paySign: res.payInfo.paySign }, (res) => { this.logList.push('支付回调: ' + JSON.stringify(res)); console.log(res, '支付'); if (res.err_msg == 'get_brand_wcpay_request:ok') { this.logList.push('支付成功'); uni.showToast({ title: '支付成功', icon: 'none' }); uni.navigateBackMiniProgram({ extraData: {}, success: function () { console.log('关闭应用成功'); }, fail: function () { console.log('关闭应用失败'); } }); } else if (res.err_msg == 'get_brand_wcpay_request:cancel') { this.logList.push('支付取消'); uni.showToast({ title: '支付取消,请重新扫码', icon: 'none' }); } else if (res.err_msg == 'get_brand_wcpay_request:fail') { this.logList.push('支付失败'); uni.showToast({ title: '支付失败,请重新扫码', icon: 'none' }); } else { this.logList.push('支付api: ' + res.err_msg); uni.showToast({ title:"支付api:" + res.err_msg, icon: 'none', duration:5000 }); } } ); }; if (typeof WeixinJSBridge == "undefined") { this.logList.push('WeixinJSBridge 未定义,等待事件...'); if (document.addEventListener) { document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false); } else if (document.attachEvent) { document.attachEvent('WeixinJSBridgeReady', onBridgeReady); document.attachEvent('onWeixinJSBridgeReady', onBridgeReady); } } else { this.logList.push('WeixinJSBridge 已定义,直接调用onBridgeReady'); onBridgeReady(); } } } }; </script> <style scoped lang="scss"> .box { width: 100%; height: 100%; box-sizing: border-box; display: flex; flex-direction: column; } </style>
星期六 17:41 - 使用snapshot uni微信小程序截屏报错 ?
预期效果想使用snapshot 对页面进行图片保存 但是调用后发现报错 不知道如何解决 使用的uniapp 请教各位大神解决办法
2023-12-07