-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebhook.php
More file actions
106 lines (91 loc) · 3.32 KB
/
Webhook.php
File metadata and controls
106 lines (91 loc) · 3.32 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
require_once "Init.php";
require_once "Log.php";
/**
* Send Message to Lark Chat Group.
*/
function Lark(string $Token, string $Topic = "", array $Message = null): array {
throw new Exception("Not Implemented");
}
/**
* Send Message to Slack Chat Group.
*/
function Slack(string $Token, string $Topic = "", array $Message = null): array {
throw new Exception("Not Implemented");
}
/**
* Send Message to Enterprise WeChat Chat Group. `Token` Should Likes `{{ACCESS_TOKEN}}|{{CHAT_ID}}`.
*/
function WeChat(string $Token, string $Topic = "", array $Message = null): array {
throw new Exception("Not Implemented");
}
/**
* Send Message to DingTalk Chat Group.
*/
function DingTalk(string $Token, string $Topic = "", array $Message = null): array {
$Response = [
"Ec" => 0,
"Em" => ""
];
if ($Message === null) { $Message = []; }
try {
$MessageBody = "<font color=#6A65FF>**" . $Topic . "**</font> \n\n " . date("Y-m-d H:i:s") . " \n\n";
foreach ($Message as $Item) {
if (empty($Item["Title"])) {
$MessageBody .= " --- \n\n ";
} else {
$Color = strtoupper($Item["Color"] ?? "UNKNOWN");
if (strpos($Color, "#") !== 0 || strlen($Color) != 7) {
$Color = [
"PURPLE" => "#6A65FF",
"RED" => "#FF6666",
"GREEN" => "#92D050",
"BLUE" => "#76CCFF"
][$Color] ?? "#76CCFF";
}
$MessageBody .= " --- \n\n <font color=" . $Color . ">**" . $Item["Title"] . "**</font> \n\n ";
}
$MessageBody .= implode(" \n\n ", $Item["Text"] ?? []) . " \n\n ";
}
$MessageBody .= "<font color=#6A65FF>" . $Topic . "</font>";
} catch (Exception $Error) {
$Response["Ec"] = 50001; $Response["Em"] = MakeErrorMessage($Error); return $Response;
}
try {
$Url = "https://oapi.dingtalk.com/robot/send?access_token=" . str_replace("https://oapi.dingtalk.com/robot/send?access_token=", "", str_replace("http://oapi.dingtalk.com/robot/send?access_token=", "", $Token));
$Dat = [
"msgtype" => "markdown",
"markdown" => [
"title" => $Topic,
"text" => $MessageBody
]
];
$Rsp = json_decode(file_get_contents($Url, false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "content-type: application/json",
"content" => json_encode($Dat),
"timeout" => 10
]
])), true);
if (($Rsp["errcode"] ?? -1) !== 0) {
throw new Exception(($Rsp["errcode"] ?? "Unknown") . "-" . ($Rsp["errmsg"] ?? "Unknown"));
}
} catch (Exception $Error) {
$Response["Ec"] = 50002; $Response["Em"] = MakeErrorMessage($Error); return $Response;
}
return $Response;
}
/**
* Send Message via Telegram Bot.
*/
function Telegram(string $Token, string $Topic = "", array $Message = null): array {
throw new Exception("Not Implemented");
}
/**
* Send Message via SeverChan.
*/
function SeverChan(string $Token, string $Topic = "", array $Message = null): array {
throw new Exception("Not Implemented");
}
?>