Browse Source

Merge remote-tracking branch 'origin/master'

yumeng 5 years ago
parent
commit
5a3c67f177

+ 103 - 0
feishu-sdk/pom.xml

@@ -0,0 +1,103 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>cn.feishu.sdk</groupId>
+  <artifactId>feishu-sdk</artifactId>
+  <version>2.0.2</version>
+
+  <name>feishu-sdk</name>
+  <!-- FIXME change it to the project's website -->
+  <url>http://www.example.com</url>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <maven.compiler.source>1.7</maven.compiler.source>
+    <maven.compiler.target>1.7</maven.compiler.target>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+      <version>2.6</version>
+    </dependency>
+    <dependency>
+      <groupId>commons-lang</groupId>
+      <artifactId>commons-lang</artifactId>
+      <version>2.6</version>
+    </dependency>
+    <dependency>
+      <groupId>org.projectlombok</groupId>
+      <artifactId>lombok</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.alibaba</groupId>
+      <artifactId>fastjson</artifactId>
+      <version>1.2.56</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.httpcomponents</groupId>
+      <artifactId>httpclient</artifactId>
+      <version>4.5.9</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.httpcomponents</groupId>
+      <artifactId>httpcore</artifactId>
+      <version>4.4</version>
+    </dependency>
+    <dependency>
+      <groupId>cn.hutool</groupId>
+      <artifactId>hutool-all</artifactId>
+      <version>4.5.11</version>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
+      <plugins>
+        <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
+        <plugin>
+          <artifactId>maven-clean-plugin</artifactId>
+          <version>3.1.0</version>
+        </plugin>
+        <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
+        <plugin>
+          <artifactId>maven-resources-plugin</artifactId>
+          <version>3.0.2</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-compiler-plugin</artifactId>
+          <version>3.8.0</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-surefire-plugin</artifactId>
+          <version>2.22.1</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-jar-plugin</artifactId>
+          <version>3.0.2</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-install-plugin</artifactId>
+          <version>2.5.2</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-deploy-plugin</artifactId>
+          <version>2.8.2</version>
+        </plugin>
+        <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
+        <plugin>
+          <artifactId>maven-site-plugin</artifactId>
+          <version>3.7.1</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-project-info-reports-plugin</artifactId>
+          <version>3.0.0</version>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+</project>

+ 18 - 0
feishu-sdk/src/main/java/cn/feishu/sdk/Test.java

@@ -0,0 +1,18 @@
+package cn.feishu.sdk;
+
+import cn.feishu.sdk.provider.AuthProvider;
+
+import java.io.UnsupportedEncodingException;
+
+public class Test {
+    public static void main(String[] args){
+        AuthProvider authProvider = new AuthProvider();
+        try {
+//            authProvider.getAuthUrl("state");
+            authProvider.getAppAccessToken();
+            authProvider.getTenantAccessToken();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}

+ 18 - 0
feishu-sdk/src/main/java/cn/feishu/sdk/common/ApiConstant.java

@@ -0,0 +1,18 @@
+package cn.feishu.sdk.common;
+
+import cn.feishu.sdk.util.PropertiesUtils;
+
+public class ApiConstant {
+    public static final String FEISHU_API_URL = PropertiesUtils.getConfig("feishu_api_url");
+    public static final String FEISHU_APP_ID = PropertiesUtils.getConfig("feishu_app_id");
+    public static final String FEISHU_APP_SECRET = PropertiesUtils.getConfig("feishu_app_secret");
+    public static final String APP_ACCESS_TOKEN = "/auth/v3/app_access_token/internal/";
+    public static final String TENANT_ACCESS_TOKEN = "/auth/v3/tenant_access_token/internal/";
+    public static final String AUTH_INDEX = "/authen/v1/index";
+    public static final String AUTH_ACCESS_TOKEN = "/authen/v1/access_token";
+    public static final String REFRESH_AUTH_ACCESS_TOKEN = "/authen/v1/refresh_access_token";
+    public static final String USER_INFO = "/authen/v1/user_info";
+    public static final String MESSAGE_BATCH_SEND = "/message/v4/batch_send/";
+    public static final String MESSAGE_SEND = "/message/v4/send/";
+    public static final String NOTIFY_SEND = "/notify/v4/appnotify";
+}

+ 61 - 0
feishu-sdk/src/main/java/cn/feishu/sdk/provider/AuthProvider.java

@@ -0,0 +1,61 @@
+package cn.feishu.sdk.provider;
+
+import cn.feishu.sdk.common.ApiConstant;
+import cn.feishu.sdk.util.HttpUtil;
+import cn.feishu.sdk.util.PropertiesUtils;
+import com.alibaba.fastjson.JSONObject;
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URLEncoder;
+
+public class AuthProvider {
+    public String getAuthUrl(String state) throws UnsupportedEncodingException, MalformedURLException {
+        String redirectUri = PropertiesUtils.getConfig("callback_url");
+        return HttpUtil.feishuGetRequestString(ApiConstant.FEISHU_API_URL+ApiConstant.AUTH_INDEX+"?redirect_uri="+ URLEncoder.encode(redirectUri,"UTF-8")+"&app_id="+ApiConstant.FEISHU_APP_ID+"&state="+state);
+    }
+    public JSONObject getAccessToken(String code) throws Exception {
+        JSONObject params = new JSONObject();
+        params.put("app_access_token",getAppAccessToken());
+        params.put("grant_type","authorization_code");
+        params.put("code",code);
+        return HttpUtil.feishuPostRequest(ApiConstant.FEISHU_API_URL+ApiConstant.AUTH_ACCESS_TOKEN,params);
+    }
+
+    public JSONObject refreshAccessToken(String refreshToken) throws Exception{
+        JSONObject params = new JSONObject();
+        params.put("app_access_token",getAppAccessToken());
+        params.put("grant_type","refresh_token");
+        params.put("refresh_token",refreshToken);
+        return HttpUtil.feishuPostRequest(ApiConstant.FEISHU_API_URL+ApiConstant.REFRESH_AUTH_ACCESS_TOKEN,params);
+    }
+
+    public JSONObject getUserInfo(String accessToken){
+        JSONObject params = new JSONObject();
+        params.put("user_access_token",accessToken);
+        return HttpUtil.feishuGetRequest("Bearer user_access_token",ApiConstant.FEISHU_API_URL+ApiConstant.USER_INFO,params);
+    }
+
+    public String getAppAccessToken() throws Exception {
+        JSONObject params = new JSONObject();
+        params.put("app_id",ApiConstant.FEISHU_APP_ID);
+        params.put("app_secret",ApiConstant.FEISHU_APP_SECRET);
+        JSONObject resultNode = HttpUtil.feishuPostRequest(ApiConstant.FEISHU_API_URL+ApiConstant.APP_ACCESS_TOKEN,params);
+        if (resultNode.getIntValue("code")==0){
+            return resultNode.getString("app_access_token");
+        }else {
+            throw new Exception();
+        }
+    }
+
+    public String getTenantAccessToken() throws Exception {
+        JSONObject params = new JSONObject();
+        params.put("app_id",ApiConstant.FEISHU_APP_ID);
+        params.put("app_secret",ApiConstant.FEISHU_APP_SECRET);
+        JSONObject resultNode = HttpUtil.feishuPostRequest(ApiConstant.FEISHU_API_URL+ApiConstant.TENANT_ACCESS_TOKEN,params);
+        if (resultNode.getIntValue("code")==0){
+            return resultNode.getString("tenant_access_token");
+        }else {
+            throw new Exception();
+        }
+    }
+}

+ 25 - 0
feishu-sdk/src/main/java/cn/feishu/sdk/provider/MessageProvider.java

@@ -0,0 +1,25 @@
+package cn.feishu.sdk.provider;
+
+import cn.feishu.sdk.common.ApiConstant;
+import cn.feishu.sdk.util.HttpUtil;
+import com.alibaba.fastjson.JSONObject;
+
+import java.util.List;
+
+public class MessageProvider {
+    public JSONObject batchSend(List<String> departmentIds,List<String> openIds,List<String> userIds,String content) throws Exception {
+        AuthProvider authProvider = new AuthProvider();
+        String tenantAccessToken = authProvider.getTenantAccessToken();
+        JSONObject contentJson = new JSONObject();
+        contentJson.put("text",content);
+        JSONObject params = new JSONObject();
+        params.put("department_ids",departmentIds);
+        params.put("open_ids",openIds);
+        params.put("user_ids",userIds);
+        params.put("msg_type","text");
+        params.put("content",contentJson);
+        return HttpUtil.feishuPostRequest("Bearer"+tenantAccessToken, ApiConstant.FEISHU_API_URL+ApiConstant.MESSAGE_BATCH_SEND,params);
+    }
+
+
+}

+ 167 - 0
feishu-sdk/src/main/java/cn/feishu/sdk/util/HttpUtil.java

@@ -0,0 +1,167 @@
+package cn.feishu.sdk.util;
+
+import cn.hutool.extra.ssh.JschRuntimeException;
+import com.alibaba.fastjson.JSONObject;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URI;
+
+public class HttpUtil {
+
+    public static JSONObject feishuGetRequest(String url, JSONObject params){
+        return HttpUtil.feishuGetRequest(null,url,params);
+    }
+    public static JSONObject feishuPostRequest(String url,JSONObject params){
+        return HttpUtil.feishuPostRequest(null,url,params);
+    }
+
+    public static String feishuGetRequestString(String url) {
+        System.out.println(url);
+        // 构造请求
+        HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
+            @Override
+            public String getMethod() {
+                return "GET";
+            }
+        };
+        CloseableHttpResponse response = null;
+        CloseableHttpClient client = null;
+        try {
+            client = HttpClientBuilder.create().build();
+            httpEntity.setURI(URI.create(url));
+            RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(12000).setConnectTimeout(12000).build();
+            httpEntity.setConfig(requestConfig);
+            response = client.execute(httpEntity);
+            if (response != null && response.getStatusLine().getStatusCode() == 200) {
+                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
+                StringBuilder result = new StringBuilder();
+                String line = "";
+                while ((line = bufferedReader.readLine()) != null) {
+                    result.append(line);
+                }
+                bufferedReader.close();
+                System.out.println(result.toString());
+                return result.toString();
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (response != null) {
+                    response.close();
+                }
+                if (client != null) {
+                    client.close();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return null;
+    }
+
+    public static JSONObject feishuGetRequest(String accessToken, String url, JSONObject params) {
+        System.out.println(url);
+        // 构造请求
+        HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
+            @Override
+            public String getMethod() {
+                return "GET";
+            }
+        };
+        if(accessToken != null){
+            httpEntity.setHeader("Authorization", accessToken);
+        }
+        CloseableHttpResponse response = null;
+        CloseableHttpClient client = null;
+        try {
+            client = HttpClientBuilder.create().build();
+            httpEntity.setURI(URI.create(url));
+            if (params != null){
+                httpEntity.setEntity(new StringEntity(params.toJSONString(), ContentType.APPLICATION_JSON));
+            }
+            RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(12000).setConnectTimeout(12000).build();
+            httpEntity.setConfig(requestConfig);
+            response = client.execute(httpEntity);
+            if (response != null && response.getStatusLine().getStatusCode() == 200) {
+                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
+                StringBuilder result = new StringBuilder();
+                String line = "";
+                while ((line = bufferedReader.readLine()) != null) {
+                    result.append(line);
+                }
+                bufferedReader.close();
+                System.out.println(result.toString());
+                return JSONObject.parseObject(result.toString());
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (response != null) {
+                    response.close();
+                }
+                if (client != null) {
+                    client.close();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return null;
+    }
+
+
+
+    public static JSONObject feishuPostRequest(String accessToken, String url, JSONObject params) {
+        // 构造请求
+        HttpPost httpEntity = new HttpPost(url);
+        if(accessToken != null){
+            httpEntity.setHeader("Authorization", accessToken);
+        }
+        CloseableHttpResponse response = null;
+        CloseableHttpClient client = null;
+        try {
+            client = HttpClientBuilder.create().build();
+            httpEntity.setEntity(new StringEntity(params.toJSONString(), ContentType.APPLICATION_JSON));
+            RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(12000).setConnectTimeout(12000).build();
+            httpEntity.setConfig(requestConfig);
+            response = client.execute(httpEntity);
+            if (response != null && response.getStatusLine().getStatusCode() == 200) {
+                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
+                StringBuilder result = new StringBuilder();
+                String line = "";
+                while ((line = bufferedReader.readLine()) != null) {
+                    result.append(line);
+                }
+                bufferedReader.close();
+                System.out.println(result.toString());
+                return JSONObject.parseObject(result.toString());
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (response != null) {
+                    response.close();
+                }
+                if (client != null) {
+                    client.close();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return null;
+    }
+}

+ 62 - 0
feishu-sdk/src/main/java/cn/feishu/sdk/util/PropertiesUtils.java

@@ -0,0 +1,62 @@
+package cn.feishu.sdk.util;
+
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * @author jeecg-boot
+ * 2019年11月12日10:04:00
+ */
+public class PropertiesUtils {
+    private static Map<String, String> cache = new HashMap<String, String>();
+
+    public static String getConfig(String key) {
+        return getValue("config", key);
+    }
+
+    public static String getValue(String name, String key) {
+        try {
+            String cacheValue = (String) cache.get(name + key);
+            if (cacheValue != null) {
+                return cacheValue;
+            }
+            Properties props = new Properties();
+            InputStream in = PropertiesUtils.class.getResourceAsStream("/"
+                    + name + ".properties");
+            props.load(in);
+            String value = props.getProperty(key);
+            cache.put(name + key, value);
+            props.clone();
+            in.close();
+            return value;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    public static Map<String, String> getMap(String name) {
+        try {
+            Properties props = new Properties();
+            InputStream in = PropertiesUtils.class.getResourceAsStream("/"
+                    + name + ".properties");
+            props.load(in);
+            Iterator<Object> it = props.keySet().iterator();
+            Map<String, String> map = new HashMap<String, String>();
+            while (it.hasNext()) {
+                String key = it.next().toString();
+                String value = props.getProperty(key);
+                map.put(key, value);
+            }
+            props.clone();
+            in.close();
+            return map;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+}

+ 4 - 0
feishu-sdk/src/main/resources/config.properties

@@ -0,0 +1,4 @@
+feishu_api_url=https://open.feishu.cn/open-apis
+feishu_app_id=cli_9e68af69ca34d00e
+feishu_app_secret=0RsCBRCLx1rG8HKfeZNeAbddxZ3Rsnwv
+callback_url=https://callback.tjyourong.com.cn/jeecg-boot/feishu/auth

+ 7 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/CallbackController.java

@@ -62,7 +62,13 @@ public class CallbackController {
     @Autowired
     private IReportService reportService;
 
-
+    @GetMapping("/feishu/auth")
+    public void feishuAuth(HttpServletRequest request,
+                        HttpServletResponse response,
+                        @RequestParam("code") String code,
+                        @RequestParam("state") String state) throws IOException {
+        System.out.println(request.getQueryString());
+    }
     @GetMapping("/qywexin")
     public void qywexin(HttpServletRequest request,
                         HttpServletResponse response,

+ 1 - 6
module-common/src/main/java/cn/com/ctop/common/module/service/impl/MaterialInfoServiceImpl.java

@@ -66,7 +66,7 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
         VideoWatermarkTemplate videoWatermarkTemplate = videoWatermarkTemplateService.getById(videoWatermarkTemplateId);
         MaterialInfo materialInfo = this.getById(materialId);
         MpsUtils mpsUtils = new MpsUtils();
-        String path = materialInfo.getUrl().substring(materialInfo.getUrl().indexOf("/", 10) + 1, materialInfo.getUrl().length());
+        String path = materialInfo.getUrl().substring(materialInfo.getUrl().indexOf('/', 10) + 1, materialInfo.getUrl().length());
         String jobId = mpsUtils.videoWaterMark(path, videoWatermarkTemplate.getTemplatePath(), videoWatermarkTemplate.getTemplateId(), videoWatermarkTemplate.getHeight());
         QueryJobListResponse.Job job = MpsUtils.getJobStatus(jobId);
         VideoWatermarkTask videoWatermarkTask = new VideoWatermarkTask();
@@ -118,11 +118,6 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
         return p.matcher(fileName).find();
     }
 
-    public static void main(String[] args) {
-        String reg = "(mp4|flv|avi|rm|rmvb|wmv)";
-        Pattern p = Pattern.compile(reg);
-    }
-
     @Autowired
     private MaterialAscriptionMapper materialAscriptionMapper;
     @Autowired

+ 1 - 3
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java

@@ -127,12 +127,10 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
     private IUserAllocationService userAllocationService;
     @Autowired
     private IKuaishouReportDailyCreativeStatisticService dailyCreativeStatisticService;
-
     @Autowired
     private IKuaiShouHistoryReportTaskService historyReportTaskService;
-
     @Autowired
-    IKuaiShouImageGetService kuaiShouImageGetService;
+    private IKuaiShouImageGetService kuaiShouImageGetService;
     @Autowired
     private IKuaiShouDailyFlowsService kuaiShouDailyFlowsService;
     @Autowired

+ 0 - 2
performance-appraisal/src/main/java/cn/com/ctop/uservideomap/controller/UserVideoMapController.java

@@ -16,8 +16,6 @@ import org.jeecg.common.util.oConvertUtils;
 import cn.com.ctop.uservideomap.entity.UserVideoMap;
 import cn.com.ctop.uservideomap.service.IUserVideoMapService;
 
-import java.util.Date;
-
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

+ 1 - 0
pom.xml

@@ -26,6 +26,7 @@
         <module>jeecg-boot-module-system</module>
         <module>module-job-bytedance</module>
         <module>module-job-kuaishou</module>
+        <module>feishu-sdk</module>
 
     </modules>