Shop, menu, and booking storefronts with OIDC SSO, Pay checkout, and merchant.ladill.com deployment workflow. Co-authored-by: Cursor <cursoragent@cursor.com>
46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Support\Qr;
|
|
|
|
class QrWifiPayload
|
|
{
|
|
/**
|
|
* Build a WiFi QR payload (ZXing MECARD format) for one-tap network join on scan.
|
|
*
|
|
* @param array<string, mixed> $content
|
|
*/
|
|
public static function encode(array $content): string
|
|
{
|
|
$encryption = strtoupper(trim((string) ($content['encryption'] ?? 'WPA')));
|
|
$auth = $encryption === 'NOPASS' ? 'nopass' : $encryption;
|
|
if (! in_array($auth, ['WPA', 'WEP', 'nopass'], true)) {
|
|
$auth = 'WPA';
|
|
}
|
|
|
|
$ssid = self::escape(trim((string) ($content['ssid'] ?? '')));
|
|
$payload = 'WIFI:T:' . $auth . ';S:' . $ssid;
|
|
|
|
if ($auth !== 'nopass') {
|
|
$password = trim((string) ($content['password'] ?? ''));
|
|
if ($password !== '') {
|
|
$payload .= ';P:' . self::escape($password);
|
|
}
|
|
}
|
|
|
|
if (filter_var($content['hidden'] ?? false, FILTER_VALIDATE_BOOL)) {
|
|
$payload .= ';H:true';
|
|
}
|
|
|
|
return $payload . ';;';
|
|
}
|
|
|
|
private static function escape(string $value): string
|
|
{
|
|
return str_replace(
|
|
['\\', ';', ',', '"', ':'],
|
|
['\\\\', '\\;', '\\,', '\\"', '\\:'],
|
|
$value
|
|
);
|
|
}
|
|
}
|