分销二维码接口
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package com.czg.service.market.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.codec.Base64Encoder;
|
||||
import cn.hutool.extra.qrcode.QrCodeUtil;
|
||||
import com.czg.market.dto.MkDistributionConfigDTO;
|
||||
import com.czg.market.entity.MkDistributionConfig;
|
||||
import com.czg.market.entity.MkDistributionLevelConfig;
|
||||
@@ -16,6 +18,11 @@ import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 分销配置 服务层实现。
|
||||
*
|
||||
@@ -55,4 +62,27 @@ public class MkDistributionConfigServiceImpl extends ServiceImpl<MkDistributionC
|
||||
|
||||
return updateById(config);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String rechargeQrCode(Long shopId, BigDecimal amount) {
|
||||
try {
|
||||
// 生成二维码图片
|
||||
BufferedImage image = QrCodeUtil.generate(
|
||||
"https://cashier.sxczgkj.com/payTest?shopId=" + shopId + "&amount=" + amount,
|
||||
500,
|
||||
500
|
||||
);
|
||||
|
||||
// 转为字节流
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
ImageIO.write(image, "png", os);
|
||||
|
||||
// 转 Base64
|
||||
String base64 = Base64Encoder.encode(os.toByteArray());
|
||||
return "data:image/png;base64," + base64;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("生成二维码失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user