rentaiming
2024-06-07 2f1988b9b3047e64d1a7b85fbaf8518d16eb88ec
ruoyi-modules/ruoyi-auction/src/main/java/com/ruoyi/auction/util/CreateQrCode.java
@@ -5,8 +5,11 @@
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.ruoyi.system.api.util.HuaWeiOBSUtil;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Base64;
import java.util.HashMap;
@@ -35,4 +38,31 @@
        String text = encoder.encodeToString(outputStream.toByteArray());
        return base64Url + text;
    }
    /**
     * 创建二维码
     *
     * @param
     * @param
     * @return
     * @throws IOException
     * @throws WriterException
     */
    public static String createQRCodeToObs(String json) throws IOException, WriterException {
        QRCodeWriter qrCodeWriter = new QRCodeWriter();
        HashMap<EncodeHintType, Object> hints = new HashMap<>();
        hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
        BitMatrix bitMatrix = qrCodeWriter.encode(json, BarcodeFormat.QR_CODE, 600, 600, hints);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        MatrixToImageWriter.writeToStream(bitMatrix, "PNG", outputStream);
        InputStream is = new ByteArrayInputStream(
                outputStream.toByteArray());
        return HuaWeiOBSUtil.obsUploadStream(json, is);
    }
    public static void main(String[] args) throws IOException, WriterException {
        String qrCodeToObs = createQRCodeToObs("123456");
        System.out.println(qrCodeToObs);
    }
}