|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace DingNotice; |
|
4
|
|
|
|
|
5
|
|
|
class DingTalk |
|
6
|
|
|
{ |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @var |
|
10
|
|
|
*/ |
|
11
|
|
|
protected $config; |
|
12
|
|
|
/** |
|
13
|
|
|
* @var string |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $robot = 'default'; |
|
16
|
|
|
/** |
|
17
|
|
|
* @var DingTalkService |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $dingTalkService; |
|
20
|
|
|
|
|
21
|
|
|
protected $client; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* DingTalk constructor. |
|
25
|
|
|
* @param $config |
|
26
|
|
|
* @param SendClient $client |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct($config,$client = null) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->config = $config; |
|
31
|
|
|
$this->client = $client; |
|
32
|
|
|
$this->with(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param string $robot |
|
37
|
|
|
* @return $this |
|
38
|
|
|
*/ |
|
39
|
|
|
public function with($robot = 'default'){ |
|
40
|
|
|
$this->robot = $robot; |
|
41
|
|
|
$this->dingTalkService = new DingTalkService($this->config[$robot],$this->client); |
|
42
|
|
|
return $this; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param string $content |
|
48
|
|
|
* @return mixed |
|
49
|
|
|
*/ |
|
50
|
|
|
public function text($content = ''){ |
|
51
|
|
|
return $this->dingTalkService |
|
52
|
|
|
->setTextMessage($content) |
|
53
|
|
|
->send(); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param $title |
|
58
|
|
|
* @param $text |
|
59
|
|
|
* @return mixed |
|
60
|
|
|
*/ |
|
61
|
|
|
public function action($title, $text){ |
|
62
|
|
|
return $this->dingTalkService |
|
63
|
|
|
->setActionCardMessage($title,$text); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param array $mobiles |
|
68
|
|
|
* @param bool $atAll |
|
69
|
|
|
* @return $this |
|
70
|
|
|
*/ |
|
71
|
|
|
public function at($mobiles = [], $atAll = false){ |
|
72
|
|
|
$this->dingTalkService |
|
73
|
|
|
->setAt($mobiles,$atAll); |
|
74
|
|
|
return $this; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param $title |
|
79
|
|
|
* @param $text |
|
80
|
|
|
* @param $url |
|
81
|
|
|
* @param string $picUrl |
|
82
|
|
|
* @return mixed |
|
83
|
|
|
*/ |
|
84
|
|
|
public function link($title, $text, $url, $picUrl = ''){ |
|
85
|
|
|
return $this->dingTalkService |
|
86
|
|
|
->setLinkMessage($title,$text,$url,$picUrl) |
|
87
|
|
|
->send(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param $title |
|
92
|
|
|
* @param $markdown |
|
93
|
|
|
* @return mixed |
|
94
|
|
|
*/ |
|
95
|
|
|
public function markdown($title, $markdown){ |
|
96
|
|
|
return $this->dingTalkService |
|
97
|
|
|
->setMarkdownMessage($title,$markdown) |
|
98
|
|
|
->send(); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @param $title |
|
103
|
|
|
* @param $markdown |
|
104
|
|
|
* @param int $hideAvatar |
|
105
|
|
|
* @param int $btnOrientation |
|
106
|
|
|
* @return mixed |
|
107
|
|
|
*/ |
|
108
|
|
|
public function actionCard($title, $markdown, $hideAvatar = 0, $btnOrientation = 0){ |
|
109
|
|
|
return $this->dingTalkService |
|
110
|
|
|
->setActionCardMessage($title,$markdown,$hideAvatar,$btnOrientation); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @return mixed |
|
115
|
|
|
*/ |
|
116
|
|
|
public function feed(){ |
|
117
|
|
|
return $this->dingTalkService |
|
118
|
|
|
->setFeedCardMessage(); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
} |
|
122
|
|
|
|