我正在尝试为我的最后一年项目复制 web whatsapp QRCode 身份验证,这是一个在线医疗管理系统。在这个系统中,长话短说,医生只有在患者允许的情况下才能查看患者的处方,并且当他从他的应用程序中扫描由医生配置文件生成的二维码时,应给予该许可,该应用程序在套接字事件上发送 authStatus这将使服务器能够重定向到患者记录路由。
服务器套接字设置如下:
router.get('/patientinfoqrcode',redirectRoutes.redirectLoginDoctor,function(req,res){
let usernameQR = req.query.usernameQR
let message='';
io.on("connection",function(socket){
console.log("The user has been connected")
io.on("disconnect",function(){
console.log("The user has been disconnected")
})
socket.on("Auth",function(data){
if(data.authStatus=='authorized'){
res.redirect(`/dashboard?usernamePatient=${usernameQR}`)
}
});
})
res.render('doctor/patientinfoqrcode',{usernameQR})
});
nativescript 应用程序设置如下:
const socketio = SocketIO.connect('https://secret-falls-76814.herokuapp.com/patientinfoqrcode'
, options);
export function scanQR(args) {
barcodescanner.scan({
formats: "QR_CODE", // Pass in of you want to restrict scanning to certain type
message: "Use the volume buttons for extra light", // Android only, default is 'Place a barcode inside the viewfinder rectangle to scan it.'
showFlipCameraButton: true, // default false
preferFrontCamera: false, // default false
showTorchButton: true, // default false
beepOnScan: true, // Play or Suppress beep on scan (default true)
torchOn: false, // launch with the flashlight on (default false)
closeCallback: function () { console.log("Scanner closed"); }, // invoked when the scanner was closed (success or abort)
resultDisplayDuration: 500, // Android only, default 1500 (ms), set to 0 to disable echoing the scanned text
orientation: "landscape", // Android only, optionally lock the orientation to either "portrait" or "landscape"
openSettingsIfPermissionWasPreviouslyDenied: true // On iOS you can send the user to the settings app if access was previously denied
}).then(
function(result) {
console.log("Scan format: " + result.format);
console.log("Scan text: " + result.text);
const button = args.object;
button.text = result.text;
socketio.emit('Auth',{
authStatus:'authorized'
});
},
function(error) {
console.log("No scan: " + error);
}
);
}
而且它不像它应该的那样工作。我认为唯一的问题是监听事件的 socket.io 在 /patientinfoqrcode 路由内,并且该路由在加载时执行其中的所有功能。然后,即使在 router.get() 的主体内发生了某些事情,也不会发生任何事情,因为它已经呈现了文档。服务器整个项目上传到heroku