數據採集目前最簡便的方式就是使用微信公衆號開發:微信提供的jsAPI,授權使用到的功能一是用戶授權,實現用戶的自動登錄;2是接調用手機攝像頭掃描二維碼,實現產品條碼或二維碼數據的採集。
核心代碼:
wx.ready(function () {
$(document).ready(function () {
$("#button").click(function () {
wx.scanQRCode({
needResult: 1, // 默認爲0,掃描結果由微信處理,1則直接返回掃描結果,
scanType: ["qrCode", "barCode"], // 可以指定掃二維碼還是一維碼,默認二者都有
success: function (res) {
var serialNumber = res.resultStr; // 當needResult 爲 1 時,掃碼返回的結果
var serial = serialNumber.split(",");
serialNumber = serial[serial.length - 1];
$('#barcode').val(serialNumber);
}
});
});
})
});
Done!