add 生成二维码接口
This commit is contained in:
@@ -33,7 +33,16 @@
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.zxing</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<version>3.3.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.zxing</groupId>
|
||||
<artifactId>javase</artifactId>
|
||||
<version>3.3.0</version>
|
||||
</dependency>
|
||||
<!-- 如果需要微服务版本,则以上API注释,释放该API
|
||||
<dependency>
|
||||
<groupId>com.jero.boot</groupId>
|
||||
|
||||
+9
@@ -31,6 +31,8 @@ import com.jero.meeting.vo.WorkingGroupMeetingExel;
|
||||
import com.jero.modules.system.volid.group.UpdateGroup;
|
||||
import com.jero.project.entity.PayWorkingGroup;
|
||||
import com.jero.project.service.IPayWorkingGroupService;
|
||||
import com.jero.util.QrcodeUtil;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.jero.common.system.base.controller.JeroController;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
@@ -329,4 +331,11 @@ public class PayMeetingController extends JeroController<PayMeeting, IPayMeeting
|
||||
return Result.OK();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "生成base64")
|
||||
@GetMapping(value = "/createBase64")
|
||||
@ApiImplicitParam(name = "contact", value = "内容", required = true, paramType = "query")
|
||||
public Result<String> createBase64(String contact) {
|
||||
return Result.OK(QrcodeUtil.create(contact));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-1
@@ -240,11 +240,12 @@ public class PayMeetingSituationServiceImpl extends ServiceImpl<PayMeetingSituat
|
||||
payMeetingSituation1.setPayMode(payMode);
|
||||
//缴费方式为打包时,不处理邮寄联系人和地址
|
||||
if (payMode.equals(MeetingSubitemCommon.PAY_MODE_PACK)) {
|
||||
ValidUtil.validate(commonPeopleVO, NotPack.class);
|
||||
ValidUtil.validate(commonPeopleVO);
|
||||
//存入打包字段
|
||||
payMeetingSituation1.setPack(PayProjectCommon.PACKAGING1);
|
||||
payMeetingSituation1.setAmountReceivable(new BigDecimal(0));
|
||||
} else {
|
||||
ValidUtil.validate(commonPeopleVO, NotPack.class);
|
||||
|
||||
payMeetingSituation1.setNeedInvoice(payMeetingSituation.getNeedInvoice());
|
||||
payMeetingSituation1.setPaymentRecord(payMeetingSituation.getPaymentRecord());
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.jero.util;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.client.j2se.MatrixToImageConfig;
|
||||
import com.google.zxing.client.j2se.MatrixToImageWriter;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.qrcode.QRCodeWriter;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import org.checkerframework.checker.units.qual.K;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Base64;
|
||||
|
||||
/**
|
||||
* 生成二维码base64工具类
|
||||
* @author liJiaRao
|
||||
* @date 2021-07-15 10:15
|
||||
*/
|
||||
public class QrcodeUtil {
|
||||
/**
|
||||
* 蓝色
|
||||
*/
|
||||
public static final int BLUE = 0xFF23CEFD;
|
||||
/**
|
||||
* 蓝色
|
||||
*/
|
||||
public static final int BLACK = 0xFF000000;
|
||||
/**
|
||||
* 白色透明
|
||||
*/
|
||||
public static final int OFF_COLOR = 0x00FFFFFF;
|
||||
/**
|
||||
* 转换url为二维码base64
|
||||
* @param content 要转换的url
|
||||
* @return base64 data:image/png;base64,
|
||||
*/
|
||||
public static String create(String content){
|
||||
try {
|
||||
QRCodeWriter qrCodeWriter = new QRCodeWriter();
|
||||
BitMatrix bitMatrix = qrCodeWriter.encode(content, BarcodeFormat.QR_CODE, 600, 600);
|
||||
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
MatrixToImageWriter.writeToStream(bitMatrix, "PNG", outputStream, new MatrixToImageConfig(BLACK,OFF_COLOR));
|
||||
|
||||
Base64.Encoder encoder = Base64.getEncoder();
|
||||
|
||||
return "data:image/png;base64,"+encoder.encodeToString(outputStream.toByteArray());
|
||||
}catch (Exception e){
|
||||
throw new JeroBootException("生成二维码失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user