fixed:修复微信通知错误

This commit is contained in:
david 2022-10-13 20:45:23 +08:00
parent 49ba219f50
commit f70b454beb
8 changed files with 73 additions and 33 deletions

View File

@ -24,7 +24,6 @@ class Reseed implements ConfigParserInterface
$rs = [
'sites' => [],
'clients' => [],
'notify' => [],
];
if (empty($uuid)) {
return $rs;
@ -40,7 +39,6 @@ class Reseed implements ConfigParserInterface
//微信通知
$rs['weixin'] = Config::getWeixin();
$rs['notify'] = Config::getNotify();
//解析站点
$sites = Config::getUserSites();

View File

@ -13,7 +13,7 @@ use app\domain\Config as domainConfig;
*/
function IYUU_VERSION(): string
{
return '2.1.9';
return '2.1.10';
}
/**

View File

@ -4,6 +4,9 @@ namespace IYUU\Notify;
use app\common\components\Curl as ICurl;
/**
* Bark通知
*/
class Bark implements INotify
{
/**
@ -19,6 +22,9 @@ class Bark implements INotify
*/
private $group = 'IYUU';
/**
* @param array $config
*/
public function __construct(array $config)
{
$this->bark_v2_server = $config['server'];
@ -27,7 +33,12 @@ class Bark implements INotify
$this->group = $config['group'];
}
public function send(string $title, string $content): bool
/**
* @param string $title
* @param string $content
* @return false|string
*/
public function send(string $title, string $content)
{
$desp = empty($content) ? date("Y-m-d H:i:s") : $content;
$data = array(
@ -35,10 +46,10 @@ class Bark implements INotify
"title" => $title,
"body" => $desp,
"device_key" => $this->device_key,
// "sound" => "minuet.caf",
// "badge" => 1,
// "icon" => "https://xxxx.xx/avatar.jpg",
// "url" => "https://github.com/Finb"
/*"sound" => "minuet.caf",
"badge" => 1,
"icon" => "https://xxxx.xx/avatar.jpg",
"url" => "https://github.com/Finb"*/
);
return ICurl::http_post($this->bark_v2_server, $data, true);
}

View File

@ -2,7 +2,22 @@
namespace IYUU\Notify;
interface INotify {
function __construct(array $config);
/**
* 定义通知接口
*/
interface INotify
{
/**
* 构造函数
* @param array $config
*/
public function __construct(array $config);
/**
* 发送通知
* @param string $title
* @param string $content
* @return mixed
*/
public function send(string $title, string $content);
}

View File

@ -4,6 +4,9 @@ namespace IYUU\Notify;
use app\common\components\Curl as ICurl;
/**
* 爱语飞飞微信模板消息通知
*/
class IYUUWechat implements INotify
{
/**
@ -11,12 +14,20 @@ class IYUUWechat implements INotify
*/
private $token;
/**
* @param array $config
*/
public function __construct(array $config)
{
$this->token = $config['token'];
}
public function send(string $title, string $content): bool
/**
* @param string $title
* @param string $content
* @return false|string
*/
public function send(string $title, string $content)
{
$desp = empty($content) ? date("Y-m-d H:i:s") : $content;
$data = array(

View File

@ -4,33 +4,28 @@ namespace IYUU\Notify;
use app\domain\Config;
use Error;
use Exception;
class NotifyFactory
{
/**
* 缓存的通知渠道
* @var array<string, INotify> | null
* @var array<string, INotify>
*/
private static $notify_channels = null;
private static function init()
{
$result = [];
$notifyConfigs = Config::getNotify();
foreach ($notifyConfigs as $key => $option) {
$result[$key] = self::create($option['type'], $option['options']);
}
self::$notify_channels = $result;
}
private static $notify_channels;
/**
* @param string $name
* @return null | INotify
* @throws Exception
*/
public static function get(string $name)
public static function get(string $name): ?INotify
{
if (self::$notify_channels == null) {
self::init();
if (null === self::$notify_channels) {
$notifyConfigs = Config::getNotify();
foreach ($notifyConfigs as $key => $option) {
self::$notify_channels[$key] = self::create($option['type'], $option['options']);
}
}
return self::$notify_channels[$name];
}
@ -39,9 +34,9 @@ class NotifyFactory
* @param string $type
* @param array $options
* @return INotify
* @throws Error
* @throws Exception
*/
private static function create(string $type, array $options)
private static function create(string $type, array $options): INotify
{
switch ($type) {
case 'iyuu':
@ -52,9 +47,9 @@ class NotifyFactory
return new Bark($options);
case 'sms':
case 'email':
throw new Error("unimplemented type `$type`");
throw new Exception("unimplemented type {$type}");
default:
throw new Error("unknown notify type `$type`");
throw new Exception("unknown notify type {$type}");
}
}
}

View File

@ -4,6 +4,9 @@ namespace IYUU\Notify;
use app\common\components\Curl as ICurl;
/**
* Server酱
*/
class ServerChan implements INotify
{
/**
@ -11,12 +14,20 @@ class ServerChan implements INotify
*/
private $key;
/**
* @param array $config
*/
public function __construct(array $config)
{
$this->key = $config['key'];
}
public function send(string $title, string $content): bool
/**
* @param string $title
* @param string $content
* @return false|string
*/
public function send(string $title, string $content)
{
$desp = empty($content) ? date("Y-m-d H:i:s") : $content;
$data = array(

View File

@ -1256,7 +1256,6 @@ class AutoReseed
}
break;
case 'off':
return false;
default:
break;
}