Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wxBot
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
wxBot
Commits
3346c9cb
Commit
3346c9cb
authored
Jul 23, 2017
by
fangzhipeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加linux控制台输出二维码
parent
0d1712ed
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
9 deletions
+54
-9
pom.xml
pom.xml
+8
-0
result.png
result.png
+0
-0
src/main/java/com/yg84/weixin/WeChat.java
src/main/java/com/yg84/weixin/WeChat.java
+46
-9
No files found.
pom.xml
View file @
3346c9cb
...
...
@@ -62,6 +62,14 @@
<version>
3.3.0
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-lang/commons-lang -->
<dependency>
<groupId>
commons-lang
</groupId>
<artifactId>
commons-lang
</artifactId>
<version>
2.6
</version>
</dependency>
</dependencies>
<build>
...
...
result.png
View replaced file @
0d1712ed
View file @
3346c9cb
1.49 KB
|
W:
|
H:
1.48 KB
|
W:
|
H:
2-up
Swipe
Onion skin
src/main/java/com/yg84/weixin/WeChat.java
View file @
3346c9cb
...
...
@@ -6,7 +6,12 @@ import com.google.zxing.BarcodeFormat;
import
com.google.zxing.EncodeHintType
;
import
com.google.zxing.MultiFormatWriter
;
import
com.google.zxing.common.BitMatrix
;
import
com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
;
import
com.google.zxing.qrcode.encoder.ByteMatrix
;
import
com.google.zxing.qrcode.encoder.Encoder
;
import
com.google.zxing.qrcode.encoder.QRCode
;
import
com.squareup.okhttp.*
;
import
org.apache.commons.lang.SystemUtils
;
import
java.io.File
;
import
java.net.CookieManager
;
...
...
@@ -83,6 +88,7 @@ public class WeChat {
private
MessageHandler
handler
;
public
WeChat
(
MessageHandler
handler
)
{
System
.
setProperty
(
"jsse.enableSNIExtension"
,
"false"
);
if
(
handler
==
null
)
this
.
handler
=
new
DefaultMessageHandler
(
this
);
else
...
...
@@ -247,17 +253,48 @@ public class WeChat {
private
void
genQRCode
(
String
uuid
)
throws
Exception
{
String
text
=
String
.
format
(
QR_CODE_URL
,
uuid
);
// 二维码内容
int
width
=
300
;
// 二维码图片宽度
int
height
=
300
;
// 二维码图片高度
String
format
=
"png"
;
// 二维码的图片格式
Hashtable
<
EncodeHintType
,
String
>
hints
=
new
Hashtable
<
EncodeHintType
,
String
>();
hints
.
put
(
EncodeHintType
.
CHARACTER_SET
,
"utf-8"
);
// 内容所使用字符集编码
BitMatrix
bitMatrix
=
new
MultiFormatWriter
().
encode
(
text
,
BarcodeFormat
.
QR_CODE
,
width
,
height
,
hints
);
// 生成二维码
File
outputFile
=
new
File
(
"./result.png"
);
MatrixToImageWriter
.
writeToFile
(
bitMatrix
,
format
,
outputFile
);
Runtime
run
=
Runtime
.
getRuntime
();
run
.
exec
(
"open "
+
outputFile
.
getAbsolutePath
());
QRCode
qrCode
=
Encoder
.
encode
(
text
,
ErrorCorrectionLevel
.
L
,
hints
);
if
(
SystemUtils
.
IS_OS_LINUX
)
{
byte
[][]
matrix
=
qrCode
.
getMatrix
().
getArray
();
System
.
out
.
print
(
"\033[47;30m \033[0m"
);
for
(
int
i
=
0
;
i
<
matrix
.
length
;
i
++)
{
System
.
out
.
print
(
"\033[47;30m \033[0m"
);
}
System
.
out
.
println
(
"\033[47;30m \033[0m"
);
for
(
int
i
=
0
;
i
<
matrix
.
length
;
i
++)
{
System
.
out
.
print
(
"\033[47;30m \033[0m"
);
for
(
int
j
=
0
;
j
<
matrix
[
i
].
length
;
j
++)
{
if
(
matrix
[
i
][
j
]
==
1
)
{
System
.
out
.
print
(
"\033[40;37m \033[0m"
);
}
else
{
System
.
out
.
print
(
"\033[47;30m \033[0m"
);
}
}
System
.
out
.
println
(
"\033[47;30m \033[0m"
);
}
System
.
out
.
print
(
"\033[47;30m \033[0m"
);
for
(
int
i
=
0
;
i
<
matrix
.
length
;
i
++)
{
System
.
out
.
print
(
"\033[47;30m \033[0m"
);
}
System
.
out
.
println
(
"\033[47;30m \033[0m"
);
}
else
if
(
SystemUtils
.
IS_OS_WINDOWS
){
}
else
if
(
SystemUtils
.
IS_OS_MAC
)
{
int
width
=
300
;
// 二维码图片宽度
int
height
=
300
;
// 二维码图片高度
String
format
=
"png"
;
// 二维码的图片格式
BitMatrix
bitMatrix
=
new
MultiFormatWriter
().
encode
(
text
,
BarcodeFormat
.
QR_CODE
,
width
,
height
,
hints
);
// 生成二维码
File
outputFile
=
new
File
(
"./result.png"
);
MatrixToImageWriter
.
writeToFile
(
bitMatrix
,
format
,
outputFile
);
Runtime
run
=
Runtime
.
getRuntime
();
run
.
exec
(
"open "
+
outputFile
.
getAbsolutePath
());
}
else
{
throw
new
RuntimeException
(
"未知操作系统平台,无法生成二维码"
);
}
}
private
void
genSyncKey
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment