作者 钟来

添加抖音私信

1 package com.zhonglai.luhui.api.controller.test; 1 package com.zhonglai.luhui.api.controller.test;
2 2
  3 +import cn.hutool.http.HttpRequest;
  4 +import cn.hutool.http.HttpUtil;
  5 +import com.google.gson.JsonArray;
  6 +import com.google.gson.JsonObject;
3 import com.ruoyi.common.core.domain.AjaxResult; 7 import com.ruoyi.common.core.domain.AjaxResult;
  8 +import com.ruoyi.common.utils.GsonConstructor;
  9 +import com.zhonglai.luhui.api.controller.test.dto.ClueData;
  10 +import com.zhonglai.luhui.config.requestbodymiss.RequestReaderHttpServletRequestWrapper;
4 import io.swagger.annotations.Api; 11 import io.swagger.annotations.Api;
5 import io.swagger.annotations.ApiOperation; 12 import io.swagger.annotations.ApiOperation;
  13 +import org.springframework.util.StreamUtils;
6 import org.springframework.web.bind.annotation.GetMapping; 14 import org.springframework.web.bind.annotation.GetMapping;
  15 +import org.springframework.web.bind.annotation.RequestBody;
7 import org.springframework.web.bind.annotation.RequestMapping; 16 import org.springframework.web.bind.annotation.RequestMapping;
8 import org.springframework.web.bind.annotation.RestController; 17 import org.springframework.web.bind.annotation.RestController;
9 18
  19 +import javax.servlet.http.HttpServletRequest;
  20 +import java.io.IOException;
  21 +import java.util.Enumeration;
  22 +import java.util.HashMap;
  23 +import java.util.Map;
  24 +
10 @Api(tags = "测试") 25 @Api(tags = "测试")
11 @RestController 26 @RestController
12 @RequestMapping("/test") 27 @RequestMapping("/test")
@@ -17,4 +32,139 @@ public class TestController { @@ -17,4 +32,139 @@ public class TestController {
17 { 32 {
18 return AjaxResult.success(new TestDto()); 33 return AjaxResult.success(new TestDto());
19 } 34 }
  35 +
  36 + @ApiOperation("默认主页")
  37 + @RequestMapping(value = "")
  38 + public String index(HttpServletRequest httpServletRequest) throws IOException {
  39 + StringBuffer bodyBytes = new StringBuffer("<html>");
  40 + bodyBytes.append("<head><meta charset=\"UTF-8\"></head>");
  41 + bodyBytes.append("<body>");
  42 + Map<String, String[]> map = httpServletRequest.getParameterMap();
  43 + bodyBytes.append("<b>parameter:</b></br>");
  44 + for (Map.Entry<String, String[]> entry : map.entrySet()) {
  45 + String key = entry.getKey();
  46 + String[] values = entry.getValue();
  47 + if (values.length == 1) {
  48 + bodyBytes.append(key).append(":").append(values[0]).append("</br>");
  49 + } else {
  50 + bodyBytes.append(key).append(":").append(values).append("</br>");
  51 + }
  52 + }
  53 +
  54 + // 打印请求头信息
  55 + bodyBytes.append("<b>header:</b></br>");
  56 + Enumeration<String> headerNames = httpServletRequest.getHeaderNames();
  57 + while (headerNames.hasMoreElements()) {
  58 + String headerName = headerNames.nextElement();
  59 + String headerValue = httpServletRequest.getHeader(headerName);
  60 + bodyBytes.append(headerName).append(":").append(headerValue).append("</br>");
  61 + }
  62 + //获取请求body
  63 + byte[] rbody = StreamUtils.copyToByteArray(httpServletRequest.getInputStream());
  64 + String body = new String(rbody, httpServletRequest.getCharacterEncoding());
  65 + bodyBytes.append("<b>body:</b></br>");
  66 + bodyBytes.append(body);
  67 + bodyBytes.append("</body>");
  68 + bodyBytes.append("</html>");
  69 + return bodyBytes.toString();
  70 + }
  71 +
  72 + @ApiOperation("抖音")
  73 + @RequestMapping(value = "douyin")
  74 + public String douyin(@RequestBody String jsr) throws IOException {
  75 + ClueData clueData = GsonConstructor.get().fromJson(jsr, ClueData.class);
  76 +
  77 + String tenant_access_token = gettenant_access_token();
  78 + JsonObject field = new JsonObject();
  79 + field.addProperty("日期",Integer.parseInt(clueData.getCreate_time()));
  80 + field.addProperty("发送人","");
  81 + field.addProperty("接收人",clueData.getRefer_dy_name());
  82 + field.addProperty("内容",clueData.getTelephone());
  83 + field.addProperty("线索来源","抖音");
  84 + field.addProperty("地址",clueData.getLocation());
  85 + subFeishuTables(tenant_access_token,"YY58bkeMjahX5Uskh4WcnYOCnZc","tbldo1VjlU9jY51Y",field);
  86 +
  87 +// switch (clueData.getActionType())
  88 +// {
  89 +// case 0: // 0: 其他
  90 +// break;
  91 +// case 1: // 1: 短视频
  92 +// break;
  93 +// case 2: // 2: 直播
  94 +// break;
  95 +// case 3: // 3: 企业主页
  96 +// break;
  97 +// case 4: // 4: 私信
  98 +// break;
  99 +// case 5: // 5: 订阅文章
  100 +// break;
  101 +// case 6: // 6: 群聊
  102 +// break;
  103 +// case 7: // 7: 独立店铺
  104 +// break;
  105 +// case 8: // 8: 搜索服务卡
  106 +// break;
  107 +// }
  108 +
  109 + return "{\n" +
  110 + " \"code\": \"1\",\n" +
  111 + " \"message\": \"success\"\n" +
  112 + "}";
  113 + }
  114 +
  115 + private static String tenant_access_token;
  116 + private static long tokenExpireTime = 0; // 添加token过期时间字段
  117 +
  118 + private String gettenant_access_token() {
  119 + // 判断token是否未超时
  120 + if (tenant_access_token != null && System.currentTimeMillis() < tokenExpireTime) {
  121 + return tenant_access_token;
  122 + }
  123 +
  124 + String url = "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal";
  125 + JsonObject params = new JsonObject();
  126 + params.addProperty("app_id", "cli_a77e560b9475100c"); // 替换为实际的 app_id
  127 + params.addProperty("app_secret", "7E80HFwgkmHjngFWDNsz6Pe1aqtKLC3m"); // 替换为实际的 app_secret
  128 +
  129 + String str = HttpRequest.post(url).header("Content-Type", "application/json; charset=utf-8").body(params.toString()).execute().body();
  130 +
  131 + JsonObject responseMap = GsonConstructor.get().fromJson(str, JsonObject.class);
  132 +
  133 + if (responseMap != null && responseMap.get("code").getAsInt()==0) {
  134 + tenant_access_token = responseMap.get("tenant_access_token").getAsString();
  135 + // 设置token过期时间,假设token有效期为7200秒
  136 + tokenExpireTime = System.currentTimeMillis() + responseMap.get("expire").getAsInt() * 1000;
  137 + return tenant_access_token;
  138 + } else {
  139 + throw new RuntimeException("Failed to get tenant_access_token: " + str);
  140 + }
  141 + }
  142 +
  143 + /**
  144 + * HTTP URL
  145 + * https://open.feishu.cn/open-apis/bitable/v1/apps/:app_token/tables/:table_id/records
  146 + * HTTP Method
  147 + * POST
  148 + * 接口频率限制
  149 + * 50 次/秒
  150 + *
  151 + * 请求头 :Authorization、Content-Type
  152 + */
  153 + private void subFeishuTables(String tenant_access_token,String app_token,String table_id, JsonObject field )
  154 + {
  155 + String url = "https://open.feishu.cn/open-apis/bitable/v1/apps/"+app_token+"/tables/"+table_id+"/records";
  156 +
  157 + JsonObject params = new JsonObject();
  158 + params.add("fields",field);
  159 +
  160 + System.out.println(params.toString());
  161 + String str = HttpRequest.post(url).header("Authorization", "Bearer "+tenant_access_token ).header("Content-Type", "application/json").body(params.toString()).execute().body();
  162 + System.out.println(str);
  163 + }
  164 +
  165 + public static void main(String[] args) {
  166 + 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\":\"鱼儿乐智慧渔业系统\"}";
  167 + ClueData clueData = GsonConstructor.get().fromJson(jsr, ClueData.class);
  168 + System.out.println(clueData);
  169 + }
20 } 170 }
  1 +package com.zhonglai.luhui.api.controller.test.dto;
  2 +
  3 +import java.util.Date;
  4 +import java.util.Map;
  5 +
  6 +// 线索数据类,用于存储和管理与线索相关的各种信息
  7 +public class ClueData {
  8 + // 日期
  9 + private String date;
  10 + // 门店活动id
  11 + private String store_pack_id;
  12 + // 请求id
  13 + private String req_id;
  14 + // 落地页链接
  15 + private String external_url;
  16 + // 门店活动备注
  17 + private String store_pack_remark;
  18 + // 广告主id
  19 + private String adv_id;
  20 + // 素材组
  21 + private String mid_info;
  22 + // 线索id
  23 + private String id;
  24 + // 广告主名称
  25 + private String adv_name;
  26 + // QQ号
  27 + private String qq;
  28 + // 线索创建时间
  29 + private String create_time;
  30 + // 手动填写地域 - 省
  31 + private String province_name;
  32 + // 站点名称
  33 + private String site_name;
  34 + // 计划id
  35 + private String ad_id;
  36 + // 微信
  37 + private String weixin;
  38 + // 组件id
  39 + private String module_id;
  40 + // 流量类型,枚举值:
  41 + // 1: 经营 - 自然流量线索
  42 + // 2: 经营 - 广告直接线索
  43 + // 3: 经营 - 广告间接线索
  44 + // 4: 广告线索
  45 + // 5: 无
  46 + private Integer flow_type;
  47 + // 电话
  48 + private String telephone;
  49 + // 姓名
  50 + private String name;
  51 + // 站点id
  52 + private String site_id;
  53 + // 组件名称
  54 + private String module_name;
  55 + // 创意id
  56 + private String cid;
  57 + // 性别,枚举值:
  58 + // 0:未知
  59 + // 1:男
  60 + // 2:女
  61 + private String gender;
  62 + // 互动类型,枚举值:
  63 + // 0: 其他
  64 + // 1: 短视频
  65 + // 2: 直播
  66 + // 3: 企业主页
  67 + // 4: 私信
  68 + // 5: 订阅文章
  69 + // 6: 群聊
  70 + // 7: 独立店铺
  71 + // 8: 搜索服务卡
  72 + private Integer action_type;
  73 + // 门店详细地址
  74 + private String store_address;
  75 + // 用户备注留言
  76 + private String remark;
  77 + // 广告id
  78 + private String promotion_id;
  79 + // 来源抖音号
  80 + private String refer_dy_id;
  81 + // 门店备注
  82 + private String store_remark;
  83 + // 广告主表单自定义字段,无业务逻辑,仅作表单标志
  84 + private String form_remark;
  85 + // 手动填写地域 - 市
  86 + private String city_name;
  87 + // 广告名称
  88 + private String promotion_name;
  89 + // 门店活动名称
  90 + private String store_pack_name;
  91 + // 广告主自定义的其它字段信息,可自定义获取
  92 + // 例:若创建表单时自定义了"test_case"字段的设置,则产生的remark_dict线索为:"test_case": "xxx"
  93 + private Map<String, String> remark_dict;
  94 + // 门店名称
  95 + private String store_name;
  96 + // 转化状态
  97 + private String clue_convert_status;
  98 + // 邮箱
  99 + private String email;
  100 + // 门店所在地
  101 + private String store_location;
  102 + // 来源抖音昵称
  103 + private String refer_dy_name;
  104 + // 门店id
  105 + private String store_id;
  106 + // 详细地址
  107 + private String address;
  108 + // 行业原始字段
  109 + private String business;
  110 + // 计划名称
  111 + private String ad_name;
  112 + // 经营工具id
  113 + private String corporate_tool_id;
  114 + // 线索渠道,枚举值:
  115 + // 0&1: 字节 - 橙子建站
  116 + // 2: 其他渠道 - 外部导入
  117 + // 5: 字节 - 抖音企业号
  118 + // 7: 字节 - 巨量线索
  119 + // 8:字节 - 云店
  120 + // 9:字节 - 星图
  121 + // 10:字节 - 获客宝
  122 + // 11:字节 - 住小帮
  123 + private Integer clue_source;
  124 + // 手动填写地域 - 区
  125 + private String country_name;
  126 + // 流量来源,如[字节 - 今日头条]、[字节 - 抖音]
  127 + private String app_name;
  128 + // 线索类型,枚举值:
  129 + // 0: 字节 - 表单提交
  130 + // 1: 字节 - 在线咨询
  131 + // 2: 字节 - 智能电话
  132 + // 3: 字节 - 网页回呼
  133 + // 4: 字节 - 卡券
  134 + // 5:字节 - 抽奖
  135 + private Integer clue_type;
  136 + // 定位城市,用户提交线索时所在省市
  137 + private String location;
  138 + // 年龄
  139 + private Integer age;
  140 +
  141 + public String getDate() {
  142 + return date;
  143 + }
  144 +
  145 + public void setDate(String date) {
  146 + this.date = date;
  147 + }
  148 +
  149 + public String getStore_pack_id() {
  150 + return store_pack_id;
  151 + }
  152 +
  153 + public void setStore_pack_id(String store_pack_id) {
  154 + this.store_pack_id = store_pack_id;
  155 + }
  156 +
  157 + public String getReq_id() {
  158 + return req_id;
  159 + }
  160 +
  161 + public void setReq_id(String req_id) {
  162 + this.req_id = req_id;
  163 + }
  164 +
  165 + public String getExternal_url() {
  166 + return external_url;
  167 + }
  168 +
  169 + public void setExternal_url(String external_url) {
  170 + this.external_url = external_url;
  171 + }
  172 +
  173 + public String getStore_pack_remark() {
  174 + return store_pack_remark;
  175 + }
  176 +
  177 + public void setStore_pack_remark(String store_pack_remark) {
  178 + this.store_pack_remark = store_pack_remark;
  179 + }
  180 +
  181 + public String getAdv_id() {
  182 + return adv_id;
  183 + }
  184 +
  185 + public void setAdv_id(String adv_id) {
  186 + this.adv_id = adv_id;
  187 + }
  188 +
  189 + public String getMid_info() {
  190 + return mid_info;
  191 + }
  192 +
  193 + public void setMid_info(String mid_info) {
  194 + this.mid_info = mid_info;
  195 + }
  196 +
  197 + public String getId() {
  198 + return id;
  199 + }
  200 +
  201 + public void setId(String id) {
  202 + this.id = id;
  203 + }
  204 +
  205 + public String getAdv_name() {
  206 + return adv_name;
  207 + }
  208 +
  209 + public void setAdv_name(String adv_name) {
  210 + this.adv_name = adv_name;
  211 + }
  212 +
  213 + public String getQq() {
  214 + return qq;
  215 + }
  216 +
  217 + public void setQq(String qq) {
  218 + this.qq = qq;
  219 + }
  220 +
  221 + public String getCreate_time() {
  222 + return create_time;
  223 + }
  224 +
  225 + public void setCreate_time(String create_time) {
  226 + this.create_time = create_time;
  227 + }
  228 +
  229 + public String getProvince_name() {
  230 + return province_name;
  231 + }
  232 +
  233 + public void setProvince_name(String province_name) {
  234 + this.province_name = province_name;
  235 + }
  236 +
  237 + public String getSite_name() {
  238 + return site_name;
  239 + }
  240 +
  241 + public void setSite_name(String site_name) {
  242 + this.site_name = site_name;
  243 + }
  244 +
  245 + public String getAd_id() {
  246 + return ad_id;
  247 + }
  248 +
  249 + public void setAd_id(String ad_id) {
  250 + this.ad_id = ad_id;
  251 + }
  252 +
  253 + public String getWeixin() {
  254 + return weixin;
  255 + }
  256 +
  257 + public void setWeixin(String weixin) {
  258 + this.weixin = weixin;
  259 + }
  260 +
  261 + public String getModule_id() {
  262 + return module_id;
  263 + }
  264 +
  265 + public void setModule_id(String module_id) {
  266 + this.module_id = module_id;
  267 + }
  268 +
  269 + public Integer getFlow_type() {
  270 + return flow_type;
  271 + }
  272 +
  273 + public void setFlow_type(Integer flow_type) {
  274 + this.flow_type = flow_type;
  275 + }
  276 +
  277 + public String getTelephone() {
  278 + return telephone;
  279 + }
  280 +
  281 + public void setTelephone(String telephone) {
  282 + this.telephone = telephone;
  283 + }
  284 +
  285 + public String getName() {
  286 + return name;
  287 + }
  288 +
  289 + public void setName(String name) {
  290 + this.name = name;
  291 + }
  292 +
  293 + public String getSite_id() {
  294 + return site_id;
  295 + }
  296 +
  297 + public void setSite_id(String site_id) {
  298 + this.site_id = site_id;
  299 + }
  300 +
  301 + public String getModule_name() {
  302 + return module_name;
  303 + }
  304 +
  305 + public void setModule_name(String module_name) {
  306 + this.module_name = module_name;
  307 + }
  308 +
  309 + public String getCid() {
  310 + return cid;
  311 + }
  312 +
  313 + public void setCid(String cid) {
  314 + this.cid = cid;
  315 + }
  316 +
  317 + public String getGender() {
  318 + return gender;
  319 + }
  320 +
  321 + public void setGender(String gender) {
  322 + this.gender = gender;
  323 + }
  324 +
  325 + public Integer getAction_type() {
  326 + return action_type;
  327 + }
  328 +
  329 + public void setAction_type(Integer action_type) {
  330 + this.action_type = action_type;
  331 + }
  332 +
  333 + public String getStore_address() {
  334 + return store_address;
  335 + }
  336 +
  337 + public void setStore_address(String store_address) {
  338 + this.store_address = store_address;
  339 + }
  340 +
  341 + public String getRemark() {
  342 + return remark;
  343 + }
  344 +
  345 + public void setRemark(String remark) {
  346 + this.remark = remark;
  347 + }
  348 +
  349 + public String getPromotion_id() {
  350 + return promotion_id;
  351 + }
  352 +
  353 + public void setPromotion_id(String promotion_id) {
  354 + this.promotion_id = promotion_id;
  355 + }
  356 +
  357 + public String getRefer_dy_id() {
  358 + return refer_dy_id;
  359 + }
  360 +
  361 + public void setRefer_dy_id(String refer_dy_id) {
  362 + this.refer_dy_id = refer_dy_id;
  363 + }
  364 +
  365 + public String getStore_remark() {
  366 + return store_remark;
  367 + }
  368 +
  369 + public void setStore_remark(String store_remark) {
  370 + this.store_remark = store_remark;
  371 + }
  372 +
  373 + public String getForm_remark() {
  374 + return form_remark;
  375 + }
  376 +
  377 + public void setForm_remark(String form_remark) {
  378 + this.form_remark = form_remark;
  379 + }
  380 +
  381 + public String getCity_name() {
  382 + return city_name;
  383 + }
  384 +
  385 + public void setCity_name(String city_name) {
  386 + this.city_name = city_name;
  387 + }
  388 +
  389 + public String getPromotion_name() {
  390 + return promotion_name;
  391 + }
  392 +
  393 + public void setPromotion_name(String promotion_name) {
  394 + this.promotion_name = promotion_name;
  395 + }
  396 +
  397 + public String getStore_pack_name() {
  398 + return store_pack_name;
  399 + }
  400 +
  401 + public void setStore_pack_name(String store_pack_name) {
  402 + this.store_pack_name = store_pack_name;
  403 + }
  404 +
  405 + public Map<String, String> getRemark_dict() {
  406 + return remark_dict;
  407 + }
  408 +
  409 + public void setRemark_dict(Map<String, String> remark_dict) {
  410 + this.remark_dict = remark_dict;
  411 + }
  412 +
  413 + public String getStore_name() {
  414 + return store_name;
  415 + }
  416 +
  417 + public void setStore_name(String store_name) {
  418 + this.store_name = store_name;
  419 + }
  420 +
  421 + public String getClue_convert_status() {
  422 + return clue_convert_status;
  423 + }
  424 +
  425 + public void setClue_convert_status(String clue_convert_status) {
  426 + this.clue_convert_status = clue_convert_status;
  427 + }
  428 +
  429 + public String getEmail() {
  430 + return email;
  431 + }
  432 +
  433 + public void setEmail(String email) {
  434 + this.email = email;
  435 + }
  436 +
  437 + public String getStore_location() {
  438 + return store_location;
  439 + }
  440 +
  441 + public void setStore_location(String store_location) {
  442 + this.store_location = store_location;
  443 + }
  444 +
  445 + public String getRefer_dy_name() {
  446 + return refer_dy_name;
  447 + }
  448 +
  449 + public void setRefer_dy_name(String refer_dy_name) {
  450 + this.refer_dy_name = refer_dy_name;
  451 + }
  452 +
  453 + public String getStore_id() {
  454 + return store_id;
  455 + }
  456 +
  457 + public void setStore_id(String store_id) {
  458 + this.store_id = store_id;
  459 + }
  460 +
  461 + public String getAddress() {
  462 + return address;
  463 + }
  464 +
  465 + public void setAddress(String address) {
  466 + this.address = address;
  467 + }
  468 +
  469 + public String getBusiness() {
  470 + return business;
  471 + }
  472 +
  473 + public void setBusiness(String business) {
  474 + this.business = business;
  475 + }
  476 +
  477 + public String getAd_name() {
  478 + return ad_name;
  479 + }
  480 +
  481 + public void setAd_name(String ad_name) {
  482 + this.ad_name = ad_name;
  483 + }
  484 +
  485 + public String getCorporate_tool_id() {
  486 + return corporate_tool_id;
  487 + }
  488 +
  489 + public void setCorporate_tool_id(String corporate_tool_id) {
  490 + this.corporate_tool_id = corporate_tool_id;
  491 + }
  492 +
  493 + public Integer getClue_source() {
  494 + return clue_source;
  495 + }
  496 +
  497 + public void setClue_source(Integer clue_source) {
  498 + this.clue_source = clue_source;
  499 + }
  500 +
  501 + public String getCountry_name() {
  502 + return country_name;
  503 + }
  504 +
  505 + public void setCountry_name(String country_name) {
  506 + this.country_name = country_name;
  507 + }
  508 +
  509 + public String getApp_name() {
  510 + return app_name;
  511 + }
  512 +
  513 + public void setApp_name(String app_name) {
  514 + this.app_name = app_name;
  515 + }
  516 +
  517 + public Integer getClue_type() {
  518 + return clue_type;
  519 + }
  520 +
  521 + public void setClue_type(Integer clue_type) {
  522 + this.clue_type = clue_type;
  523 + }
  524 +
  525 + public String getLocation() {
  526 + return location;
  527 + }
  528 +
  529 + public void setLocation(String location) {
  530 + this.location = location;
  531 + }
  532 +
  533 + public Integer getAge() {
  534 + return age;
  535 + }
  536 +
  537 + public void setAge(Integer age) {
  538 + this.age = age;
  539 + }
  540 +}