Wx.php
1022 字节
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
<?php
namespace Lackoxygen\ExceptionPush\Agents;
use GuzzleHttp\RequestOptions;
use Lackoxygen\ExceptionPush\Attribute\Attribute;
use Lackoxygen\ExceptionPush\Client;
use Lackoxygen\ExceptionPush\Contracts\AgentInterface;
class Wx implements AgentInterface
{
use Attribute;
public string $key = '';
public bool $enable = true;
public function report(array $content)
{
/**
* @var \GuzzleHttp\Client $client
*/
$client = Client::new('https://qyapi.weixin.qq.com');
$client->post('cgi-bin/webhook/send', [
RequestOptions::HEADERS => [
'content-type' => 'application/json'
], RequestOptions::QUERY => [
'key' => $this->key,
], RequestOptions::JSON => [
'msgtype' => 'text', 'text' => [
'content' => join("\n", $content)
]
]
]);
}
public function disabled(): bool
{
return !$this->enable;
}
}