生产 endroid/qr-code 3.9 要求 ErrorCorrectionLevel::HIGH() 实例化调用, 旧写法传字符串导致 /v1/api/device/add 返回 HTTP 500。 Co-authored-by: Cursor <cursoragent@cursor.com>
31 lines
918 B
PHP
31 lines
918 B
PHP
#!/usr/bin/env php
|
||
<?php
|
||
/**
|
||
* 设备绑定二维码生成 smoke(Endroid 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";
|