Payloads

laravel-go-qrcode Alpha Laravel for Go

A QR code holds text. Phones act on some formats: they open an email draft, dial a number or join a WiFi network. Each payload type builds that text; pass the result to any render method.

text, err := qrcode.PhoneNumber{Number: "+32 9 123 45 67"}.Payload()
if err != nil {
	return err
}
png, err := g.PNG(text)

Optional fields are pointers: leave them nil to omit them.

TypeFieldsExample output
qrcode.EmailTo, Subject *string, Body *stringA draft with a prefilled subject
qrcode.PhoneNumberNumbertel:+32-9-123-45-67
qrcode.SMSNumber, Body *stringsms:+3291234567?body=See%20you%20at%208
qrcode.GeoLatitude, Longitudegeo:51.05,3.72
qrcode.WiFiSSID, Auth, Password *string, Hidden *boolWIFI:T:WPA;S:Guest;P:guest-code;
qrcode.BitcoinAddress, Amount *string, Label *string, Message *string, ReturnURL *stringbitcoin:bc1qexample?amount=0.001

Invalid fields return qrcode.ErrInvalidPayload: a phone number with characters that don't belong in one, coordinates outside ±90 and ±180, or a Bitcoin amount that isn't a plain decimal.

WiFi

password := "guest-code"
hidden := true
text, err := qrcode.WiFi{
	SSID:     "Guest",
	Auth:     qrcode.WiFiWPA,
	Password: &password,
	Hidden:   &hidden,
}.Payload()

Auth is qrcode.WiFiWPA (WPA and WPA2), qrcode.WiFiSAE (WPA3), qrcode.WiFiWEP, qrcode.WiFiNoPassword (an open network, stated) or qrcode.WiFiOpen (the field left out). The package escapes ;, ,, :, \ and " in the SSID and password.

Differences from PHP

  • Email uses %20 for spaces and CRLF in the message body.
  • Phone numbers use hyphens as visual separators where the input contains spaces.
  • SMS requires a recipient and percent-escapes the ?body= query. RFC 5724
  • Geo formats coordinates as decimal degrees, including very small values.
  • WiFi escapes delimiters and writes an explicit boolean as true or false. Simple QrCode #333
  • Bitcoin takes an exact decimal string. It percent-escapes query values and omits the question mark when all parameters are unset.