接着昨天的需求,不过此次不依赖微信,使用纯js唤醒手机本地摄像头或者选择手机相册图片,识别其中的二维码或者是条形码.昨天,我使用微信扫一扫识别,效果超棒的.不过若是依赖微信的话,又怎么实现呢,这里介绍两个js库,都很牛掰,感谢大神,献上连接.css
仓库:https://github.com/serratus/quaggaJS
html
官网: https://serratus.github.io/quaggaJS/android
识别二维码ios
条形码解析:git
我也是在网上找了一大堆,都失败了,别人博主写的都没头没尾的,没法实现其功能,既然有工具就一梭子的事情了,花费了一夜,终于弄出来了,下面就是设置参数的问题了github
甩出一个仓库,你们下载这个仓库就能够实现此功能的,不过条形码识别的准确性有点问题.须要设置对应的参数,其中须要修改代码web
........浏览器
// , 'code_39_reader','code_128_reader',"ean_reader", decoder: { readers: [{ format: ['ean_reader'], //条形码种类不少,选择适合本身的 config: {} }] },
........微信
二维码解析:app
这个没找到开源仓库,不过找到一个能够实现的DMEO,你们喜欢的话能够本身深究,我要去撸代码了.
个人仓库实例地址: https://gitee.com/guyandog/QR_BR 传送门
收集不易,点赞鼓励,谢谢
PS: 我这里是识别静态图片,若是是须要手机打开摄像头的,将input中添加这样的属性,以下:
<!DOCTYPE html> < html> < head> <meta charset="UTF-8"/> <title>index</title> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no"/> <meta name="apple-mobile-web-app-capable" content="yes"/> <meta name="apple-mobile-web-app-status-bar-style" content="black"/> <meta name="mobile-web-app-capable" content="yes"/> <meta name="format-detection" content="telephone=no"> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="Cache-Control" content="no-store, must-revalidate"> < /head> < body> < style> input{ display: block; width: 100px; height: 60px; background: red; color: white; font-size: 16px; line-height: 60px; outline: none; border: 0; } < /style> <input id="pictureB_file" accept="image/*" type="file" capture="camera" name="pictureA_file"/> < input id="pictureC_file" type="file" name="pictureA_file"/> < script> var u = navigator.userAgent, app = navigator.appVersion; var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //android终端或者uc浏览器 var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端 //alert('是不是Android:'+isAndroid); //alert('是不是iOS:'+isiOS); if (isAndroid) { //若是是安卓手机,就弹框是选择图片仍是拍照 $(".tankuang").css("display", "block"); } else { //若是是苹果系统,就还照以前的样子去操做便可 //$($("#pictureA_file")[0]).click(); } < /script> < /body> < /html>
参考网站:(感谢这些博客的博主)