作者 lackoxygen

feat:去掉pkg依赖

@@ -23,7 +23,6 @@ @@ -23,7 +23,6 @@
23 }, 23 },
24 "require": { 24 "require": {
25 "php": ">=7.4", 25 "php": ">=7.4",
26 - "wujunze/dingtalk-exception": "^2.2",  
27 "illuminate/queue":"^8.0", 26 "illuminate/queue":"^8.0",
28 "illuminate/support": "^8.0", 27 "illuminate/support": "^8.0",
29 "illuminate/bus": "^8.0", 28 "illuminate/bus": "^8.0",
@@ -2,8 +2,9 @@ @@ -2,8 +2,9 @@
2 2
3 namespace Lackoxygen\ExceptionPush\Agents; 3 namespace Lackoxygen\ExceptionPush\Agents;
4 4
5 -use DingNotice\DingTalkService; 5 +use GuzzleHttp\Psr7\Request;
6 use Lackoxygen\ExceptionPush\Attribute\Attribute; 6 use Lackoxygen\ExceptionPush\Attribute\Attribute;
  7 +use Lackoxygen\ExceptionPush\Client;
7 use Lackoxygen\ExceptionPush\Contracts\AgentInterface; 8 use Lackoxygen\ExceptionPush\Contracts\AgentInterface;
8 9
9 class Ding implements AgentInterface 10 class Ding implements AgentInterface
@@ -18,10 +19,51 @@ class Ding implements AgentInterface @@ -18,10 +19,51 @@ class Ding implements AgentInterface
18 19
19 public function report(array $content) 20 public function report(array $content)
20 { 21 {
21 - $talk = new DingTalkService(['token' => $this->token, 'enabled' => true, 'secret' => $this->secret]);  
22 - $talk->setTextMessage(join("\n", $content))->send(); 22 + /**
  23 + * @var \GuzzleHttp\Client $client
  24 + */
  25 + $client = Client::new('https://oapi.dingtalk.com');
  26 +
  27 + $uri = sprintf('robot/send?access_token=%s', $this->token);
  28 +
  29 + if (!empty($this->secret)) {
  30 + $timestamp = time() . sprintf('%03d', rand(1, 999));
  31 + $sign = hash_hmac('sha256', $timestamp . "\n" . $this->secret, $this->secret, true);
  32 + $uri .= '&timestamp=' . $timestamp;
  33 + $uri .= '&sign=' . base64_encode($sign);
  34 + }
  35 +
  36 + $request = new Request(
  37 + 'POST',
  38 + $uri,
  39 + [
  40 + 'Content-Type' => 'application/json;charset=utf-8'
  41 + ],
  42 + $this->body($content),
  43 + '1.1'
  44 + );
  45 +
  46 + $client->send($request);
  47 + }
  48 +
  49 + /**
  50 + * @param array $content
  51 + * @return string
  52 + */
  53 + protected function body(array $content): string
  54 + {
  55 + return json_encode([
  56 + 'msgtype' => 'text',
  57 + 'text' => [
  58 + 'content' => join("\n", $content)
  59 + ],
  60 + 'isAtAll' => false
  61 + ]);
23 } 62 }
24 63
  64 + /**
  65 + * @return bool
  66 + */
25 public function disabled(): bool 67 public function disabled(): bool
26 { 68 {
27 return !$this->enable; 69 return !$this->enable;