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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值