我们正在使用以下技术实现移动应用程序:
Node.JS和Express
MongoDB和猫鼬
颤振
假设我们应该生成包含商品信息(例如名称,价格,到期日期等)的QR码,这些信息应该是唯一的,并且每当客户扫描QR码时,都应通过连接到服务器,获取数据并添加所选内容来对其进行验证很好购物。
当我在互联网上搜索时,我发现我们应该将数据转换为画布(具有QR码)。有什么解决方案可以在服务器端生成QR码,并将其存储在mongodb中并进行验证?
这是我们的product.js文件:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var productSchema = new Schema({
productID: {
type: mongoose.Schema.Types.ObjectId,
required: true
},
name: {
type: String,
required: true,
trim: true
},
expirationDate: {
type: Date,
required: true
},
price: {
type: Number,
required: true,
trim: true
},
discount: {
type: Number,
default: 0,
trim: true
},
producer: {
type: String,
required: true
},
QRCode: {
type: String,
required: true
}
})
var Product = mongoose.model('Product', productSchema);
module.exports = Product;
答案 0 :(得分:1)
use jsqr,jimp we can decode the qr image and we will get data after that one we will compare the db and decoder data....
==========================================================================
npm i jimp, jsqr
const Jimp = require('jimp');
const jsQR = require("jsqr");
Jimp.read('./path/to/image.jpg')// image path use path.join(__dirname,'/fileName')
.then(image => {
const code = jsQR(image.bitmap.data,image.bitmap.width,image.bitmap.height);
if (code) {
console.log("Found QR code", code);
//comapre db data and code
}
})
.catch(err => {
// Handle an exception.
});
答案 1 :(得分:0)
THIS模块可能会为您提供帮助。它既可以在服务器上使用,也可以在客户端上使用,并具有使用它的所有详细信息。