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
| <?php
$secret = 'SEC065d711a3b14615ae20bbf2ccea4eb86a8e3d6c2b221eeba440d8f3f9b42bf6y'; // 替换自己serert
$token = 'e6111ebe513727ac288e9bbb6b7d212c2ab34b0666eca9c5d0af88f34d7b2cf16'; // 替换自己access token
$time = intval(microtime(true) * 1000);
$sign = urlencode(base64_encode(hash_hmac('sha256', "{$time}\n{$secret}", $secret, true)));
$api = "https://oapi.dingtalk.com/robot/send?access_token={$token}×tamp={$time}&sign={$sign}";
$headers = ['Content-Type: application/json;charset=utf-8'];
$text = <<<TEXT
## 莫名博客
> 嘿嘿哈哈
这里是莫名的博客哦!\n

TEXT;
$post = [
'msgtype' => 'actionCard',
'actionCard' => [
'title' => date('Y-m-d H:i:s'),
'text' => $text,
'btnOrientation' => 1,
'btns' => [
[
'title' => 'Yes',
'actionURL' => 'https://qzone.work',
],
[
'title' => 'No',
'actionURL' => 'https://www.baidu.com',
]
],
],
];
$res = json_decode(getCurl($api, [
'post' => json_encode($post),
'headers' => $headers,
]), true);
print_r($res);
function getCurl($url, $opt = [])
{
$cookie = '';
if (is_array($opt['cookie'])) {
foreach ($opt['cookie'] as $k => $v) {
$cookie .= $k . '=' . $v . '; ';
}
}
$cookie = (mb_substr($cookie, 0, mb_strlen($cookie) - 2));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_NOBODY, $opt['nobody']);
curl_setopt($ch, CURLOPT_HEADER, $opt['header'] ?? false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $opt['headers'] ?? []);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, $opt['rtime'] ?? 10000);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, $opt['ctime'] ?? 10000);
curl_setopt($ch, CURLOPT_REFERER, $opt['refer'] ?? 'https://user.qzone.qq.com/');
curl_setopt($ch, CURLOPT_USERAGENT,
$opt['UA'] ?? "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36");
if (isset($opt['post'])) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, is_array($opt['post']) ? http_build_query($opt['post']) : $opt['post']);
}
if (isset($opt['proxy']) && is_array($opt['proxy'])) {
curl_setopt($ch, CURLOPT_PROXY, $opt['proxy']['ip']);
curl_setopt($ch, CURLOPT_PROXYPORT, $opt['proxy']['port']);
}
$res = curl_exec($ch);
$error = curl_error($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($opt['detail']) {
return ['code' => $code, 'error' => $error, 'response' => $res,];
}
return $res;
}
|