1 Star 0 Fork 0

linngc / central-mirror

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
qrcode.go 763 Bytes
一键复制 编辑 原始数据 按行查看 历史
linngc 提交于 2024-03-19 17:47 . add:添加生成验证码工具
// Package qrcode
// @Link https://gitee.com/linngc/central-mirror
// @Copyright Copyright (c) 2024 central-mirror CLI
// @Author linngc
// @License
package qrcode
import (
"context"
"fmt"
"github.com/gogf/gf/v2/frame/g"
"github.com/skip2/go-qrcode"
tuotoo "github.com/tuotoo/qrcode"
"io"
)
// CreatePng 生成二维码
// @param content 二维码内容
func CreatePng(ctx context.Context, content string) []byte {
png, err := qrcode.Encode(content, qrcode.Medium, 256)
if err != nil {
g.Log().Errorf(ctx, "创建二维码失败,-->%s", err)
return nil
}
return png
}
// Read 读取二维码内容
func Read(fi io.Reader) string {
qr, err := tuotoo.Decode(fi)
if err != nil {
fmt.Println(err.Error())
return ""
}
return qr.Content
}
Go
1
https://gitee.com/linngc/central-mirror.git
git@gitee.com:linngc/central-mirror.git
linngc
central-mirror
central-mirror
4aaf4b1e930c

搜索帮助

53164aa7 5694891 3bd8fe86 5694891