|
|
@ -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()); |
|
|
|
} |
|
|
|
} |
|
|
|