当前位置:网站首页>Wechat payment QR code generation
Wechat payment QR code generation
2022-06-22 13:06:00 【Wandering hunter】
The QR code of wechat payment is based on payment related information , Go to wechat server to apply for payment QR code , Then display the QR code content on the website , In this way, the user can pay for the order .
1、 Generate pictures
public static BufferedImage drawImage(String content, String imgPath, boolean needCompress) throws Exception {
Hashtable<EncodeHintType, Object> hints = new Hashtable<>();
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
hints.put(EncodeHintType.CHARACTER_SET, CHARSET);
hints.put(EncodeHintType.MARGIN, 1);
BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, QRCODE_SIZE, QRCODE_SIZE,
hints);
bitMatrix = deleteWhite(bitMatrix);
int width = bitMatrix.getWidth();
int height = bitMatrix.getHeight();
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF);
}
}
return image;
}
2、 Insert a picture
private static void insertImage(BufferedImage source, String imgPath, boolean needCompress) throws Exception {
File file = new File(imgPath);
if (!file.exists()) {
System.err.println("" + imgPath + " The file does not exist !");
return;
}
Image src = ImageIO.read(new File(imgPath));
int width = src.getWidth(null);
int height = src.getHeight(null);
if (needCompress) {
// Compress LOGO
if (width > WIDTH) {
width = WIDTH;
}
if (height > HEIGHT) {
height = HEIGHT;
}
Image image = src.getScaledInstance(width, height, Image.SCALE_SMOOTH);
BufferedImage tag = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = tag.getGraphics();
g.drawImage(image, 0, 0, null); // Draw a reduced image
g.dispose();
src = image;
}
// Insert LOGO
Graphics2D graph = source.createGraphics();
int x = (QRCODE_SIZE - width) / 2;
int y = (QRCODE_SIZE - height) / 2;
graph.drawImage(src, x, y, width, height, null);
Shape shape = new RoundRectangle2D.Float(x, y, width, width, 6, 6);
graph.setStroke(new BasicStroke(3f));
graph.draw(shape);
graph.dispose();
}
3、 Convert the picture to Base64
try(ByteArrayOutputStream outputStream = new ByteArrayOutputStream();) {
BufferedImage image = QRCodeUtil.createImage(codeUrl , null, false);
ImageIO.write(image, "jpg", outputStream);
String base64Str = "data:image/jpeg;base64,"+new BASE64Encoder().encode(outputStream.toByteArray());
} catch (Exception e) {
log.error(e.getMessage(),e);
}
边栏推荐
- Fluent: split statefulwidget -- simplify page development, jump and value transfer
- Sap-abap- how to transfer material master data, supplier master data, work orders, purchase orders and other information to external systems in real time - implicit enhancement.
- Parallels Desktop 17.1.4pd virtual machine
- Universaldependencies dependency label interpretation
- 记录阿里云ECS实例重启之后无法登录解决方法(亲身实践)
- [Jishu reading] arm64 learning experience sharing by running bar community
- 微信支付二维码生成
- 老王说系列第六期:PHP程序员要建立自己的自信心
- Tis tutorial 03 export
- access_token不到两个小时失效的处理办法
猜你喜欢

ffmpeg将amr格式转成mp3格式

Tis tutorial 04 client

On the routing tree of gin

CVPR 2022 | 针对场景文本检测的视觉语言模型预训练

Sap-abap- how to find a table and what related tables the fields have

这不会又是一个Go的BUG吧?

A2L file analysis based on CAN bus (1)

SequoiaDB分布式数据库2022.5月刊

Tis tutorial 03 export

Jushan database was invited to attend Kunpeng developers' annual event 2022 to jointly build a domestic digital base
随机推荐
微信公众号开发注意事项
SAP-ABAP-如何打开本地文件
MySQL_创建和管理表
[game] Zhou Yu's skills
Repair flutter_ webview_ The problem of web layer residue when the plugin slides out of the page
Hurun Research Institute launched the list of potential enterprises of China's meta universe, and Jushan database was selected as the future star enterprise
SAP 系统取消用户设置ALV全局布局
Getting started with webrtc: 11 In kurento, rtendpoint is used to pull RTP streams for clustering in live broadcast
SAP-ABAP-如何实时传输物料主数据,供应商主数据,工单,采购订单等信息给外部系统-隐式增强。
MySQL_数据处理之增删改
SAP fi financial statement version setting
SequoiaDB分布式数据库2022.5月刊
Tianyi cloud digital government smart data center has passed the certification
2022-6-21os review group linking method
In depth analysis of glide source code
Heavyweight live | bizdevops: the way to break the technology situation under the tide of digital transformation
SAP-ABAP-SE14丢失的数据如何恢复
SAP-ABAP-BAPI_GOODSMVT_CREATE创建物料凭证bapi的各种情况如何赋值
关于 GIN 的路由树
Reddit product director: a practical guide for NFT members for Web3 creators