forked from Catfeeds/ssrpanel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerChan.php
More file actions
38 lines (33 loc) · 931 Bytes
/
ServerChan.php
File metadata and controls
38 lines (33 loc) · 931 Bytes
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
<?php
namespace App\Components;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7;
use GuzzleHttp\Exception\RequestException;
use Log;
class ServerChan
{
/**
* @param string $title 消息标题
* @param string $content 消息内容
* @param string $key ServerChan上申请的SCKEY
* @return string
*/
public function send($title, $content, $key)
{
$client = new Client();
try {
$response = $client->request('GET', 'https://sc.ftqq.com/' . $key . '.send', [
'query' => [
'text' => $title,
'desp' => $content
]
]);
return json_decode($response->getBody());
} catch (RequestException $e) {
Log::error(Psr7\str($e->getRequest()));
if ($e->hasResponse()) {
Log::error(Psr7\str($e->getResponse()));
}
}
}
}