he2802 4 tahun lalu
induk
melakukan
10fa894f35

+ 2 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/alioss/service/OssService.java

@@ -16,4 +16,6 @@ public interface OssService {
     ResultBean callback(HttpServletRequest request);
 
     Boolean upload(OssRequest base) throws Exception;
+
+    String uploadBase64(String fileStr);
 }

+ 29 - 3
zhongzheng-system/src/main/java/com/zhongzheng/modules/alioss/service/impl/OssServiceImpl.java

@@ -7,6 +7,7 @@ import com.aliyun.oss.OSS;
 import com.aliyun.oss.OSSClient;
 import com.aliyun.oss.OSSClientBuilder;
 import com.aliyun.oss.common.utils.BinaryUtil;
+import com.aliyun.oss.internal.OSSUtils;
 import com.aliyun.oss.model.MatchMode;
 import com.aliyun.oss.model.PolicyConditions;
 import com.aliyun.oss.model.PutObjectRequest;
@@ -27,11 +28,14 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.util.Base64Utils;
 import org.springframework.web.multipart.MultipartFile;
+import sun.misc.BASE64Decoder;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.sql.rowset.serial.SerialBlob;
+import javax.sql.rowset.serial.SerialException;
 import java.awt.*;
 import java.io.*;
+import java.sql.SQLException;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Date;
@@ -111,8 +115,7 @@ public class OssServiceImpl implements OssService {
         int intDay = calCurrent.get(Calendar.DATE);
         int intMonth = calCurrent.get(Calendar.MONTH) + 1;
         int intYear = calCurrent.get(Calendar.YEAR);
-        String now = String.valueOf(intYear) + "_" + String.valueOf(intMonth) + "_" +
-                String.valueOf(intDay) + "_";
+        String now = String.valueOf(System.currentTimeMillis()) + "_";
 
         RandomFilename = now + String.valueOf(random > 0 ? random : (-1) * random);
         switch(ossRequest.getImageStatus()){
@@ -140,7 +143,6 @@ public class OssServiceImpl implements OssService {
         }
 
         return RandomFilename;
-
     }
 
     @Override
@@ -182,4 +184,28 @@ public class OssServiceImpl implements OssService {
         }
     }
 
+    @Override
+    public String uploadBase64(String fileStr) {
+        try{
+            BASE64Decoder decoder = new BASE64Decoder();
+            byte[] imageByte = decoder.decodeBuffer(fileStr);
+            SerialBlob serialBlob = new SerialBlob(imageByte);
+            InputStream binaryStream = serialBlob.getBinaryStream();
+            OssRequest ossRequest = new OssRequest();
+            ossRequest.setImageStatus(1);
+            String fileName = generateRandomFilename(ossRequest);
+            PutObjectResult putObjectResult = ossClient.putObject(ALIYUN_OSS_BUCKET_NAME, fileName, binaryStream);
+            ossClient.shutdown();
+            return fileName;
+        }catch (SerialException throwables) {
+            throwables.printStackTrace();
+        } catch (SQLException throwables) {
+            throwables.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+        return null;
+    }
+
 }

+ 5 - 2
zhongzheng-system/src/main/java/com/zhongzheng/modules/face/service/impl/FaceServiceImpl.java

@@ -11,9 +11,12 @@ import com.tencentcloudapi.faceid.v20180301.models.DetectAuthRequest;
 import com.tencentcloudapi.faceid.v20180301.models.DetectAuthResponse;
 import com.tencentcloudapi.faceid.v20180301.models.GetDetectInfoRequest;
 import com.tencentcloudapi.faceid.v20180301.models.GetDetectInfoResponse;
+import com.zhongzheng.modules.alioss.service.OssService;
+import com.zhongzheng.modules.course.mapper.CourseMapper;
 import com.zhongzheng.modules.exam.domain.ExamArrangementGuide;
 import com.zhongzheng.modules.face.bo.FaceVo;
 import com.zhongzheng.modules.face.service.IFaceService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
@@ -26,6 +29,8 @@ public class FaceServiceImpl implements IFaceService {
     @Value("${tencent.cloud.SecretKey}")
     private String SecretKey;
 
+    @Autowired
+    private OssService ossService;
 
     @Override
     public FaceVo getFaceDetectAuth() {
@@ -44,7 +49,6 @@ public class FaceServiceImpl implements IFaceService {
             System.out.println(DetectAuthResponse.toJsonString(resp));
             FaceVo vo = BeanUtil.toBean(resp, com.zhongzheng.modules.face.bo.FaceVo.class);
             return vo;
-    //        return resp.getBizToken();
         } catch (TencentCloudSDKException e) {
             System.out.println(e.toString());
         }
@@ -68,7 +72,6 @@ public class FaceServiceImpl implements IFaceService {
             req.setBizToken(bizToken);
             req.setRuleId("0");
             GetDetectInfoResponse resp = client.GetDetectInfo(req);
-
             System.out.println(GetDetectInfoResponse.toJsonString(resp));
         } catch (TencentCloudSDKException e) {
             System.out.println(e.toString());