loading...
魔改Daovoice添加实时监控
Published in:2022-03-04 | category: 魔改
Words: 591 | Reading time: 2min | reading:

有一次看到国光用了这个功能好像还蛮屌的,于是自己也用了一下,用的过程中发现一个问题,就是会错过很多消息,不能及时的回复,本着研究的精神,便有了以下的文章

魔改Daovoice添加实时监控

分析源码

先发一个消息,看整个过程调用了哪些函数

一眼就能看到关键函数

跟进去之后下断点

然后再来来发送一遍消息,看看消息在哪个变量中,最后确定是在t.body里面

加上alert测试是否正常捕捉到消息

对接钉钉

直接上php代码了,大家伙自己看着改吧

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
function request_by_curl($remote_server, $post_string)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $remote_server);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json;charset=utf-8'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// 不用开启curl证书验证
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$data = curl_exec($ch);
//$info = curl_getinfo($ch);
//var_dump($info);
curl_close($ch);
return $data;
}

function XXXXXXXXXX($content,$webhook){
if (!empty($content)){
$data = [
'msgtype' => 'link',
'link' => [
'text' => '您的博客有人留言说: '.$content,
'title' => '您的Daovoice有新的即时消息,请点击查看',
'picUrl' => '',
'messageUrl' => "http://dashboard.daovoice.io/app/XXXX/inboxes/XXXX/conversations/"
]
];
$textString = json_encode($data);
$result = request_by_curl($webhook, $textString);
}else{
$data = [
'msgtype' => 'link',
'link' => [
'text' => '您有可能收到了一张图片',
'title' => '您的Daovoice有新的即时消息,请点击查看',
'picUrl' => '',
'messageUrl' => "http://dashboard.daovoice.io/app/XXXX/inboxes/XXXX/conversations/"
]
];
$textString = json_encode($data);
$result = request_by_curl($webhook, $textString);
}
}

function main(){
$content = $_POST['daovoice_content'];
$verify = $_POST['verify'];

$webhook = "https://oapi.dingtalk.com/robot/send?access_token=XXXX";
if($verify == "True"){
XXXXXXXXXX($content,$webhook);
}
}

main();

魔改源码

先下载JS

然后在sendMessage函数结尾添加代码

1
2
3
4
5
6
7
8
9
var httpRequest = new XMLHttpRequest();
httpRequest.open("POST","https://XXXX/XXXX.php",true);
httpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
httpRequest.send("daovoice_content="+t.body+"&verify=True");
httpRequest.onreadystatechange = ()=>{
if(httpRequest.status == 200){
console.log("留言成功");
}
}

整体代码效果如下

总结

还可以做更多的优化,例如获取到匿名者的ID,拼装组成URL这样钉钉收到消息,点击链接即可跳转回复

Prev:
mac版钉钉防撤回
Next:
2021年终总结
catalog
catalog