From 7c7c20fb9df0b440e6c4ee1b2e8d655ebaf9192d Mon Sep 17 00:00:00 2001
From: CeDo <cedoogle@gmail.com>
Date: 星期一, 26 四月 2021 18:13:01 +0800
Subject: [PATCH] bugfixed: 78648

---
 springcloud_k8s_panzhihuazhihuishequ/applets/src/main/java/com/panzhihua/applets/api/CommonApi.java |   70 +++++++++++++++++++++++++++++++---
 1 files changed, 63 insertions(+), 7 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/applets/src/main/java/com/panzhihua/applets/api/CommonApi.java b/springcloud_k8s_panzhihuazhihuishequ/applets/src/main/java/com/panzhihua/applets/api/CommonApi.java
index 1300435..e1cb5bb 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/applets/src/main/java/com/panzhihua/applets/api/CommonApi.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/applets/src/main/java/com/panzhihua/applets/api/CommonApi.java
@@ -1,14 +1,22 @@
 package com.panzhihua.applets.api;
 
+import cn.binarywang.wx.miniapp.api.WxMaSecCheckService;
+import com.netflix.discovery.converters.Auto;
+import com.panzhihua.applets.config.WxMaConfiguration;
 import com.panzhihua.common.constants.FtpConstants;
 import com.panzhihua.common.constants.UserConstants;
 import com.panzhihua.common.model.vos.R;
+import com.panzhihua.common.model.vos.area.AreaInfoVo;
 import com.panzhihua.common.model.vos.user.UserPhoneVO;
+import com.panzhihua.common.service.community.CommunityService;
+import com.panzhihua.common.service.user.UserService;
 import com.panzhihua.common.utlis.SFTPUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
+import me.chanjar.weixin.common.error.WxErrorException;
 import org.apache.commons.lang3.RandomUtils;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.data.redis.core.ValueOperations;
 import org.springframework.util.ObjectUtils;
@@ -17,7 +25,12 @@
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
+import java.io.File;
+import java.io.IOException;
 import java.io.InputStream;
+import java.util.Base64;
+import java.util.List;
+import java.util.UUID;
 import java.util.concurrent.TimeUnit;
 
 /**
@@ -33,18 +46,56 @@
 public class CommonApi {
     @Resource
     private StringRedisTemplate stringRedisTemplate;
+    // FTP 登录用户名
+    @Value("${ftp.username}")
+    private String userName;
+    // FTP 登录密码
+    @Value("${ftp.password}")
+    private String password;
+    // FTP 服务器地址IP地址
+    @Value("${ftp.host}")
+    private String host;
+    // FTP 端口
+    @Value("${ftp.port}")
+    private int port;
+    @Value("${ftp.url}")
+    private String url;
+
+    @Resource
+    private WxMaConfiguration wxMaConfiguration;
+    @Resource
+    private CommunityService communityService;
 
     @ApiOperation(value = "上传照片")
-    @PostMapping(value = "uploadimage",consumes = "multipart/*",headers = "content-type=multipart/form-date")
-    public R uploadImage(@RequestParam MultipartFile file, HttpServletRequest request) {
+    @PostMapping(value = "uploadimage", consumes = "multipart/*", headers = "content-type=multipart/form-date")
+    public R uploadImage(@RequestParam MultipartFile file, HttpServletRequest request) throws IOException {
+//        微信图片内容校验
+        WxMaSecCheckService wxMaSecCheckService = wxMaConfiguration.getMaService().getSecCheckService();
+        String property = System.getProperty("user.dir");
+        String fileName = property + File.separator + UUID.randomUUID().toString().replace("-", "") + ".jpg";
+        File file1 = new File(fileName);
+
         String name = file.getOriginalFilename();
+        name = UUID.randomUUID().toString().replaceAll("-", "") + ".jpg";
         try {
-            SFTPUtil sftp = new SFTPUtil();
+            SFTPUtil sftp = new SFTPUtil(userName, password, host, port);
             sftp.login();
             InputStream is = file.getInputStream();
+            file.transferTo(file1);
+            try {
+                boolean b = wxMaSecCheckService.checkImage(file1);
+                boolean delete = file1.delete();
+                log.info("临时文件删除【{}】", delete);
+                if (!b) {
+                    return R.fail("图片内容违规");
+                }
+            } catch (WxErrorException e) {
+                log.error("微信审核图片出错【{}】", e.getMessage());
+                e.printStackTrace();
+            }
             sftp.uploadMore(FtpConstants.FTPFILEPATH_IDCARD, name, is);
             sftp.logout();
-            return R.ok(FtpConstants.HTTP_URL+"/idcard/" + name);
+            return R.ok(url + "/idcard/" + name);
         } catch (Exception e) {
             log.error("上传照片失败【{}】", e.getMessage());
             return R.fail();
@@ -62,12 +113,17 @@
         //todo 发送验证码接第三方
         int nextInt = RandomUtils.nextInt(99999, 1000000);
         ValueOperations<String, String> valueOperations = stringRedisTemplate.opsForValue();
-        valueOperations.set(UserConstants.PHONE_PUT+newPhone,nextInt+"",3, TimeUnit.MINUTES);
+        valueOperations.set(UserConstants.PHONE_PUT + newPhone, nextInt + "", 3, TimeUnit.MINUTES);
         return R.ok(nextInt);
     }
 
+
     public static void main(String[] args) {
-        int nextInt = RandomUtils.nextInt(99999, 1000000);
-        System.out.println(nextInt);
+//        int nextInt = RandomUtils.nextInt(99999, 1000000);
+//        System.out.println(nextInt);
+        String basicStr = "2092261934651932672" + ":" + "de1c0dbb-9197-4724-9cc2-aa94e30a072f" + ":" + System.currentTimeMillis();
+        String s = Base64.getEncoder().encodeToString(basicStr.getBytes());
+        System.out.println(s);
+
     }
 }

--
Gitblit v1.7.1