package utils import ( "encoding/base64" "gitee.ltd/lxh/logger/log" "github.com/skip2/go-qrcode" ) type qrCode struct{} func QRCode() qrCode { return qrCode{} } // GenerateQrCodeBase64 // @description: 生成二维码 // @receiver qr // @param content // @param size // @return imgStr // @return err func (qr qrCode) GenerateQrCodeBase64(content []byte, size int) (imgStr string, err error) { q, err := qrcode.New(string(content), qrcode.Highest) if err != nil { log.Errorf("初始化二维码对象失败: %v", err.Error()) return } q.DisableBorder = false png, err := q.PNG(size) if err != nil { log.Errorf("生成二维码失败: %v", err.Error()) return "", err } imgStr = "data:image/png;base64," + base64.StdEncoding.EncodeToString(png) return }