js实现扫描付款码获取数据

543 阅读1分钟

使用FNScanner的工具,具体如下

~function (W) { var FNScanner = false; W.FNScanner = function (callBack) { if (!FNScanner) { FNScanner = api.require('FNScanner'); } if (!callBack) { callBack = function () { } } FNScanner.openScanner({ autorotation: true }, callBack); } }(this)

然后可以调用手机的拍照功能了

api.addEvt(api.dom('.scan-code'), 'click', function () { FNScanner(function (ret, err) { if (ret) { console.log(JSON.stringify(ret)) setTimeout(function () { if (ret.content) { console.log(JSON.stringify(ret)) /* 这里跳转到设备页面 */ ROUTER.linkTo('scanCodePay', { id: ret.content // source: 'myDecive', // shopid: api.pageParam.shopid || '' }); } }, 100) } }); })

扫描后在跳转的页面监听事件然后向后端发送,并接受后端的数据展示在html中。