|
|
@@ -6,14 +6,23 @@ import com.etotem.cfc.common.Result;
|
|
|
import com.etotem.cfc.entity.PackageOrder;
|
|
|
import com.etotem.cfc.service.PaymentService;
|
|
|
import com.etotem.cfc.service.WechatService;
|
|
|
+import com.google.zxing.BarcodeFormat;
|
|
|
+import com.google.zxing.EncodeHintType;
|
|
|
+import com.google.zxing.client.j2se.MatrixToImageWriter;
|
|
|
+import com.google.zxing.qrcode.QRCodeWriter;
|
|
|
+import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import javax.imageio.ImageIO;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.Hashtable;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
@@ -154,4 +163,22 @@ public class PaymentController {
|
|
|
|
|
|
return Result.success(order);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成支付二维码图片
|
|
|
+ */
|
|
|
+ @Operation(summary = "生成支付二维码")
|
|
|
+ @GetMapping("/qrcode")
|
|
|
+ public void generateQrCode(String text, HttpServletResponse response) throws Exception {
|
|
|
+ int size = 280;
|
|
|
+ Hashtable<EncodeHintType, Object> hints = new Hashtable<>();
|
|
|
+ hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
|
|
|
+ hints.put(EncodeHintType.MARGIN, 1);
|
|
|
+ QRCodeWriter writer = new QRCodeWriter();
|
|
|
+ com.google.zxing.common.BitMatrix bitMatrix = writer.encode(text, BarcodeFormat.QR_CODE, size, size, hints);
|
|
|
+ BufferedImage image = MatrixToImageWriter.toBufferedImage(bitMatrix);
|
|
|
+ response.setContentType("image/png");
|
|
|
+ response.setHeader("Cache-Control", "public, max-age=3600");
|
|
|
+ ImageIO.write(image, "png", response.getOutputStream());
|
|
|
+ }
|
|
|
}
|