Files
cunkebao_v3/Server/tests/device_qrcode_smoke.php
Manus AI b838ae8fc1 fix: 设备管理获取二维码 Endroid 3.9 枚举调用修复
生产 endroid/qr-code 3.9 要求 ErrorCorrectionLevel::HIGH() 实例化调用,
旧写法传字符串导致 /v1/api/device/add 返回 HTTP 500。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-25 12:20:34 +08:00

31 lines
918 B
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env php
<?php
/**
* 设备绑定二维码生成 smokeEndroid 3.9 ErrorCorrectionLevel 枚举调用)
*/
require dirname(__DIR__) . '/vendor/autoload.php';
use Endroid\QrCode\ErrorCorrectionLevel;
use Endroid\QrCode\QrCode;
$payload = json_encode([
'tenantGuid' => 'test-guid',
'deviceSocketHost' => 'wss://example.test',
'checkVersionUrl' => '',
'accountId' => 123,
], JSON_UNESCAPED_UNICODE);
$qrCode = new QrCode($payload);
$qrCode->setSize(300);
$qrCode->setMargin(10);
$qrCode->setWriterByName('png');
$qrCode->setEncoding('UTF-8');
$qrCode->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH());
$png = $qrCode->writeString();
assert(strlen($png) > 128, 'png binary too short');
$dataUri = 'data:image/png;base64,' . base64_encode($png);
assert(strpos($dataUri, 'data:image/png;base64,') === 0, 'data uri prefix');
echo "[PASS] device_qrcode ErrorCorrectionLevel::HIGH()\n";