排查 Android 管理 API 注册令牌 QR 代码生成中的 404 错误

问题描述 投票:0回答:1

我使用 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://colab.research.google.com/github/google/android-management-api-samples/blob/master/notebooks/quickstart.ipynb#scrollTo=TTSgnpC9EScx

enter image description here

google-api android-management-api
1个回答
0
投票

https://chart.googleapis.com/chart?cht=qr API 已弃用多年,现在终于被删除。您需要找到一种不同的方法来生成 QR 码。我建议您使用众多可用的二维码生成库之一,而不是依赖 api,因为:

    使用别人的服务器生成二维码存在安全风险
  1. 使用库时制作二维码非常简单。
您可以考虑使用

https://github.com/nayuki/QR-Code-generator

© www.soinside.com 2019 - 2024. All rights reserved.