正在显示
2 个修改的文件
包含
71 行增加
和
46 行删除
| @@ -8,6 +8,7 @@ import com.ruoyi.common.core.domain.AjaxResult; | @@ -8,6 +8,7 @@ import com.ruoyi.common.core.domain.AjaxResult; | ||
| 8 | import com.ruoyi.common.utils.DateUtils; | 8 | import com.ruoyi.common.utils.DateUtils; |
| 9 | import com.ruoyi.common.utils.GsonConstructor; | 9 | import com.ruoyi.common.utils.GsonConstructor; |
| 10 | import com.zhonglai.luhui.api.controller.test.dto.ClueData; | 10 | import com.zhonglai.luhui.api.controller.test.dto.ClueData; |
| 11 | +import com.zhonglai.luhui.api.controller.test.dto.TenantAccessToken; | ||
| 11 | import com.zhonglai.luhui.config.requestbodymiss.RequestReaderHttpServletRequestWrapper; | 12 | import com.zhonglai.luhui.config.requestbodymiss.RequestReaderHttpServletRequestWrapper; |
| 12 | import io.swagger.annotations.Api; | 13 | import io.swagger.annotations.Api; |
| 13 | import io.swagger.annotations.ApiOperation; | 14 | import io.swagger.annotations.ApiOperation; |
| @@ -75,68 +76,42 @@ public class TestController { | @@ -75,68 +76,42 @@ public class TestController { | ||
| 75 | @RequestMapping(value = "douyin") | 76 | @RequestMapping(value = "douyin") |
| 76 | public String douyin(@RequestBody String jsr) throws IOException { | 77 | public String douyin(@RequestBody String jsr) throws IOException { |
| 77 | ClueData clueData = GsonConstructor.get().fromJson(jsr, ClueData.class); | 78 | ClueData clueData = GsonConstructor.get().fromJson(jsr, ClueData.class); |
| 78 | - | ||
| 79 | - String tenant_access_token = gettenant_access_token(); | ||
| 80 | - JsonObject field = new JsonObject(); | ||
| 81 | - field.addProperty("日期",DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",new Date(Integer.parseInt(clueData.getCreate_time())*1000l))); | ||
| 82 | - field.addProperty("发送人",""); | ||
| 83 | - field.addProperty("接收人",clueData.getRefer_dy_name()); | ||
| 84 | - field.addProperty("内容",clueData.getTelephone()); | ||
| 85 | - field.addProperty("线索来源","抖音"); | ||
| 86 | - field.addProperty("地址",clueData.getLocation()); | ||
| 87 | - subFeishuTables(tenant_access_token,"YY58bkeMjahX5Uskh4WcnYOCnZc","tbldo1VjlU9jY51Y",field); | ||
| 88 | - | ||
| 89 | -// switch (clueData.getActionType()) | ||
| 90 | -// { | ||
| 91 | -// case 0: // 0: 其他 | ||
| 92 | -// break; | ||
| 93 | -// case 1: // 1: 短视频 | ||
| 94 | -// break; | ||
| 95 | -// case 2: // 2: 直播 | ||
| 96 | -// break; | ||
| 97 | -// case 3: // 3: 企业主页 | ||
| 98 | -// break; | ||
| 99 | -// case 4: // 4: 私信 | ||
| 100 | -// break; | ||
| 101 | -// case 5: // 5: 订阅文章 | ||
| 102 | -// break; | ||
| 103 | -// case 6: // 6: 群聊 | ||
| 104 | -// break; | ||
| 105 | -// case 7: // 7: 独立店铺 | ||
| 106 | -// break; | ||
| 107 | -// case 8: // 8: 搜索服务卡 | ||
| 108 | -// break; | ||
| 109 | -// } | ||
| 110 | - | 79 | + subData(clueData); |
| 111 | return "{\n" + | 80 | return "{\n" + |
| 112 | " \"code\": \"1\",\n" + | 81 | " \"code\": \"1\",\n" + |
| 113 | " \"message\": \"success\"\n" + | 82 | " \"message\": \"success\"\n" + |
| 114 | "}"; | 83 | "}"; |
| 115 | } | 84 | } |
| 116 | 85 | ||
| 117 | - private static String tenant_access_token; | ||
| 118 | - private static long tokenExpireTime = 0; // 添加token过期时间字段 | ||
| 119 | 86 | ||
| 120 | - private String gettenant_access_token() { | ||
| 121 | - // 判断token是否未超时 | ||
| 122 | - if (tenant_access_token != null && System.currentTimeMillis() < tokenExpireTime) { | ||
| 123 | - return tenant_access_token; | 87 | + private static Map<String, TenantAccessToken> tenant_access_token_map = new HashMap<>(); |
| 88 | + | ||
| 89 | + private static String gettenant_access_token(String yy_app_id,String yy_app_secret) { | ||
| 90 | + if(tenant_access_token_map.containsKey(yy_app_id)) | ||
| 91 | + { | ||
| 92 | + TenantAccessToken tenant_access_token = tenant_access_token_map.get(yy_app_id); | ||
| 93 | + // 判断token是否未超时 | ||
| 94 | + if (tenant_access_token.getTenant_access_token() != null && System.currentTimeMillis() < tenant_access_token.getTokenExpireTime()) { | ||
| 95 | + return tenant_access_token.getTenant_access_token(); | ||
| 96 | + } | ||
| 124 | } | 97 | } |
| 125 | 98 | ||
| 126 | String url = "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal"; | 99 | String url = "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal"; |
| 127 | JsonObject params = new JsonObject(); | 100 | JsonObject params = new JsonObject(); |
| 128 | - params.addProperty("app_id", "cli_a77e560b9475100c"); // 替换为实际的 app_id | ||
| 129 | - params.addProperty("app_secret", "7E80HFwgkmHjngFWDNsz6Pe1aqtKLC3m"); // 替换为实际的 app_secret | 101 | + params.addProperty("app_id", yy_app_id); // 替换为实际的 app_id |
| 102 | + params.addProperty("app_secret", yy_app_secret); // 替换为实际的 app_secret | ||
| 130 | 103 | ||
| 131 | String str = HttpRequest.post(url).header("Content-Type", "application/json; charset=utf-8").body(params.toString()).execute().body(); | 104 | String str = HttpRequest.post(url).header("Content-Type", "application/json; charset=utf-8").body(params.toString()).execute().body(); |
| 132 | 105 | ||
| 133 | JsonObject responseMap = GsonConstructor.get().fromJson(str, JsonObject.class); | 106 | JsonObject responseMap = GsonConstructor.get().fromJson(str, JsonObject.class); |
| 134 | 107 | ||
| 135 | if (responseMap != null && responseMap.get("code").getAsInt()==0) { | 108 | if (responseMap != null && responseMap.get("code").getAsInt()==0) { |
| 136 | - tenant_access_token = responseMap.get("tenant_access_token").getAsString(); | 109 | + TenantAccessToken tenant_access_token = new TenantAccessToken(); |
| 110 | + tenant_access_token.setTenant_access_token(responseMap.get("tenant_access_token").getAsString()); | ||
| 137 | // 设置token过期时间,假设token有效期为7200秒 | 111 | // 设置token过期时间,假设token有效期为7200秒 |
| 138 | - tokenExpireTime = System.currentTimeMillis() + responseMap.get("expire").getAsInt() * 1000; | ||
| 139 | - return tenant_access_token; | 112 | + tenant_access_token.setTokenExpireTime(System.currentTimeMillis() + responseMap.get("expire").getAsInt() * 1000); |
| 113 | + tenant_access_token_map.put(yy_app_id, tenant_access_token); | ||
| 114 | + return tenant_access_token.getTenant_access_token(); | ||
| 140 | } else { | 115 | } else { |
| 141 | throw new RuntimeException("Failed to get tenant_access_token: " + str); | 116 | throw new RuntimeException("Failed to get tenant_access_token: " + str); |
| 142 | } | 117 | } |
| @@ -152,7 +127,7 @@ public class TestController { | @@ -152,7 +127,7 @@ public class TestController { | ||
| 152 | * | 127 | * |
| 153 | * 请求头 :Authorization、Content-Type | 128 | * 请求头 :Authorization、Content-Type |
| 154 | */ | 129 | */ |
| 155 | - private void subFeishuTables(String tenant_access_token,String app_token,String table_id, JsonObject field ) | 130 | + private static void subFeishuTables(String tenant_access_token,String app_token,String table_id, JsonObject field ) |
| 156 | { | 131 | { |
| 157 | String url = "https://open.feishu.cn/open-apis/bitable/v1/apps/"+app_token+"/tables/"+table_id+"/records"; | 132 | String url = "https://open.feishu.cn/open-apis/bitable/v1/apps/"+app_token+"/tables/"+table_id+"/records"; |
| 158 | 133 | ||
| @@ -165,8 +140,36 @@ public class TestController { | @@ -165,8 +140,36 @@ public class TestController { | ||
| 165 | } | 140 | } |
| 166 | 141 | ||
| 167 | public static void main(String[] args) { | 142 | public static void main(String[] args) { |
| 168 | - String jsr= "{\"store_id\":0,\"create_time\":\"1745031148\",\"gender\":\"未知\",\"action_type\":4,\"telephone\":\"13063963982\",\"promotion_id\":0,\"clue_source\":5,\"store_pack_id\":0,\"refer_dy_id\":\"2046931013\",\"app_name\":\"暂未获取到\",\"ad_id\":\"0\",\"module_id\":\"0\",\"flow_type\":1,\"name\":\"未命名\",\"site_id\":\"0\",\"remark_dict\":{},\"adv_id\":\"0\",\"clue_type\":1,\"location\":\"江苏+常州\",\"id\":\"7494853024813154342\",\"clue_convert_status\":\"外部流量\",\"refer_dy_name\":\"鱼儿乐智慧渔业系统\"}"; | 143 | + String jsr= "{\"store_id\":0,\"create_time\":\"1746668144\",\"gender\":\"未知\",\"action_type\":3,\"telephone\":\"18061271693\",\"promotion_id\":0,\"clue_source\":5,\"store_pack_id\":0,\"refer_dy_id\":\"2046931013\",\"app_name\":\"暂未获取到\",\"ad_id\":\"0\",\"module_id\":\"1805421364269097\",\"flow_type\":1,\"name\":\"未命名\",\"site_id\":\"0\",\"remark_dict\":{},\"adv_id\":\"0\",\"clue_type\":2,\"location\":\"山东+泰安\",\"id\":\"7501883876034215974\",\"module_name\":\"官方电话\",\"clue_convert_status\":\"外部流量\",\"refer_dy_name\":\"鱼儿乐>智慧渔业系统\"}"; |
| 169 | ClueData clueData = GsonConstructor.get().fromJson(jsr, ClueData.class); | 144 | ClueData clueData = GsonConstructor.get().fromJson(jsr, ClueData.class); |
| 170 | System.out.println(clueData); | 145 | System.out.println(clueData); |
| 146 | + subData(clueData); | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + private static void subData(ClueData clueData) | ||
| 150 | + { | ||
| 151 | + subFeishuLiushuiyu(clueData); | ||
| 152 | + subFeishuLuhui(clueData); | ||
| 153 | + } | ||
| 154 | + | ||
| 155 | + private static void subFeishuLiushuiyu(ClueData clueData) | ||
| 156 | + { | ||
| 157 | + JsonObject field = new JsonObject(); | ||
| 158 | + field.addProperty("账号",clueData.getRefer_dy_name()); | ||
| 159 | + field.addProperty("联系方式",clueData.getTelephone()); | ||
| 160 | + field.addProperty("渠道","抖音"); | ||
| 161 | + field.addProperty("地址",clueData.getLocation()); | ||
| 162 | + subFeishuTables(gettenant_access_token("cli_a88a14d3b279d01c","Z3hpYKHeR1yR2aiv6Rp0mcnwKvehkzmT"),"VLGDbZTtPaJIrgsAzzJcyb8Vnve","tblgzxv9TNwKjUFv",field); | ||
| 163 | + } | ||
| 164 | + private static void subFeishuLuhui(ClueData clueData) | ||
| 165 | + { | ||
| 166 | + JsonObject field = new JsonObject(); | ||
| 167 | + field.addProperty("日期",Integer.parseInt(clueData.getCreate_time())*1000l); | ||
| 168 | + field.addProperty("发送人",""); | ||
| 169 | + field.addProperty("接收人",clueData.getRefer_dy_name()); | ||
| 170 | + field.addProperty("内容",clueData.getTelephone()); | ||
| 171 | + field.addProperty("线索来源","抖音"); | ||
| 172 | + field.addProperty("地址",clueData.getLocation()); | ||
| 173 | + subFeishuTables(gettenant_access_token("cli_a77e560b9475100c","7E80HFwgkmHjngFWDNsz6Pe1aqtKLC3m"),"YY58bkeMjahX5Uskh4WcnYOCnZc","tbldo1VjlU9jY51Y",field); | ||
| 171 | } | 174 | } |
| 172 | } | 175 | } |
lh-modules/lh-api/src/main/java/com/zhonglai/luhui/api/controller/test/dto/TenantAccessToken.java
0 → 100644
| 1 | +package com.zhonglai.luhui.api.controller.test.dto; | ||
| 2 | + | ||
| 3 | +public class TenantAccessToken { | ||
| 4 | + private String tenant_access_token; | ||
| 5 | + private long tokenExpireTime; | ||
| 6 | + | ||
| 7 | + public String getTenant_access_token() { | ||
| 8 | + return tenant_access_token; | ||
| 9 | + } | ||
| 10 | + | ||
| 11 | + public void setTenant_access_token(String tenant_access_token) { | ||
| 12 | + this.tenant_access_token = tenant_access_token; | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + public long getTokenExpireTime() { | ||
| 16 | + return tokenExpireTime; | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + public void setTokenExpireTime(long tokenExpireTime) { | ||
| 20 | + this.tokenExpireTime = tokenExpireTime; | ||
| 21 | + } | ||
| 22 | +} |
-
请 注册 或 登录 后发表评论