1. 生成:
    boombuler/barcode

     package main
     import (
         "github.com/boombuler/barcode"
         "github.com/boombuler/barcode/qr"
         "image/png"
         "os"
     )
     func main() {
         qrCode, _ := qr.Encode("hello world", qr.M, qr.Auto)
         qrCode, _ = barcode.Scale(qrCode, 256, 256)
         file, _ := os.Create("qr.png")
         defer file.Close()
         png.Encode(file, qrCode)
     }
  2. 解析:
    tuotoo/qrcode

     package main
     import (
         "fmt"
         "os"
         "github.com/tuotoo/qrcode"
     )
     func main() {
         fi, err := os.Open("qr.png")
         if err != nil {
             fmt.Println(err.Error())
             return
         }
         defer fi.Close()
         qrmatrix, err := qrcode.Decode(fi)
         if err != nil {
             fmt.Println(err.Error())
             return
         }
         fmt.Println(qrmatrix.Content)
     }
文档更新时间: 2024-04-20 10:57   作者:lee