go随聊-生成、识别二维码 - Go语言中文社区

go随聊-生成、识别二维码


QRCode

        QR Code码,是由Denso公司于1994年9月研制的一种矩阵二维码符号,它具有一维条码及其它二维条码所具有的信息容量大、可靠性高、可表示汉字及图象多种文字信息、保密防伪性强等优点。

生成二维码

skip2/go-qrcode

地址:https://github.com/skip2/go-qrcode

ackage qrcode implements a QR Code encoder. 

A QR Code is a matrix (two-dimensional) barcode. Arbitrary content may be encoded, with URLs being a popular choice :)

Each QR Code contains error recovery information to aid reading damaged or obscured codes. There are four levels of error recovery: Low, medium, high and highest. QR Codes with a higher recovery level are more robust to damage, at the cost of being physically larger.

安装

go get -u github.com/skip2/go-qrcode/...

生成二维码例子

import (
	"fmt"

	"github.com/skip2/go-qrcode"
)

func main() {
	err := qrcode.WriteFile("hello world", qrcode.Highest, 256, "d://qr.png")
	if err!=nil {
		fmt.Println(err)
	}
}

识别二维码

tuotoo/qrcode

地址:https://github.com/tuotoo/qrcode

安装

go get github.com/tuotoo/qrcode

识别二维码例子

import (
	"os"
	"fmt"

	"github.com/tuotoo/qrcode"
)

func main() {
	file, err := os.Open("d://qr.png")
	if err != nil{
		fmt.Println(err)
		return
	}
	defer file.Close()
	//识别二维码
	qr, err := qrcode.Decode(file)
	if err != nil{
		fmt.Println(err.Error())
		return
	}
	fmt.Println(qr.Content)
}
----------------------------------------------------
hello world

识别刚才生成的二维码图片,输出hello world

 

版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/yimin_tank/article/details/83719041
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-04-18 12:57:02
  • 阅读 ( 1298 )
  • 分类:Go

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢