Browse Source

1、二维码图片识别解析逻辑调测

2、方法名变更
master
bjang03 7 months ago
parent
commit
28d254e918
  1. 6
      win-module-eam/win-module-eam-biz/pom.xml
  2. 9
      win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/licences/LicencesController.java
  3. 6
      win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/service/licences/LicencesService.java
  4. 14
      win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/service/licences/LicencesServiceImpl.java

6
win-module-eam/win-module-eam-biz/pom.xml

@ -124,12 +124,6 @@
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.3.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

9
win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/licences/LicencesController.java

@ -29,14 +29,14 @@ public class LicencesController {
@Resource
private LicencesService licencesService;
@PostMapping("/licenceDiscernByCodeFile")
@PostMapping("/licencesDiscernByCodeImage")
@Operation(summary = "识别续期许可(二维码图片)")
@Parameters({
@Parameter(name = "file", description = "续期二维码图片", required = true)
})
@PreAuthorize("@ss.hasPermission('basic:licences:licenceDiscern')")
public CommonResult<Boolean> licenceDiscernByCodeFile(@Valid @NotNull @RequestParam("file") MultipartFile file) throws IOException {
licencesService.licencesDiscern(QrCodeUtil.decode(file.getInputStream()));
public CommonResult<Boolean> licencesDiscernByCodeImage(@Valid @NotNull @RequestParam("file") MultipartFile file) throws IOException {
licencesService.licencesDiscernByCodeImage(file);
return success(true);
}
@ -47,9 +47,10 @@ public class LicencesController {
})
@PreAuthorize("@ss.hasPermission('basic:licences:licenceDiscern')")
public CommonResult<Boolean> licenceDiscernByCodeStr(@RequestBody String code) {
licencesService.licencesDiscern(code);
licencesService.licenceDiscernByCodeStr(code);
return success(true);
}
@PostMapping("/generateLicence")
@Operation(summary = "生成续期二维码")
@PreAuthorize("@ss.hasPermission('basic:licences:licenceDiscern')")

6
win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/service/licences/LicencesService.java

@ -1,11 +1,15 @@
package com.win.module.eam.service.licences;
import com.win.module.eam.controller.licences.vo.GenerateLicenceReqVO;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.io.IOException;
public interface LicencesService {
void licencesDiscern(String encryptionStr);
void licencesDiscernByCodeImage(@Valid @NotNull MultipartFile file) throws IOException;
void licenceDiscernByCodeStr(@Valid @NotNull String encryptionStr);
void generateLicence(@Valid GenerateLicenceReqVO req, HttpServletResponse response) throws Exception;
}

14
win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/service/licences/LicencesServiceImpl.java

@ -4,7 +4,6 @@ import cn.hutool.core.codec.Base64;
import cn.hutool.crypto.digest.MD5;
import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.extra.qrcode.QrConfig;
import com.alibaba.excel.metadata.data.ImageData;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.win.module.eam.controller.licences.vo.GenerateLicenceReqVO;
@ -12,6 +11,8 @@ import com.win.module.eam.mq.message.LicencesMessage;
import org.apache.calcite.util.Util;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.crypto.Cipher;
@ -19,6 +20,7 @@ import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
@ -27,6 +29,7 @@ import static com.win.framework.common.exception.util.ServiceExceptionUtil.excep
import static com.win.module.eam.enums.ErrorCodeConstants.ENCRYPTION_STR_FORMAT_IS_ERROR;
@Service
@Validated
public class LicencesServiceImpl implements LicencesService {
private static final String ALGORITHM = "AES";
private static final int KEY_SIZE = 128;
@ -58,7 +61,12 @@ public class LicencesServiceImpl implements LicencesService {
}
@Override
public void licencesDiscern(String encryptionStr) {
public void licencesDiscernByCodeImage(MultipartFile file) throws IOException {
licenceDiscernByCodeStr(QrCodeUtil.decode(file.getInputStream()));
}
@Override
public void licenceDiscernByCodeStr(String encryptionStr) {
if (Util.isNullOrEmpty(encryptionStr)) {
throw exception(ENCRYPTION_STR_FORMAT_IS_ERROR);
}
@ -103,6 +111,6 @@ public class LicencesServiceImpl implements LicencesService {
QrConfig config = new QrConfig(300, 300);
config.setErrorCorrection(com.google.zxing.qrcode.decoder.ErrorCorrectionLevel.M); // 设置纠错级别
// 或者直接输出到流
QrCodeUtil.generate(JSONObject.toJSONString(licencesMessage), config, ImageData.ImageType.PICTURE_TYPE_DIB.name(), response.getOutputStream());
QrCodeUtil.generate(JSONObject.toJSONString(licencesMessage), config, "png", response.getOutputStream());
}
}

Loading…
Cancel
Save