|
@@ -1,6 +1,9 @@
|
|
|
package com.skyversation.xjcy.controller;
|
|
package com.skyversation.xjcy.controller;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.extra.qrcode.BufferedImageLuminanceSource;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import com.google.zxing.*;
|
|
|
|
|
+import com.google.zxing.common.HybridBinarizer;
|
|
|
import com.skyversation.xjcy.bean.User;
|
|
import com.skyversation.xjcy.bean.User;
|
|
|
import com.skyversation.xjcy.dms.DMSColumn;
|
|
import com.skyversation.xjcy.dms.DMSColumn;
|
|
|
import com.skyversation.xjcy.dms.DMSService;
|
|
import com.skyversation.xjcy.dms.DMSService;
|
|
@@ -14,9 +17,13 @@ import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
-import java.util.Collections;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
|
+import javax.imageio.ImageIO;
|
|
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
|
|
+import java.io.File;
|
|
|
|
|
+import java.io.InputStream;
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
import static com.skyversation.xjcy.service.AuthService.RESPONSE_FIELD_USERNAME;
|
|
import static com.skyversation.xjcy.service.AuthService.RESPONSE_FIELD_USERNAME;
|
|
|
|
|
|
|
@@ -76,4 +83,26 @@ public class OtherController {
|
|
|
return MessageManage.successWithNoData("成功绑定到对应企业");
|
|
return MessageManage.successWithNoData("成功绑定到对应企业");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @RequestMapping(value ="/scanQR")
|
|
|
|
|
+ public String scanQR(
|
|
|
|
|
+ @RequestParam("file") MultipartFile file
|
|
|
|
|
+ ){
|
|
|
|
|
+ try {
|
|
|
|
|
+ InputStream inputStream = file.getInputStream();
|
|
|
|
|
+ BufferedImage image = ImageIO.read(inputStream);
|
|
|
|
|
+ LuminanceSource source = new BufferedImageLuminanceSource(image);
|
|
|
|
|
+ BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
|
|
|
|
|
+
|
|
|
|
|
+ // 正确配置解码提示
|
|
|
|
|
+ Map<DecodeHintType, Object> hints = new EnumMap<>(DecodeHintType.class);
|
|
|
|
|
+ hints.put(DecodeHintType.POSSIBLE_FORMATS, Collections.singletonList(BarcodeFormat.QR_CODE));
|
|
|
|
|
+ hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
|
|
|
|
|
+
|
|
|
|
|
+ Result result = new MultiFormatReader().decode(bitmap, hints);
|
|
|
|
|
+ return MessageManage.success("成功解析二维码", result.getText());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ return MessageManage.error(-1,"解析二维码失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|