vue-h5调用支付宝小程序扫一扫功能
1,引入js
<script>
if (navigator.userAgent.indexOf('AlipayClient') > -1) {
document.writeln('<script src="https://appx/web-view.min.js"' + '>' + '<' + '/' + 'script>');
}
</script>
2,扫一扫代码块
let vm = this
if(utils.isAliClient()) {
my.postMessage({
$type: 'scan',
hideAlbum: true,
})
my.postMessage({
$type: 'USER_INFO'
})
my.onMessage = function(e) {
if(e.$type === "scan") {
vm.uuid = e.code.split('=')[1]
}
if(e.$type === "USER_INFO") {
vm.token = e.wanxiaoToken
}
if(vm.uuid&&vm.token) {
window.location.href = `http://api.text.com/operation/pub/iface/pc/scanCode?uuid=${vm.uuid}&token=${vm.token}`
}
}
}