生成订单核销二维码,扫码完成核销
需求:
- 用户端:根据用户支付成功的订单商品,生成核销二维码
- 店员端:扫描客户的二维码,获取二维码信息,验证判断二维码是否正确,根据二维码信息,获取用户 信息,完成核销功能
步骤
1.对用户订单号进行加密加钥处理 2.利用QRcode生成二维码 3.使用uni.scanCode获取二维码信息 4.对信息进行解密,判断是否正确
源码
导入qrcode.js import qrCode from "../../common/weapp-qrcode.js"; 对信息加密加钥,保存信息使用qrcode生成二维码
this.$refs.writeoff.open()
let key = 13_9993wp_s#a52dx1p_; //请勿随意修改
let data = key + this.UserInfo.member_id.toString(),
width = 330 / 750 * wx.getSystemInfoSync().windowWidth,
height = 330 / 750 * wx.getSystemInfoSync().windowWidth,
code = new Buffer(data).toString(base64);
console.log(code, code)
let QRcode = new qrCode(couponQrcode_0, {
render: canvas,
text: code,
width: width,
height: height,
colorDark: "#000000",
colorLight: "#ffffff",
correctLevel: qrCode.CorrectLevel.H
})
uni.hideTabBar({
animation: true
});
setTimeout(() => {
this.BillCode = true
}, 390)
效果图
扫码
对信息解密,判断二维码是否正确,
uni.scanCode({
onlyFromCamera: true,
success: function(res) {
setTimeout(() => {
uni.hideLoading();
let data = res.result.toString(),
MaskData = new Buffer(data, base64).toString(utf8),
arrayresult = MaskData.toString().split(_);
if (res.result.toString().length > 0 && arrayresult.length > 0 &&
arrayresult[2] === s#a52dx1p) {
let memberId = arrayresult[3]
uni.navigateTo({
url: `../Mineday/billingCode?memberInfo=${
memberId}`
})
} else if (arrayresult[1] == Rts) {
uni.showToast({
title: "请出示开单码",
icon: "error",
duration: 2500
})
} else {
uni.showToast({
title: "二维码错误",
icon: "error",
duration: 2500
})
}
}, 1000)
},
fail: function(error) {
setTimeout(() => {
uni.hideLoading();
}, 20)
},
complete: function(res) {
uni.showLoading({
title: 识别中...,
mask: true,
});
},
})
上一篇:
uniapp开发微信小程序-2.页面制作
下一篇:
微信小程序解决多个视频播放的问题
