我使用 Node.js 中的 Google Android Management API 开发了一个移动设备管理应用程序。应用程序运行正常,但现在当我使用二维码创建注册令牌时遇到 404 未找到错误。您能建议一个解决方案来解决这个问题吗?
这是代码
const createEnrollmentToken = async (req,res,policyId) => {
try {
if (global.collectionExists) {
console.log(`Collection already exists. Data will not be stored.`);
} else {
// Qr Code Exapraition time setting for 1000 years
const durationInYears = 1000;
const secondsInYear = 365.25 * 24 * 60 * 60; // 365.25 days in a year to account for leap years
const durationInSeconds = durationInYears * secondsInYear;
const enrollmentToken = await androidManagementClient.enterprises.enrollmentTokens.create({
parent: global.enterpriseName,
requestBody: {
policyName: policyId,
duration: `${durationInSeconds}s`,
}
});
console.log('Enrollment token created successfully:', enrollmentToken.data);
try {
/* qr image */
const policies = await PoliciesDataModel.find({ username: global.adminUserName, "Polices.policyName": req.body.policyId });
if (policies && policies.length > 0) {
const image = {
'cht': 'qr', //cht represents the type of the chart or image, and its value is set to 'qr'.
'chs': '320x320', //chs specifies the size of the chart or image, and its value is set to '500x500', indicating a width and height of 500 pixels each.
'chl': enrollmentToken.data.qrCode //chl is the URL or data for the chart or image, and its value is taken from enrollmentToken.data.qrCode.
};
console.log(enrollmentToken.data.qrCode )
const qrcodeImgUrl = 'https://chart.googleapis.com/chart?' + querystring.stringify(image);
console.log('qrcodeImgUrl : ', qrcodeImgUrl)
const qrDoc = {
QrcodeImg: qrcodeImgUrl,
expiredDateTime: enrollmentToken.data.expirationTimestamp
};
} else {
// If no policies were found, send a not found response
console.log('No policies found for the given email and policy name.');
await res.redirect('/provision-Template');
}
} catch (error) {
console.log("Update Error", error)
}
// expiredDateTime: enrollmentToken.data.expirationTimestamp
await res.redirect('/provision-Template');
}
} catch (error) {
console.error('Error creating enrollment token:', error.message);
}
};
https://chart.googleapis.com/chart?cht=qr API 已弃用多年,现在终于被删除。您需要找到一种不同的方法来生成 QR 码。我建议您使用众多可用的二维码生成库之一,而不是依赖 api,因为:
https://github.com/nayuki/QR-Code-generator。