Total Complexity | 5 |
Total Lines | 67 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
14 | class HttpClient implements SendClient |
||
15 | { |
||
16 | protected $client; |
||
17 | protected $config; |
||
18 | /** |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $hookUrl = "https://oapi.dingtalk.com/robot/send"; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $accessToken = ""; |
||
27 | |||
28 | public function __construct($config) |
||
29 | { |
||
30 | $this->config = $config; |
||
31 | $this->setAccessToken(); |
||
32 | $this->client = $this->createClient(); |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * |
||
37 | */ |
||
38 | public function setAccessToken(){ |
||
39 | $this->accessToken = $this->config['token']; |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * create a guzzle client |
||
44 | * @return Client |
||
45 | * @author wangju 2019-05-17 20:25 |
||
46 | */ |
||
47 | protected function createClient() |
||
48 | { |
||
49 | $client = new Client([ |
||
50 | 'timeout' => $this->config['timeout'] ?? 2.0, |
||
51 | ]); |
||
52 | return $client; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @return string |
||
57 | */ |
||
58 | public function getRobotUrl(){ |
||
59 | return $this->hookUrl . "?access_token={$this->accessToken}"; |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * send message |
||
64 | * @param $url |
||
65 | * @param $params |
||
66 | * @return array |
||
67 | * @author wangju 2019-05-17 20:48 |
||
68 | */ |
||
69 | public function send($params): array |
||
81 | } |
||
82 | } |
||
83 |