Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
luolongfei committed Dec 14, 2021
2 parents ba9a313 + 522f419 commit b6e3de8
Show file tree
Hide file tree
Showing 25 changed files with 149 additions and 21 deletions.
160 changes: 144 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ Documentation: [English version](https://github.com/luolongfei/freenom/blob/main

[⛵ 通过 Docker 方式部署](#-方式一通过-docker-部署推荐最简单的部署方式)(推荐,最简单的部署方式)

[🕹 通过腾讯云函数部署](#-方式二通过腾讯云函数部署推荐无服务器的用户使用)(推荐无服务器的用户使用
[🕹 通过腾讯云函数部署](#-方式二通过腾讯云函数部署)(供无服务器的用户使用

[🚧 直接拉取源码部署](#-方式三直接拉取源码部署)
[🧊 通过阿里云函数部署](#-方式三通过阿里云函数部署)(同上,供无服务器的用户使用)

[🚧 直接拉取源码部署](#-方式四直接拉取源码部署)

[📋 捐赠名单 Donate List](#-捐赠名单-donate-list)

Expand All @@ -47,7 +49,8 @@ Documentation: [English version](https://github.com/luolongfei/freenom/blob/main
仓库,然后在 [@Mattraks](https://github.com/Mattraks) 的提醒下,通过特别的方式恢复了本仓库。
- 本次封禁导致的直接后果是以前的`issues`全部丢失,以及近`1.8k``star`数重新归零,在动力上面确实有受到影响,不过也不会有太大影响,本项目依然长期维护,如果项目有帮到你,欢迎 star。
- 狡兔三窟,临时仓库 https://github.com/luolongfei/next-freenom 也是备用仓库,如若本仓库再次失联,可以移步到备用仓库获取最新消息,正常情况下以后的开发维护依然在本仓库进行。
- 推荐 [通过 Docker 方式部署](#-方式一通过-docker-部署推荐最简单的部署方式),或者参考下方文档直接搬运到 [腾讯云函数部署](#-方式二通过腾讯云函数部署推荐无服务器的用户使用) ,腾讯云函数不需要有自己的服务器。
- 推荐 [⛵ 通过 Docker 方式部署](#-方式一通过-docker-部署推荐最简单的部署方式),也可以参考下方文档 [🕹 通过腾讯云函数部署](#-方式二通过腾讯云函数部署)
或者 [🧊 通过阿里云函数部署](#-方式三通过阿里云函数部署),腾讯云函数和阿里云函数不需要你有自己的服务器。

### 📃 引言

Expand All @@ -61,7 +64,8 @@ Documentation: [English version](https://github.com/luolongfei/freenom/blob/main

### 🎁 事前准备

- VPS:随便一台服务器都行,系统推荐`Centos7`或者`Debian`,另外 PHP 版本需在`php7.2`及以上。如果你没有服务器,推荐参考下方文档部署到 [腾讯云函数](#-方式二通过腾讯云函数部署推荐无服务器的用户使用)
- VPS:随便一台服务器都行,系统推荐`Centos7`或者`Debian`,另外 PHP 版本需在`php7.2`及以上。如果你没有服务器,推荐参考下方文档
[🕹 通过腾讯云函数部署](#-方式二通过腾讯云函数部署) 或者 [🧊 通过阿里云函数部署](#-方式三通过阿里云函数部署)
- 送信邮箱(可选):为了方便理解又称机器人邮箱,用于发送通知邮件。目前针对`Gmail``QQ邮箱``163邮箱`以及`Outlook邮箱`,程序会自动判断送信邮箱类型并使用合适的配置。
如果你使用的是其它第三方邮箱或者自建邮件服务,那么请参考 [.env.example](https://github.com/luolongfei/freenom/blob/main/.env.example)
文件中与邮件配置相关的注释进行配置。
Expand Down Expand Up @@ -263,11 +267,11 @@ Bark 是一款 IOS 端用于推送自定义通知的 app,是个人开发者在

***

*与 配置送信功能 相关的篇幅完。下面开始讲本项目的三种使用方式,一种是通过 Docker,另一种是通过腾讯云函数,再一种是直接拉取源码部署,推荐使用 Docker 方式,无需纠结环境。*
*与 配置送信功能 相关的篇幅完。下面开始讲本项目的几种使用方式。推荐使用 Docker 方式,无需纠结环境。*

### ⛵ 方式一:通过 Docker 部署(推荐,最简单的部署方式)
***

<hr>
### ⛵ 方式一:通过 Docker 部署(推荐,最简单的部署方式)

Docker 仓库地址为: [https://hub.docker.com/r/luolongfei/freenom](https://hub.docker.com/r/luolongfei/freenom) ,同样欢迎 star 。
此镜像支持的架构为`linux/amd64``linux/arm64``linux/ppc64le``linux/s390x``linux/386``linux/arm/v7``linux/arm/v6`, 理论上支持`群晖`
Expand Down Expand Up @@ -440,42 +444,154 @@ docker stats --no-stream
docker version
```

重启 Docker(非容器)

```shell
systemctl restart docker
```

*有关容器部署的内容结束。*

### 🕹 方式二:通过腾讯云函数部署(推荐无服务器的用户使用)
***

<hr>
### 🕹 方式二:通过腾讯云函数部署

*推荐没有自己服务器的用户使用。*

**注意,由于下方文档中图片文件过大,可能会出现图片加载失败的情况,点击裂掉的图片名即可跳转到新页面打开原图。**

#### 1、下载腾讯云函数版的压缩包

腾讯云函数版将与主版同步维护更新,推荐没有自己服务器的用户使用,最新版本号为`v0.4.3`下载地址:
腾讯云函数版将与主版同步维护更新,腾讯云函数和阿里云函数使用的是同一个压缩包,下载地址:
[https://github.com/luolongfei/freenom/releases/download/v0.4.3/freenom_scf.zip](https://github.com/luolongfei/freenom/releases/download/v0.4.3/freenom_scf.zip)
。本文档会在发布新版的时候同步更新此处的压缩包下载地址,所以不必担心,你看到的下载地址指向的包一定是最新版本。

下载后你将得到一个 zip 文件,将 zip 文件放到你能找到的任意目录,后面我们将以 zip 文件的形式上传到腾讯云函数。

#### 2、创建腾讯云函数

直接访问腾讯云函数控制台创建云函数: [https://console.cloud.tencent.com/scf/list-create?rid=5&ns=default&createType=empty](https://console.cloud.tencent.com/scf/list-create?rid=5&ns=default&createType=empty)
,按照下图所示的说明进行创建。如果无法看清图片,可访问: [https://github.com/luolongfei/freenom/blob/main/resources/screenshot/scf.png](https://github.com/luolongfei/freenom/blob/main/resources/screenshot/scf.png)
或者 [https://z3.ax1x.com/2021/10/14/5lMweU.png](https://z3.ax1x.com/2021/10/14/5lMweU.png) 查看原图,也可以直接点击图片查看原图。
,按照下图所示的说明进行创建。如果无法看清图片,直接点击图片即可查看原图。

[![scf01](https://z3.ax1x.com/2021/10/14/5lMweU.png)](https://z3.ax1x.com/2021/10/14/5lMweU.png)

按照上图所示部署完成后,可以点击云函数的名称进入云函数管理画面,管理画面点击函数代码,然后往下翻可看到`部署``测试`按钮,点击`测试`,稍等几秒钟,即可看到输出日志, 根据输出日志判断配置以及部署是否正确。

[![scf02](https://z3.ax1x.com/2021/10/14/5l3oHf.png)](https://z3.ax1x.com/2021/10/14/5l3oHf.png)

> 如何在腾讯云函数修改或者新增环境变量呢?
>
如果你在创建腾讯云函数的时候,某些环境变量忘记填了,或者在创建腾讯云函数后想要修改或者新增某些环境变量,可以参考这里操作,无需重建:

[![scf03](https://z3.ax1x.com/2021/11/07/I13Ku8.png)](https://imgtu.com/i/I13Ku8)
[![scf03](https://z3.ax1x.com/2021/11/07/I13Ku8.png)](https://z3.ax1x.com/2021/11/07/I13Ku8.png)

所有受支持的环境变量及其含义请参考 [.env.example](https://github.com/luolongfei/freenom/blob/main/.env.example) 文件。

> 如何在腾讯云函数更新部署的代码呢?
>
当有新版本可用时,想升级到最新版本,请按下图所示操作。更新代码包并部署后,可以点击测试查看部署是否成功。在更新完代码后,腾讯云函数编辑器里面可能会提示你同步代码,点击确定即可。

[![scf04.png](https://s4.ax1x.com/2021/12/14/ovruHf.png)](https://s4.ax1x.com/2021/12/14/ovruHf.png)

*有关腾讯云函数部署的内容结束。*

### 🚧 方式三:直接拉取源码部署
***

### 🧊 方式三:通过阿里云函数部署

*推荐没有自己服务器的用户使用。*

**注意,由于下方文档中图片文件过大,可能会出现图片加载失败的情况,点击裂掉的图片名即可跳转到新页面打开原图。**

#### 1、下载阿里云函数版的压缩包

阿里云函数版将与主版同步维护更新,阿里云函数和腾讯云函数使用的是同一个压缩包,下载地址:
[https://github.com/luolongfei/freenom/releases/download/v0.4.3/freenom_scf.zip](https://github.com/luolongfei/freenom/releases/download/v0.4.3/freenom_scf.zip)
。本文档会在发布新版的时候同步更新此处的压缩包下载地址,所以不必担心,你看到的下载地址指向的包一定是最新版本。

下载后你将得到一个 zip 文件,将 zip 文件放到你能找到的任意目录,后面我们将以 zip 文件的形式上传到阿里云函数。

#### 2、在阿里云开通云函数服务

[https://common-buy.aliyun.com/?commodityCode=fc#/buy](https://common-buy.aliyun.com/?commodityCode=fc#/buy)
可以免费开通阿里云函数服务。 详情请参考 [阿里云函数开通流程介绍](https://free.aliyun.com/product/fcfreetrial)
以及 [阿里云函数官方指南](https://help.aliyun.com/product/50980.html)

[![aliyun00.png](https://s4.ax1x.com/2021/12/14/ovCauQ.png)](https://s4.ax1x.com/2021/12/14/ovCauQ.png)

#### 3、创建服务以及创建函数

##### 3.1 创建服务

直接访问 [https://fcnext.console.aliyun.com/cn-hongkong/services](https://fcnext.console.aliyun.com/cn-hongkong/services)
,然后点击【创建服务】,地点推荐选择【香港】。此处我没有勾选【日志功能】,如果你需要【日志功能】请勾选后根据官方引导开启,否则跟下图配置一致即可。

[![aliyun01.png](https://s4.ax1x.com/2021/12/14/ovPFKg.png)](https://s4.ax1x.com/2021/12/14/ovPFKg.png)

##### 3.2 创建函数

上一步创建了服务,会跳到函数管理画面,点击创建函数,然后根据下面图示流程进行即可。

[![aliyun02.png](https://s4.ax1x.com/2021/12/14/ovinwd.png)](https://s4.ax1x.com/2021/12/14/ovinwd.png)

<hr>
[![aliyun03.png](https://s4.ax1x.com/2021/12/14/ovidkn.png)](https://s4.ax1x.com/2021/12/14/ovidkn.png)

所有操作均在Centos7系统下进行,其它Linux发行版大同小异
[![aliyun04.png](https://s4.ax1x.com/2021/12/14/ovig0J.png)](https://s4.ax1x.com/2021/12/14/ovig0J.png)

配置环境变量

[![aliyun05.png](https://s4.ax1x.com/2021/12/14/oviq7d.png)](https://s4.ax1x.com/2021/12/14/oviq7d.png)

在上图所在画面向下滚动,可以很容易找到【环境变量】的配置位置,注意此处我只示例了最简单的几个变量的配置,没有启用任何送信功能,
建议你在配置时记得启用送信功能,以掌握脚本的执行情况以及续期相关讯息。如何配置以及启用送信功能可以参考本文档的 [配置送信功能](https://github.com/luolongfei/freenom#-%E9%85%8D%E7%BD%AE%E9%80%81%E4%BF%A1%E5%8A%9F%E8%83%BD)
部分。所有受支持的环境变量及其含义请参考 [.env.example](https://github.com/luolongfei/freenom/blob/main/.env.example) 文件。

[![aliyun06.png](https://s4.ax1x.com/2021/12/14/ovFauD.png)](https://s4.ax1x.com/2021/12/14/ovFauD.png)

[![aliyun07.png](https://s4.ax1x.com/2021/12/14/ovkhQK.png)](https://s4.ax1x.com/2021/12/14/ovkhQK.png)

添加函数触发器,即计划任务。这里设置的 Cron 表达式为【CRON_TZ=Asia/Shanghai 49 24 11 * * *】,意为北京时间每天 11:24:49 执行,
**注意,执行时间一定要记得改为你自定义的时间,不要跟我这里一模一样,尽可能跟大多数人的设置不一样,否则可能出现多人在同一时间向 freenom 的服务器发起请求的情况,导致 freenom 无法稳定提供服务,影响续期操作。**

[![aliyun08.png](https://s4.ax1x.com/2021/12/14/ovAnw4.png)](https://s4.ax1x.com/2021/12/14/ovAnw4.png)

上传压缩包(在上面步骤 1 中下载得到 zip 压缩包),部署代码

[![aliyun09.png](https://s4.ax1x.com/2021/12/14/ovmKRs.png)](https://s4.ax1x.com/2021/12/14/ovmKRs.png)

[![aliyun10.png](https://s4.ax1x.com/2021/12/14/ovmDL6.png)](https://s4.ax1x.com/2021/12/14/ovmDL6.png)

由于阿里云函数默认有一个示例文件,所以此处我们上传完 zip 文件后,会提示我们是否需要同步代码,点击【是】即可

[![aliyun11.png](https://s4.ax1x.com/2021/12/14/ovmqYQ.png)](https://s4.ax1x.com/2021/12/14/ovmqYQ.png)

然后点击部署代码

[![aliyun12.png](https://s4.ax1x.com/2021/12/14/ovnn0K.png)](https://s4.ax1x.com/2021/12/14/ovnn0K.png)

【可选】 延长执行超时时间。阿里云函数默认的执行超时时间为 60 s,满足大多数人的需求。如果你的账户或者域名特别多的话,可以考虑延长它, 在【函数配置】->【环境信息】处可以编辑配置

[![aliyun13.png](https://s4.ax1x.com/2021/12/14/ovumgs.png)](https://s4.ax1x.com/2021/12/14/ovumgs.png)

> 在阿里云函数如何修改或者新增环境变量呢?
>
请参考下图操作。

[![aliyun14.png](https://s4.ax1x.com/2021/12/14/ovRKQe.png)](https://s4.ax1x.com/2021/12/14/ovRKQe.png)

> 在阿里云函数如何更新代码或者升级代码到最新版本呢?
>
参考下图,上传新的代码包后,阿里云函数编辑器可能会提示你同步代码,点击【是】即可。然后记得点击【部署】并测试。

[![aliyun15.png](https://s4.ax1x.com/2021/12/14/ovW6HA.png)](https://s4.ax1x.com/2021/12/14/ovW6HA.png)

*有关阿里云函数部署的内容结束。*

***

### 🚧 方式四:直接拉取源码部署

*所有操作均在Centos7系统下进行,其它Linux发行版大同小异*

#### 1、获取源码

Expand Down Expand Up @@ -601,6 +717,8 @@ cd /data/wwwroot/freenom/ && php run

不出意外的话,你将收到一封关于域名情况的邮件。

*有关 直接拉取源码部署 的内容结束。*

***

遇到任何问题或 Bug 欢迎提 [issue](https://github.com/luolongfei/freenom/issues) (请按模板格式提`issue`,以便我快速复现你的问题,否则问题会被忽略), 如果`Freenom`
Expand Down Expand Up @@ -649,8 +767,18 @@ cd /data/wwwroot/freenom/ && php run

##### Changed

- 解决 企业微信 因送信内容过长被截断问题

#### [v0.4.4](https://github.com/luolongfei/freenom/releases/tag/v0.4.4) - 2021-12-14

##### Changed

- 改进与 Cron 表达式验证相关的正则,兼容各种花里胡哨的表达式

##### Added

- 支持自动从 Bark url 中提取有效的 Bark key
- 支持通过 阿里云函数 部署

#### [v0.4.3](https://github.com/luolongfei/freenom/releases/tag/v0.4.3) - 2021-11-07

Expand Down
2 changes: 1 addition & 1 deletion app/Console/FreeNom.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

class FreeNom extends Base
{
const VERSION = 'v0.4.3';
const VERSION = 'v0.4.4';

const TIMEOUT = 33;

Expand Down
2 changes: 1 addition & 1 deletion app/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ function system_check()
// 如果是在云函数部署,则不需要检查这几项
if (IS_SCF) {
system_log('检测到运行环境为云函数,所有环境变量将直接从环境中读取,环境中找不到的变量,则直接从 .env.example 文件中读取');
system_log('如果是在腾讯云函数,可以参考此处修改或新增环境变量,无需重建:https://github.com/luolongfei/freenom/blob/main/resources/screenshot/scf_env_modify.png');
system_log('如果是在腾讯云函数,可以参考此处修改或新增环境变量,无需重建:https://github.com/luolongfei/freenom/blob/main/resources/screenshot/scf03.png');
system_log('如果是在阿里云函数,可以直接在【函数详情】->【函数配置】->【环境信息】处编辑环境变量');
} else {
if (!function_exists('putenv')) {
Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
ini_set('display_errors', 1);
set_time_limit(0);

define('IS_SCF', false); // 是否云函数环境
define('IS_SCF', true); // 是否云函数环境
define('IS_CLI', PHP_SAPI === 'cli');
define('DS', DIRECTORY_SEPARATOR);
define('ROOT_PATH', realpath(__DIR__));
Expand Down
4 changes: 2 additions & 2 deletions libs/MessageServices/WeChat.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct()
/**
* 获取 access_token 缓存
*
* 由于腾讯云函数环境中只有 /tmp 目录的读写权限,且每次运行结束后写入的内容不会被保留,故腾讯云函数无法真正做到通过文件缓存 access_token
* 由于云函数环境中只有 /tmp 目录的读写权限,且每次运行结束后写入的内容不会被保留,故云函数无法真正做到通过文件缓存 access_token
* 参考:https://cloud.tencent.com/document/product/583/9180
*
* @return string|null
Expand Down Expand Up @@ -285,7 +285,7 @@ public function send(string $content, string $subject = '', int $type = 1, array
'msgtype' => 'text', // 消息类型,text 类型支持 a 标签以及 \n 换行,基本满足需求。由于腾讯要求 markdown 语法必须使用 企业微信APP 才能查看,不想安装,故弃之
'agentid' => $this->agentId, // 企业应用的 ID,整型,可在应用的设置页面查看
'text' => [
'content' => $content, // 消息内容,最长不超过2048个字节,超过将截断
'content' => $content, // 消息内容,最长不超过 2048 个字节,超过将截断
],
'enable_duplicate_check' => 1,
'duplicate_check_interval' => 60,
Expand Down
Binary file added resources/screenshot/aliyun00.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/screenshot/aliyun01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/screenshot/aliyun02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/screenshot/aliyun03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/screenshot/aliyun04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/screenshot/aliyun05.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/screenshot/aliyun06.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/screenshot/aliyun07.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/screenshot/aliyun08.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/screenshot/aliyun09.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/screenshot/aliyun10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/screenshot/aliyun11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/screenshot/aliyun12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/screenshot/aliyun13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/screenshot/aliyun14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/screenshot/aliyun15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added resources/screenshot/scf02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added resources/screenshot/scf04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b6e3de8

Please sign in to comment.