Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
fix: 修复微信警报功能
Browse files Browse the repository at this point in the history
  • Loading branch information
linkunyuan committed Nov 10, 2023
1 parent cafde1e commit 6a7c026
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 49 deletions.
15 changes: 11 additions & 4 deletions src/DingTalk/Message/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,20 @@ abstract class Base extends SplBean implements MessageInterface

public function getAtText($text = '')
{
foreach (['atMobiles', 'atUserIds'] as $item)
{
foreach ($this->{$item} as $tel)
{
foreach (['atMobiles', 'atUserIds'] as $item) {
foreach ($this->{$item} as $tel) {
$text .= ' @' . $tel;
}
}
return $text;
}

public function getServerText($text = '')
{
return $text . PHP_EOL . implode(PHP_EOL, [
'系统:' . APP_MODULE,
'服务器:' . config('SERVNAME'),
'时间:' . date('Y年m月d日 H:i:s')
]);
}
}
2 changes: 1 addition & 1 deletion src/DingTalk/Message/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function fullData()
return [
'msgtype' => 'text',
'text' => [
'content' => $this->getAtText($this->content)
'content' => $this->getServerText($this->getAtText($this->content))
],
'at' => [
'atMobiles' => $this->atMobiles,
Expand Down
11 changes: 8 additions & 3 deletions src/WeChat/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

namespace WonderGame\EsNotify\WeChat;

use EasySwoole\Spl\SplBean;
use WonderGame\EsNotify\Interfaces\ConfigInterface;
use WonderGame\EsNotify\Interfaces\NotifyInterface;
use EasySwoole\Spl\SplBean;

/**
* @document https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Template_Message_Interface.html
*
* 更新公告:https://mp.weixin.qq.com/cgi-bin/announce?action=getannouncement&announce_id=11680142498cInTZ&version=&lang=zh_CN&token=2080631067
*
*/
class Config extends SplBean implements ConfigInterface
{
/**
Expand Down Expand Up @@ -86,8 +92,7 @@ public function getAppend()

public function setToOpenid($openid)
{
if (is_string($openid))
{
if (is_string($openid)) {
$openid = [$openid];
}
$this->toOpenid = $openid;
Expand Down
18 changes: 4 additions & 14 deletions src/WeChat/Message/Notice.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,15 @@

class Notice extends Base
{
protected $title = '';

protected $content = '';

protected $color = '#32CD32';

public function struct()
{
return [
'first' => [
'value' => $this->title,
'color' => $this->color
],
'keyword1' => [
'value' => $this->content,
'color' => $this->color
],
'keyword3' => date('Y年m月d日 H:i:s'),
'remark' => '查看详情'
'keyword1' => ['value' => $this->content],
'keyword2' => ['value' => APP_MODULE],
'keyword3' => ['value' => config('SERVNAME')],
'keyword4' => ['value' => date('Y年m月d日 H:i:s')],
];
}
}
32 changes: 5 additions & 27 deletions src/WeChat/Message/Warning.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,15 @@

class Warning extends Base
{
protected $file = '';

protected $line = '';

protected $servername = '';

protected $message = '';

protected $color = '#FF0000';
protected $content = '';

public function struct()
{
return [
'first' => [
'value' => "程序异常:第{$this->line}",
'color' => $this->color
],
'keyword1' => [
'value' => "服务器: {$this->servername}",
'color' => $this->color
],
'keyword2' => [
'value' => "相关文件: {$this->file}",
'color' => $this->color
],
'keyword3' => [
'value' => "相关内容:{$this->message}",
'color' => $this->color
],
'keyword4' => date('Y年m月d日 H:i:s'),
'remark' => '查看详情'
'keyword1' => ['value' => $this->content],
'keyword2' => ['value' => APP_MODULE],
'keyword3' => ['value' => config('SERVNAME')],
'keyword4' => ['value' => date('Y年m月d日 H:i:s')],
];
}
}

0 comments on commit 6a7c026

Please sign in to comment.