qrcode “github.com/skip2/go-qrcode”

png,_:= qrcode.Encode("https://example.org", qrcode.Medium, 256)
    fmt.Println(png)
    qrcode.WriteFile("https://example.org", qrcode.Medium, 256, "qr.png")
    qrcode.WriteColorFile("彩色二维码", qrcode.Medium, 256, color.RGBA{11,22,44,90}, color.White, "qr1.png")

github.com/mojocn/base64Captcha
在gin中

var store = base64Captcha.DefaultMemStore
func code(c *gin.Context) {
        //driver := base64Captcha.DefaultDriverDigit //默认数字
        //driver:= base64Captcha.NewDriverString(60,240,0,0,5,"1234567890ABCDEFGHIJKLMNPQRSTUVWXYZ",nil,nil) //字符
        driver:=base64Captcha.NewDriverMath(60,240,0,0,nil,nil) //算式
        rs := base64Captcha.NewCaptcha(driver, store)
        id, b64s, _ := rs.Generate()
        fmt.Println(id)
        i := strings.Index(b64s, ",")
        dec := base64.NewDecoder(base64.StdEncoding, strings.NewReader(b64s[i+1:]))
        c.Header("Content-Type","image/png")
        io.Copy(c.Writer, dec)
}
func verify(id string, val string) bool {
    if id == "" || val == ""{
        return false
    }
    return store.Verify(id, val, true)
}
文档更新时间: 2021-11-04 19:14   作者:Yoby