Skip to content

Commit 7dfa410

Browse files
committed
[feat] qr decode
1 parent 6711b58 commit 7dfa410

6 files changed

Lines changed: 111 additions & 1 deletion

File tree

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,8 @@ Test-Driven development
5656

5757
- go-app-example
5858

59-
pwa
59+
build pwa program
60+
61+
- qrcode-decode
62+
63+
decode qr img

qrcode-decode/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
qrcode-decode
2+
*.jpg
3+
*.jpeg
4+
*.png
5+
6+
.idea
7+
.vscode
8+
9+
go.sum
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
repos:
2+
- repo: https://github.com/thlorenz/doctoc
3+
rev: v1.4.0
4+
hooks:
5+
- id: doctoc
6+
exclude: ^vendor/
7+
- repo: git://github.com/dnephin/pre-commit-golang
8+
rev: master
9+
hooks:
10+
- id: go-fmt
11+
exclude: ^vendor/
12+
- id: go-imports
13+
exclude: ^vendor/

qrcode-decode/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
2+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
3+
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
4+
5+
- [qrcode-decode](#qrcode-decode)
6+
- [使用](#%E4%BD%BF%E7%94%A8)
7+
- [致谢](#%E8%87%B4%E8%B0%A2)
8+
9+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
10+
11+
### qrcode-decode
12+
13+
二维码识别工具
14+
15+
### 使用
16+
17+
```sh
18+
# ronething @ ashings-macbook-pro in ~/Documents/qrcode-decode on git:master x [17:17:17]
19+
$ ./qrcode-decode -h
20+
qrcode-decode tool
21+
Usage: qrcode [-h help]
22+
Options:
23+
-h 帮助
24+
-p string
25+
图片文件路径 (default "./qrcode.png")
26+
27+
# ronething @ ashings-macbook-pro in ~/Documents/qrcode-decode on git:master x [17:17:21]
28+
$ ./qrcode-decode -p ./qrcode.jpeg
29+
2021/02/10 17:17:27 识别链接为 https://support.weixin.qq.com/cgi-bin/mmsupport-bin/showredpacket?receiveuri=xCvTj3TtrzF&check_type=1#wechat_redirect
30+
```
31+
32+
### 致谢
33+
34+
- github.com/tuotoo/qrcode

qrcode-decode/go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module qrcode-decode
2+
3+
go 1.13
4+
5+
require github.com/tuotoo/qrcode v0.0.0-20190222102259-ac9c44189bf2 // indirect

qrcode-decode/main.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"log"
7+
"os"
8+
9+
"github.com/tuotoo/qrcode"
10+
)
11+
12+
var (
13+
filePath string // 配置文件路径
14+
help bool // 帮助
15+
)
16+
17+
func usage() {
18+
fmt.Fprintf(os.Stdout, `qrcode-decode tool
19+
Usage: qrcode [-h help]
20+
Options:
21+
`)
22+
flag.PrintDefaults()
23+
}
24+
func main() {
25+
flag.StringVar(&filePath, "p", "./qrcode.png", "图片文件路径")
26+
flag.BoolVar(&help, "h", false, "帮助")
27+
flag.Usage = usage
28+
flag.Parse()
29+
if help {
30+
usage()
31+
return
32+
}
33+
file, err := os.Open(filePath)
34+
if err != nil {
35+
log.Printf("打开文件 %s 失败, %v\n", filePath, err.Error())
36+
return
37+
}
38+
defer file.Close()
39+
qrMatrix, err := qrcode.Decode(file)
40+
if err != nil {
41+
log.Println("识别二维码失败", err.Error())
42+
return
43+
}
44+
log.Printf("识别链接为 %s\n", qrMatrix.Content)
45+
}

0 commit comments

Comments
 (0)