Skip to content

Commit 53ef102

Browse files
committed
feat:新增文件、图片、云阶、版本信息特性
1 parent 91fe4e6 commit 53ef102

15 files changed

+583
-17
lines changed

README.md

+166-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
### 一、产品概述
77

88
- PHP通用简单小工具,简称SSU
9-
- 时间戳、云变量
9+
- 时间戳、云变量、图片访问、文件下载、版本信息管理、迷你云阶
1010
- 可用于支持PHP的云主机、云服务器、云虚拟机
11-
- 云变量可用于发卡、懒后端、慢消息队列
11+
- 云变量可用于发卡、懒后端、慢消息队列、区块链
12+
- 支持密码访问图片、密码下载文件、版本信息动态更新
13+
- 迷你云阶支持负载均衡、动静态随机、无感更新、静态云变量
1214
- 任何操作均需携带密钥操作,安全防盗用
1315
- 参数错误或操作无效时进行无感返回
1416
- PHP项目可能存在漏洞,公益项目还请手下留情(不要攻击我,可以提漏洞)
@@ -29,11 +31,15 @@
2931
- 每个功能具有单独公钥,独立配置
3032
- 公钥修改位置在app/common.php
3133

32-
### 三、数据库配置
34+
### 三、数据配置
3335

3436
- 数据库应指定为您自己的数据库,项目中所带的无法直接使用
3537
- 数据库配置位于config/database.php
3638
- 若您使用了.env,请注意您的.env配置
39+
- 文件、图片、云阶、版本信息请修改runtime文件夹下对应文件
40+
- 请勿删除example文件,它们同时也是混淆使用的默认信息
41+
- 若需要拓展则需要按照example中提供的格式修改
42+
- 云阶、版本信息等xml信息功能传参无需携带文件后缀名,文件名就是name
3743

3844
### 四、时间戳接口
3945

@@ -136,7 +142,163 @@
136142
1
137143
```
138144
139-
### 六、错误代码
145+
### 六、图片访问
146+
147+
> /picture/get
148+
149+
- 接口说明:携带密码访问图片
150+
- 请求方式:get
151+
- 请求参数
152+
```
153+
注意! 所有参数必传
154+
key: 图片功能公钥
155+
name: 图片文件全名(带后缀名,目标文件在runtime/picture文件夹)
156+
```
157+
- 返回类型:file
158+
159+
- 返回示例:
160+
```
161+
直接显示图片
162+
```
163+
164+
### 七、文件下载
165+
166+
> /file/get
167+
168+
- 接口说明:携带密码下载文件
169+
- 请求方式:get
170+
- 请求参数
171+
```
172+
注意! 所有参数必传
173+
key: 文件功能公钥
174+
name: 文件全名称(带后缀名,目标文件在runtime/file文件夹)
175+
```
176+
- 返回类型:file
177+
178+
- 返回示例:
179+
```
180+
直接下载文件
181+
```
182+
183+
### 八、版本信息管理
184+
185+
> /version/all
186+
187+
- 接口说明:获取指定产品的版本信息
188+
- 请求方式:get
189+
- 请求参数
190+
```
191+
注意! 所有参数必传
192+
key: 版本功能公钥
193+
name: 要获得的版本信息(不带后缀名,信息存放在runtime/version文件夹)
194+
```
195+
- 返回类型:json
196+
197+
- 返回示例:
198+
```
199+
{
200+
"versionInfo": {
201+
"name": {
202+
"zh-cn": "简单小软件",
203+
"en": "SimpleSmallUtil"
204+
},
205+
"description": {
206+
"zh-cn": "PHP通用简单小工具",
207+
"en": "PHP universal simple gadget."
208+
},
209+
"icon": "https://s2.loli.net/2025/02/28/xMY7QVAfa4sIyrJ.jpg",
210+
"lastest": "1.0.20250309",
211+
"tags": {
212+
"tag": [
213+
"办公软件",
214+
"开发者工具"
215+
]
216+
},
217+
"platforms": {
218+
"platform": "全平台"
219+
},
220+
"architectures": {
221+
"architecture": [
222+
"x86",
223+
"x64"
224+
]
225+
},
226+
"extends": {},
227+
"versions": {
228+
"version": [
229+
{
230+
"number": "1.0.20250228",
231+
"releaseDate": "2025-02-28",
232+
"features": {
233+
"feature": [
234+
"初始版本发布",
235+
"基本功能实现"
236+
]
237+
},
238+
"Links": {
239+
"Link": [
240+
"https://www.mutantcat.org/software/simplesmallutil",
241+
"https://pan.baidu.com/share/init?surl=2DCvhlz5NhQpWiZS0Z3nBA&pwd=nu2w",
242+
"https://shuntaoyuan.lanzout.com/ioCrb2p54hdc",
243+
"https://github.com/Mutantcat-Working-Group/SimpleSmallUtil/releases/tag/v1.0.20250228"
244+
]
245+
},
246+
"extends": {}
247+
},
248+
{
249+
"number": "1.0.20250309",
250+
"releaseDate": "2025-08-09",
251+
"features": {
252+
"feature": "新增图片、版本、文件、云阶"
253+
},
254+
"Links": {
255+
"Link": "https://www.mutantcat.org/software/simplesmallutil"
256+
},
257+
"extends": {}
258+
}
259+
]
260+
}
261+
}
262+
}
263+
```
264+
265+
> /version/lastest
266+
267+
- 接口说明:获取指定产品的最新版本号
268+
- 请求方式:get
269+
- 请求参数
270+
```
271+
注意! 所有参数必传
272+
key: 版本功能公钥
273+
name: 要获得的版本信息(不带后缀名,信息存放在runtime/version文件夹)
274+
```
275+
- 返回类型:string
276+
277+
- 返回示例:
278+
```
279+
1.0.20250309
280+
```
281+
282+
### 九、迷你云阶
283+
284+
> /cloudstep/get
285+
286+
- 接口说明:以云阶的方式获取数据
287+
- 请求方式:get
288+
- 请求参数
289+
```
290+
注意! 所有参数必传
291+
key: 迷你云阶功能公钥
292+
name: 要获得的版本信息(不带后缀名,信息存放在runtime/cloudstep文件夹)
293+
```
294+
- 返回类型:string
295+
296+
- 返回示例:
297+
```
298+
mutantcat
299+
```
300+
301+
### 十、错误代码
140302
141303
- `-2`: 事务执行失败
142304

app/common.php

+31-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,38 @@
22
// 应用公共文件
33

44
// 配置公钥
5+
6+
// 时间戳公钥
57
if (!defined('TIME_PUBLIC_KEY')) {
6-
define('TIME_PUBLIC_KEY', 'ttt-mutantcat-TTT');
8+
define('TIME_PUBLIC_KEY', 'mutantcat');
79
}
10+
11+
// 云变量公钥
812
if (!defined('VALUE_PUBLIC_KEY')) {
9-
define('VALUE_PUBLIC_KEY', 'm8u8t8a8n8t8c8a8t');
13+
define('VALUE_PUBLIC_KEY', 'mutantcat');
14+
}
15+
16+
// 图片公钥
17+
if (!defined('PICTURE_PUBLIC_KEY')) {
18+
define('PICTURE_PUBLIC_KEY', 'mutantcat');
19+
}
20+
21+
// 文件公钥
22+
if (!defined('FILE_PUBLIC_KEY')) {
23+
define('FILE_PUBLIC_KEY', 'mutantcat');
24+
}
25+
26+
// 版本公钥
27+
if (!defined('VERSION_PUBLIC_KEY')) {
28+
define('VERSION_PUBLIC_KEY', 'mutantcat');
29+
}
30+
31+
// 文件公钥
32+
if (!defined('FILE_PUBLIC_KEY')) {
33+
define('FILE_PUBLIC_KEY', 'mutantcat');
34+
}
35+
36+
// 云阶公钥
37+
if (!defined('CLOUDSTEP_PUBLIC_KEY')) {
38+
define('CLOUDSTEP_PUBLIC_KEY', 'mutantcat');
1039
}

app/controller/Index.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Index extends BaseController
88
{
99
public function index()
1010
{
11-
return '用于简单小工具(SSU)的请求接口';
11+
return 'Welcome,SimpleSmallUtil.xml(SSU),mutantcat.org';
1212
}
1313

1414
public function ping(){
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace app\controller\cloudstep;
4+
5+
class CloudStep
6+
{
7+
public function index()
8+
{
9+
return 'mutantcat.org';
10+
}
11+
12+
public function getCloudStep()
13+
{
14+
$rootPath = dirname(__DIR__, 3); // 项目根路径
15+
$public_key = input('get.key'); // 从GET请求中获取密钥
16+
$filename = input('get.name'); // 从GET请求中获取文件名
17+
18+
if ($public_key != CLOUDSTEP_PUBLIC_KEY) {
19+
$filePath = $rootPath . '/runtime/cloudstep/example_cloudstep.xml';
20+
}else if (!$filename) {
21+
$filePath = $rootPath . '/runtime/cloudstep/example_cloudstep.xml';
22+
} else {
23+
$filePath = $rootPath . '/runtime/cloudstep/' . $filename . '.xml';
24+
}
25+
26+
// 验证文件是否存在且路径合法
27+
if (!file_exists($filePath) || strpos(realpath($filePath), realpath($rootPath . '/runtime/cloudstep/')) !== 0) {
28+
$filePath = $rootPath . '/runtime/cloudstep/example_cloudstep.xml';
29+
}
30+
31+
// 读取并解析 XML 文件
32+
try {
33+
// 将 XML 文件加载为 PHP 对象
34+
$xmlObject = simplexml_load_file($filePath);
35+
36+
switch ($xmlObject->mode){
37+
case "random":
38+
// 先获得targets的数量
39+
$targetCount = count($xmlObject->targets->target);
40+
// 随机选择一个
41+
$randomIndex = rand(0, $targetCount - 1);
42+
return $xmlObject->targets->target[$randomIndex];
43+
break;
44+
default:
45+
return "-1";
46+
}
47+
} catch (\Exception $e) {
48+
// 处理解析错误
49+
return "-1";
50+
}
51+
}
52+
}

app/controller/file/FileGetter.php

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace app\controller\file;
4+
5+
class FileGetter
6+
{
7+
public function index()
8+
{
9+
return 'mutantcat.org';
10+
}
11+
12+
public function getFile()
13+
{
14+
$rootPath = dirname(__DIR__, 3); // 项目根路径
15+
$public_key = input('get.key'); // 从GET请求中获取密钥
16+
$filename = input('get.name'); // 从GET请求中获取文件名
17+
18+
// 验证密钥
19+
if ($public_key != FILE_PUBLIC_KEY) {
20+
$filePath = $rootPath . '/runtime/file/example_file.txt';
21+
}else if (!$filename) {
22+
$filePath = $rootPath . '/runtime/file/example_file.txt';
23+
} else {
24+
$filePath = $rootPath . '/runtime/file/' . $filename;
25+
}
26+
// 验证文件是否存在且路径合法
27+
if (!file_exists($filePath) || strpos(realpath($filePath), realpath($rootPath . '/runtime/file/')) !== 0) {
28+
$filePath = $rootPath . '/runtime/file/example_file.txt';
29+
}
30+
31+
// 获取文件的 MIME 类型并设置响应头
32+
$fileInfo = mime_content_type($filePath);
33+
header("Content-Type: $fileInfo");
34+
35+
// 设置下载头,指定下载文件名
36+
header("Content-Disposition: attachment; filename=" . basename($filePath));
37+
header("Content-Length: " . filesize($filePath));
38+
39+
// 输出文件内容
40+
readfile($filePath);
41+
42+
// 终止脚本执行
43+
exit;
44+
}
45+
}
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace app\controller\picture;
4+
5+
include dirname(__DIR__, 2) . '/common.php';
6+
7+
8+
class PictureGetter
9+
{
10+
public function index()
11+
{
12+
return 'mutantcat.org';
13+
}
14+
15+
public function getPicture()
16+
{
17+
$rootPath = dirname(__DIR__, 3);
18+
$public_key = input('get.key');
19+
$filename = input('get.name');
20+
21+
// 不可缺少 缺少返回example图片
22+
if ($public_key != PICTURE_PUBLIC_KEY) {
23+
$filePath = $rootPath . '/runtime/picture/example_picture.jpg';
24+
} else if (!$filename) {
25+
$filePath = $rootPath . '/runtime/picture/example_picture.jpg';
26+
} else {
27+
$filePath = $rootPath . '/runtime/picture/' . $filename;
28+
}
29+
30+
// 验证文件是否存在且是否为安全路径
31+
if (!file_exists($filePath) || strpos(realpath($filePath), realpath($rootPath . '/runtime/picture/')) !== 0) {
32+
$filePath = $rootPath . '/runtime/picture/example_picture.jpg';
33+
}
34+
35+
// 获取文件的 MIME 类型并设置响应头
36+
$fileInfo = mime_content_type($filePath);
37+
header("Content-Type: $fileInfo");
38+
39+
// 设置文件为可下载(可选)
40+
// header("Content-Disposition: attachment; filename=" . basename($filePath));
41+
42+
// 输出文件内容
43+
readfile($filePath);
44+
45+
// 终止脚本执行
46+
exit;
47+
}
48+
49+
}

0 commit comments

Comments
 (0)