Commit 9e07bd53feb3b04245b239805caf21defc66b3a0

Authored by 王明元
1 parent 384d35dc

2023年6月19日16:25:23 修复抖音页面修改导致无法获取登录二维码问题

db/freya.mv.db
No preview for this file type
fw-freya.iml
... ... @@ -163,5 +163,7 @@
163 163 <orderEntry type="library" name="Maven: cn.hutool:hutool-setting:5.7.16" level="project" />
164 164 <orderEntry type="library" name="Maven: cn.hutool:hutool-log:5.7.16" level="project" />
165 165 <orderEntry type="library" name="Maven: com.alibaba:fastjson:1.2.78" level="project" />
  166 + <orderEntry type="library" name="Maven: com.aliyun:alibaba-dingtalk-service-sdk:1.0.1" level="project" />
  167 + <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.1.1" level="project" />
166 168 </component>
167 169 </module>
168 170 \ No newline at end of file
... ...
... ... @@ -86,6 +86,18 @@
86 86 <artifactId>fastjson</artifactId>
87 87 <version>1.2.78</version>
88 88 </dependency>
  89 + <!-- 钉钉消息推送 -->
  90 + <dependency>
  91 + <groupId>com.aliyun</groupId>
  92 + <artifactId>alibaba-dingtalk-service-sdk</artifactId>
  93 + <version>1.0.1</version>
  94 + <exclusions>
  95 + <exclusion>
  96 + <groupId>log4j</groupId>
  97 + <artifactId>log4j</artifactId>
  98 + </exclusion>
  99 + </exclusions>
  100 + </dependency>
89 101 </dependencies>
90 102  
91 103 <build>
... ...
src/main/java/cn/fw/freya/service/crawl/impl/DouYinCrawl.java
... ... @@ -87,9 +87,9 @@ public class DouYinCrawl implements CrawlStrategy {
87 87 }
88 88 driver.get("https://creator.douyin.com/");// 打开指定的页面
89 89 new WebDriverWait(driver, 10, 300).until(driver1 ->
90   - driver1.findElement(By.xpath("//div[@class='creator-header-nav']//span[@class='login']"))).click();// 获取'登录'按钮元素, 单击
91   - new WebDriverWait(driver, 10, 300).until(driver1 ->
92   - driver1.findElement(By.xpath("//span[@class='semi-button-content']"))).click();
  90 + driver1.findElement(By.xpath("//div[@class = 'banner-div active']"))).click();// 获取'登录'按钮元素, 单击
  91 + /*new WebDriverWait(driver, 10, 300).until(driver1 ->
  92 + driver1.findElement(By.xpath("//span[@class='semi-button-content']"))).click();*/
93 93 WebElement qrCodeEle = new WebDriverWait(driver, 10, 300).until(driver1 ->
94 94 driver1.findElement(By.xpath("//div[@class='qrcode-image']/img[1]")));
95 95 return qrCodeEle.getAttribute("src");// 返回对象src属性对应的值
... ...
src/main/java/cn/fw/freya/utils/dingding/DingTalkService.java 0 → 100644
  1 +package cn.fw.freya.utils.dingding;
  2 +
  3 +import com.dingtalk.api.DefaultDingTalkClient;
  4 +import com.dingtalk.api.DingTalkClient;
  5 +import com.dingtalk.api.request.OapiRobotSendRequest;
  6 +import com.dingtalk.api.response.OapiRobotSendResponse;
  7 +import lombok.extern.slf4j.Slf4j;
  8 +import org.apache.commons.codec.binary.Base64;
  9 +
  10 +import javax.crypto.Mac;
  11 +import javax.crypto.spec.SecretKeySpec;
  12 +import java.net.URLEncoder;
  13 +import java.nio.charset.StandardCharsets;
  14 +import java.util.List;
  15 +
  16 +/**
  17 + * @author wmy3969
  18 + * @version 1.0
  19 + * @date 2022/2/8 9:24
  20 + * @Description 钉钉推送服务类
  21 + */
  22 +@Slf4j
  23 +public class DingTalkService {
  24 +
  25 + public static final String TEXT = "text";// 文本消息
  26 + public static final String WEBHOOK = "https://oapi.dingtalk.com/robot/send?access_token=e4b93e75a58be3bf142ad91b6a4b0f99c404d6eb1115ac6d9d36333a66aeec3c";// webhook
  27 + public static final String SECRET = "SECb0357db53bc981e5886b5fe6c41560ddaeb3dd0ba1b2528308fdc4908dabd668";// 密钥
  28 +
  29 + /**
  30 + * 推送消息
  31 + *
  32 + * @param body 发送的消息体
  33 + * @throws Exception
  34 + */
  35 + public static void sendMessage(SendMessageBody body) throws Exception {
  36 + log.info("开始推送钉钉消息:" + body);
  37 + Long timestamp = System.currentTimeMillis();
  38 + String secret = body.getSecret();
  39 +
  40 + String stringToSign = timestamp + "\n" + secret;
  41 + Mac mac = Mac.getInstance("HmacSHA256");
  42 + mac.init(new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA256"));
  43 + byte[] signData = mac.doFinal(stringToSign.getBytes(StandardCharsets.UTF_8));
  44 + String sign = URLEncoder.encode(new String(Base64.encodeBase64(signData)), "UTF-8");
  45 +
  46 + DingTalkClient client = new DefaultDingTalkClient(body.getWebhook() + "&timestamp=" + timestamp + "&sign=" + sign);
  47 + OapiRobotSendRequest request = new OapiRobotSendRequest();
  48 +
  49 + OapiRobotSendRequest.At at = new OapiRobotSendRequest.At();
  50 + if (body.isAtAll() || body.getMobileList() == null || body.getMobileList().isEmpty()) {
  51 + at.setIsAtAll(true);// 推送所有人
  52 + } else {
  53 + at.setAtMobiles(body.getMobileList());
  54 + at.setIsAtAll(false);// 推送指定用户
  55 + }
  56 + request.setAt(at);
  57 +
  58 + if (TEXT.equals(body.getMsgType())) {// 文本消息
  59 + request.setMsgtype(TEXT);
  60 + OapiRobotSendRequest.Text text = new OapiRobotSendRequest.Text();
  61 + text.setContent(body.getText());
  62 + request.setText(text);
  63 + }
  64 +
  65 + OapiRobotSendResponse response = client.execute(request);
  66 + log.info("钉钉推送返回结果:" + response);
  67 + }
  68 +
  69 + /**
  70 + * 给群里发送一条钉钉消息 @所有人
  71 + *
  72 + * @param message 消息内容
  73 + * @throws Exception
  74 + */
  75 + public static void sendToEverybody(String message) throws Exception {
  76 + sendMessage(SendMessageBody.builder()
  77 + .isAtAll(true)
  78 + .msgType(TEXT)
  79 + .webhook(WEBHOOK)
  80 + .secret(SECRET)
  81 + .text(message)
  82 + .build());
  83 + }
  84 +
  85 + /**
  86 + * 给群里发送一条钉钉消息 @指定的人
  87 + *
  88 + * @param message 消息内容
  89 + * @param peopleList 指定的人手机号集合
  90 + * @throws Exception
  91 + */
  92 + public static void sendToSpecified(String message, List<String> peopleList) throws Exception {
  93 + sendMessage(SendMessageBody.builder()
  94 + .isAtAll(false)
  95 + .msgType(TEXT)
  96 + .webhook(WEBHOOK)
  97 + .secret(SECRET)
  98 + .text(message)
  99 + .mobileList(peopleList)
  100 + .build());
  101 + }
  102 +}
... ...
src/main/java/cn/fw/freya/utils/dingding/SendMessageBody.java 0 → 100644
  1 +package cn.fw.freya.utils.dingding;
  2 +
  3 +import lombok.AllArgsConstructor;
  4 +import lombok.Builder;
  5 +import lombok.Data;
  6 +import lombok.NoArgsConstructor;
  7 +
  8 +import java.util.List;
  9 +
  10 +/**
  11 + * @author wmy3969
  12 + * @version 1.0
  13 + * @date 2022/2/8 9:28
  14 + * @Description 发送钉钉消息
  15 + */
  16 +@Data
  17 +@NoArgsConstructor
  18 +@AllArgsConstructor
  19 +@Builder(toBuilder = true)
  20 +public class SendMessageBody {
  21 + /**
  22 + * 消息类型
  23 + */
  24 + private String msgType;
  25 + /**
  26 + * webhook
  27 + */
  28 + private String webhook;
  29 + /**
  30 + * 密钥
  31 + */
  32 + private String secret;
  33 + /**
  34 + * 消息文本
  35 + */
  36 + private String text;
  37 + /**
  38 + * 群内指定成员手机号
  39 + */
  40 + private List<String> mobileList;
  41 + /**
  42 + * 是否推送所有人
  43 + */
  44 + private boolean isAtAll;
  45 +}
... ...