浏览代码

Merge branch 'dev'

luolongfei 3 年之前
父节点
当前提交
86a931c154
共有 4 个文件被更改,包括 23 次插入2 次删除
  1. 1 0
      .env.example
  2. 1 0
      README.md
  3. 1 1
      config.php
  4. 20 1
      libs/MessageServices/Bark.php

+ 1 - 0
.env.example

@@ -98,6 +98,7 @@ SCT_ENABLE=0
 
 
 ######################  Bark 送信  #########################
 ######################  Bark 送信  #########################
 # Bark key 打开 Bark App,注册设备后看到的 key Open the Bark App, register the device and see the key
 # Bark key 打开 Bark App,注册设备后看到的 key Open the Bark App, register the device and see the key
+# 支持直接粘贴 “https://api.day.app/xxx/这里改成你自己的推送内容” 这类文本,程序会自动从中提取有效的 Bark key Support direct paste "https://api.day.app/xxx/这里改成你自己的推送内容" type of text, the program will automatically extract the valid Bark key from it
 BARK_KEY=''
 BARK_KEY=''
 
 
 # Bark 域名 默认是 Bark 作者提供的服务,建议自建 The Bark URL defaults to the server provided by the Bark author, and it is recommended to build your own
 # Bark 域名 默认是 Bark 作者提供的服务,建议自建 The Bark URL defaults to the server provided by the Bark author, and it is recommended to build your own

+ 1 - 0
README.md

@@ -650,6 +650,7 @@ cd /data/wwwroot/freenom/ && php run
 ##### Changed
 ##### Changed
 
 
 - 改进与 Cron 表达式验证相关的正则,兼容各种花里胡哨的表达式
 - 改进与 Cron 表达式验证相关的正则,兼容各种花里胡哨的表达式
+- 支持自动从 Bark url 中提取有效的 Bark key
 
 
 #### [v0.4.3](https://github.com/luolongfei/freenom/releases/tag/v0.4.3) - 2021-11-07
 #### [v0.4.3](https://github.com/luolongfei/freenom/releases/tag/v0.4.3) - 2021-11-07
 
 

+ 1 - 1
config.php

@@ -84,7 +84,7 @@ return [
          * Bark 送信
          * Bark 送信
          */
          */
         'bark' => [
         'bark' => [
-            'bark_key' => env('BARK_KEY'), // 打开 Bark App,注册设备后看到的 Key
+            'bark_key' => (string)env('BARK_KEY'), // 打开 Bark App,注册设备后看到的 Key
             'bark_url' => (string)env('BARK_URL'), // Bark 域名
             'bark_url' => (string)env('BARK_URL'), // Bark 域名
             'bark_is_archive' => env('BARK_IS_ARCHIVE') === '' ? null : (int)env('BARK_IS_ARCHIVE'),
             'bark_is_archive' => env('BARK_IS_ARCHIVE') === '' ? null : (int)env('BARK_IS_ARCHIVE'),
             'bark_group' => env('BARK_GROUP') === '' ? null : env('BARK_GROUP'),
             'bark_group' => env('BARK_GROUP') === '' ? null : env('BARK_GROUP'),

+ 20 - 1
libs/MessageServices/Bark.php

@@ -80,7 +80,7 @@ class Bark extends MessageGateway
 
 
     public function __construct()
     public function __construct()
     {
     {
-        $this->barkKey = config('message.bark.bark_key');
+        $this->barkKey = $this->parseBarkKey(config('message.bark.bark_key'));
         $this->barkUrl = rtrim(config('message.bark.bark_url'), '/');
         $this->barkUrl = rtrim(config('message.bark.bark_url'), '/');
 
 
         $this->isArchive = config('message.bark.bark_is_archive');
         $this->isArchive = config('message.bark.bark_is_archive');
@@ -98,6 +98,25 @@ class Bark extends MessageGateway
         ]);
         ]);
     }
     }
 
 
+    /**
+     * 解析 Bark Key
+     *
+     * 支持从这类 url 地址中提取 Bark Key
+     * https://api.day.app/xxx/这里改成你自己的推送内容
+     *
+     * @param string $barkKey
+     *
+     * @return string
+     */
+    public function parseBarkKey(string $barkKey)
+    {
+        if (preg_match('/^https?:\/\/[^\/]+?\/(?P<barkKey>.+?)\//iu', $barkKey, $m)) {
+            return $m['barkKey'];
+        }
+
+        return $barkKey;
+    }
+
     /**
     /**
      * 生成域名文本
      * 生成域名文本
      *
      *