我们正在使用以下技术实现一个移动应用程序:
假设我们应该生成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;发布于 2018-12-18 07:14:54
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.
});https://stackoverflow.com/questions/52204271
复制相似问题