src/main/java/io/github/biezhi/wechat/utils/QRCodeUtils.java
public static void showQrCode(File qrCode, boolean terminal) throws WriterException {
        if (!terminal) {
            String os = System.getProperty("os.name").toLowerCase();
            try {
                if (os.contains("mac") || os.contains("win")) {
                    Desktop.getDesktop().open(qrCode);
                    return;
                }
            } catch (Exception e) {
                log.warn("在 {} 下打开文件 {} 失败", os, qrCode.getPath(), e);
            }
        }
        Map<EncodeHintType, Object> hintMap = new EnumMap<EncodeHintType, Object>(EncodeHintType.class);
        hintMap.put(EncodeHintType.CHARACTER_SET, "UTF-8");
        // Now with zxing version 3.2.1 you could change border size (white border size to just 1)
        // default = 4
        hintMap.put(EncodeHintType.MARGIN, 1);
        hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);

        String       qrContent    = QRCodeUtils.readQRCode(qrCode, hintMap);
        QRCodeWriter qrCodeWriter = new QRCodeWriter();
        BitMatrix    bitMatrix;
        bitMatrix = qrCodeWriter.encode(qrContent, BarcodeFormat.QR_CODE, 10, 10, hintMap);
        System.out.println(toAscii(bitMatrix));
    }
public static void showQrCode(File qrCode, boolean terminal) throws WriterException {
        if (!terminal) {
            String os = System.getProperty("os.name").toLowerCase();
            try {
                if (os.contains("mac") || os.contains("win")) {
                    Desktop.getDesktop().open(qrCode);
                    return;
                }
            } catch (Exception e) {
                log.warn("在 {} 下打开文件 {} 失败", os, qrCode.getPath(), e);
            }
        }
        Map<EncodeHintType, Object> hintMap = new EnumMap<EncodeHintType, Object>(EncodeHintType.class);
        hintMap.put(EncodeHintType.CHARACTER_SET, "UTF-8");
        // Now with zxing version 3.2.1 you could change border size (white border size to just 1)
        // default = 4
        hintMap.put(EncodeHintType.MARGIN, 1);
        hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);

        String       qrContent    = QRCodeUtils.readQRCode(qrCode, hintMap);
        QRCodeWriter qrCodeWriter = new QRCodeWriter();
        BitMatrix    bitMatrix;
        bitMatrix = qrCodeWriter.encode(qrContent, BarcodeFormat.QR_CODE, 10, 10, hintMap);
        System.out.println(toAscii(bitMatrix));
    }
public static void showQrCode ( File qrCode , boolean terminal ) throws WriterException { if ( ! terminal ) { String os = System . getProperty ( "os.name" ) . toLowerCase ( ) ; try { if ( os . contains ( "mac" ) || os . contains ( "win" ) ) { Desktop . getDesktop ( ) . open ( qrCode ) ; return ; } } catch ( Exception e ) { log . warn ( "在 {} 下打开文件 {} 失败", os, qrCode.get P th ( , e); } } Map < EncodeHintType , Object > hintMap = new EnumMap < EncodeHintType , Object > ( EncodeHintType . class ) ; hintMap . put ( EncodeHintType . CHARACTER_SET , "UTF-8" ) ; // Now with zxing version 3.2.1 you could change border size (white border size to just 1) // default = 4 hintMap . put ( EncodeHintType . MARGIN , 1 ) ; hintMap . put ( EncodeHintType . ERROR_CORRECTION , ErrorCorrectionLevel . L ) ; String qrContent = QRCodeUtils . readQRCode ( qrCode , hintMap ) ; QRCodeWriter qrCodeWriter = new QRCodeWriter ( ) ; BitMatrix bitMatrix ; bitMatrix = qrCodeWriter . encode ( qrContent , BarcodeFormat . QR_CODE , 10 , 10 , hintMap ) ; System . out . println ( toAscii ( bitMatrix ) ) ; }
显示二维码，Linux会显示在终端

@param qrCode
@param terminal
显示二维码，Linux会显示在终端