1、依赖
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>4.6.10</version>
</dependency>
2、hutooL生成
@GetMapping("/weixinLogin/{context}")
@ResponseBody
public void createQRCode(HttpServletResponse response,@PathVariable("context") String token) {
try {
QrCodeUtil.generate(token, initQrConfig(), "png", response.getOutputStream());
log.info("生成二维码成功!");
} catch (QrCodeException | IOException e) {
log.error("发生错误! {}!", e.getMessage());
}
}
private static QrConfig initQrConfig() {
QrConfig config = new QrConfig(300, 300);
config.setMargin(3);
config.setForeColor(Color.CYAN.getRGB());
config.setBackColor(Color.GRAY.getRGB());
return config;
}