Skip to content

Commit

Permalink
增加密码提示接口
Browse files Browse the repository at this point in the history
  • Loading branch information
limingxinleo committed Jan 5, 2024
1 parent 959d4fb commit 91ba3cd
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 私密空间-接口服务
# 我的隐私空间-接口服务

## 教程视频

Expand Down
9 changes: 9 additions & 0 deletions app/Controller/SecretController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,13 @@ public function check(SwaggerRequest $request)

return $this->response->success($result);
}

#[SA\Get('/secret/message', summary: '密码提示', tags: ['密码管理'])]
#[SA\Response(response: '200', content: new SA\JsonContent(ref: '#/components/schemas/MessageSchema'))]
public function message()
{
return $this->response->success(
$this->service->message()
);
}
}
34 changes: 34 additions & 0 deletions app/Schema/MessageSchema.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/

namespace App\Schema;

use Hyperf\Swagger\Annotation\Property;
use Hyperf\Swagger\Annotation\Schema;
use JsonSerializable;

#[Schema(title: '消息数据')]
class MessageSchema implements JsonSerializable
{
public function __construct(
#[Property(property: 'message', title: '消息内容', type: 'string')]
public string $message
) {
}

public function jsonSerialize(): mixed
{
return [
'message' => $this->message,
];
}
}
6 changes: 6 additions & 0 deletions app/Service/SecretService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use App\Constants\ErrorCode;
use App\Exception\BusinessException;
use App\Schema\MessageSchema;
use App\Schema\SecretSchema;
use App\Service\Dao\SecretDao;
use App\Service\SubService\UserAuth;
Expand Down Expand Up @@ -43,4 +44,9 @@ public function check(string $secret, int $userId): SecretSchema

return new SecretSchema($model);
}

public function message(): MessageSchema
{
return new MessageSchema('输入密钥,解锁内容。所有密钥和内容都会加密存储,不会泄露任何数据。没有提前设置密钥,可以点击右下角的+号,新增密钥。');
}
}
2 changes: 1 addition & 1 deletion storage/swagger/http.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"openapi":"3.0.0","paths":{"\/content\/save":{"post":{"tags":["内容管理"],"summary":"创建内容","operationId":"a78b24e177cb54b1c1a9855d6f04ba53","requestBody":{"content":{"application\/json":{"schema":{"properties":{"id":{"description":"内容 ID","type":"integer","rules":"required|integer","attribute":null},"secret_id":{"description":"密码 ID","type":"integer","rules":"required|integer","attribute":null},"title":{"description":"标题","type":"string","rules":"required|string","attribute":null},"content":{"description":"内容","type":"string","rules":"required|string","attribute":null},"type":{"description":"类型 0 文本 1 音频 2 视频","type":"integer","rules":"integer","attribute":null}},"type":"object"}}},"_content":{"properties":{"id":{"description":"内容 ID","type":"integer","rules":"required|integer","attribute":null},"secret_id":{"description":"密码 ID","type":"integer","rules":"required|integer","attribute":null},"title":{"description":"标题","type":"string","rules":"required|string","attribute":null},"content":{"description":"内容","type":"string","rules":"required|string","attribute":null},"type":{"description":"类型 0 文本 1 音频 2 视频","type":"integer","rules":"integer","attribute":null}},"type":"object"}},"responses":{"200":{"content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/SavedSchema"}}}}}}},"\/content\/list":{"get":{"tags":["内容管理"],"summary":"内容列表","operationId":"18f900c225e9137df5c8f04b5f9cbb0b","requestBody":{"content":{"application\/json":{"schema":{"properties":{"secret_id":{"description":"密码 ID","type":"integer","rules":"required|integer","attribute":null}},"type":"object"}}},"_content":{"properties":{"secret_id":{"description":"密码 ID","type":"integer","rules":"required|integer","attribute":null}},"type":"object"}},"responses":{"200":{"content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/ContentListSchema"}}}}}}},"\/content\/info":{"get":{"tags":["内容管理"],"summary":"内容详情","operationId":"a8a058393085c920c33af03e92b3e7b1","requestBody":{"content":{"application\/json":{"schema":{"properties":{"id":{"description":"内容 ID","type":"integer","rules":"required|integer","attribute":null}},"type":"object"}}},"_content":{"properties":{"id":{"description":"内容 ID","type":"integer","rules":"required|integer","attribute":null}},"type":"object"}},"responses":{"200":{"content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/ContentSchema"}}}}}}},"\/login":{"post":{"tags":["注册登录"],"summary":"小程序登录","operationId":"af704524b829a3c6cea821006f70e2b0","requestBody":{"content":{"application\/json":{"schema":{"properties":{"code":{"description":"微信授权码","type":"string","rules":"required|string","attribute":null}},"type":"object"}}},"_content":{"properties":{"code":{"description":"微信授权码","type":"string","rules":"required|string","attribute":null}},"type":"object"}},"responses":{"200":{"content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/LoginSchema"}}}}}}},"\/secret\/create":{"post":{"tags":["密码管理"],"summary":"创建密码","operationId":"27217b189e2bb645206816f6fd7bb30d","requestBody":{"content":{"application\/json":{"schema":{"properties":{"secret":{"description":"密码","type":"string","rules":"required|string","attribute":null}},"type":"object"}}},"_content":{"properties":{"secret":{"description":"密码","type":"string","rules":"required|string","attribute":null}},"type":"object"}},"responses":{"200":{"content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/SavedSchema"}}}}}}},"\/secret\/check":{"post":{"tags":["密码管理"],"summary":"验证密码","operationId":"d5a3412a21c72fb0ee41e2361d1e91c5","requestBody":{"content":{"application\/json":{"schema":{"properties":{"secret":{"description":"密码","type":"string","rules":"required|string","attribute":null}},"type":"object"}}},"_content":{"properties":{"secret":{"description":"密码","type":"string","rules":"required|string","attribute":null}},"type":"object"}},"responses":{"200":{"content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/SecretSchema"}}}}}}},"\/user\/info":{"get":{"tags":["注册登录"],"summary":"用户信息","operationId":"c39dc625b20bc8ec41aeb09f2b7a98a0","responses":{"200":{"content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/UserSchema"}}}}}}}},"components":{"schemas":{"ContentListSchema":{"title":"内容列表","properties":{"list":{"title":"列表","type":"array","items":{"$ref":"#\/components\/schemas\/ContentSchema"},"rules":null,"attribute":null},"count":{"title":"总数","type":"integer","rules":null,"attribute":null}},"type":"object"},"ContentSchema":{"title":"内容详情","properties":{"id":{"title":"","type":"integer","rules":null,"attribute":null},"user_id":{"title":"用户 ID","type":"integer","rules":null,"attribute":null},"secret_id":{"title":"密码 ID","type":"integer","rules":null,"attribute":null},"title":{"title":"标题","type":"string","rules":null,"attribute":null},"content":{"title":"内容","type":"string","rules":null,"attribute":null},"type":{"title":"类型 0 文本 1 音频 2 视频","type":"integer","rules":null,"attribute":null},"created_at":{"title":"","type":"mixed","rules":null,"attribute":null},"updated_at":{"title":"","type":"mixed","rules":null,"attribute":null}},"type":"object"},"LoginSchema":{"title":"LoginSchema","properties":{"token":{"title":"Token","type":"string","rules":null,"attribute":null}},"type":"object"},"SavedSchema":{"title":"SavedSchema","properties":{"saved":{"title":"是否保存成功","type":"boolean","rules":null,"attribute":null}},"type":"object"},"SecretSchema":{"title":"密码详情","properties":{"id":{"title":"","type":"integer","rules":null,"attribute":null},"user_id":{"title":"用户 ID","type":"integer","rules":null,"attribute":null},"created_at":{"title":"","type":"mixed","rules":null,"attribute":null},"updated_at":{"title":"","type":"mixed","rules":null,"attribute":null}},"type":"object"},"UserSchema":{"title":"用户详情","properties":{"id":{"title":"","type":"integer","rules":null,"attribute":null},"openid":{"title":"小程序 OpenID","type":"string","rules":null,"attribute":null},"has_secret":{"title":"是否已经创建过密码","type":"boolean","rules":null,"attribute":null},"created_at":{"title":"","type":"string","rules":null,"attribute":null},"updated_at":{"title":"","type":"string","rules":null,"attribute":null}},"type":"object"}}}}
{"openapi":"3.0.0","paths":{"\/content\/save":{"post":{"tags":["内容管理"],"summary":"创建内容","operationId":"a78b24e177cb54b1c1a9855d6f04ba53","requestBody":{"content":{"application\/json":{"schema":{"properties":{"id":{"description":"内容 ID","type":"integer","rules":"required|integer","attribute":null},"secret_id":{"description":"密码 ID","type":"integer","rules":"required|integer","attribute":null},"title":{"description":"标题","type":"string","rules":"required|string","attribute":null},"content":{"description":"内容","type":"string","rules":"required|string","attribute":null},"type":{"description":"类型 0 文本 1 音频 2 视频 3 图片","type":"integer","rules":"integer","attribute":null}},"type":"object"}}},"_content":{"properties":{"id":{"description":"内容 ID","type":"integer","rules":"required|integer","attribute":null},"secret_id":{"description":"密码 ID","type":"integer","rules":"required|integer","attribute":null},"title":{"description":"标题","type":"string","rules":"required|string","attribute":null},"content":{"description":"内容","type":"string","rules":"required|string","attribute":null},"type":{"description":"类型 0 文本 1 音频 2 视频 3 图片","type":"integer","rules":"integer","attribute":null}},"type":"object"}},"responses":{"200":{"content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/SavedSchema"}}}}}}},"\/content\/list":{"get":{"tags":["内容管理"],"summary":"内容列表","operationId":"18f900c225e9137df5c8f04b5f9cbb0b","requestBody":{"content":{"application\/json":{"schema":{"properties":{"secret_id":{"description":"密码 ID","type":"integer","rules":"required|integer","attribute":null}},"type":"object"}}},"_content":{"properties":{"secret_id":{"description":"密码 ID","type":"integer","rules":"required|integer","attribute":null}},"type":"object"}},"responses":{"200":{"content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/ContentListSchema"}}}}}}},"\/content\/info":{"get":{"tags":["内容管理"],"summary":"内容详情","operationId":"a8a058393085c920c33af03e92b3e7b1","requestBody":{"content":{"application\/json":{"schema":{"properties":{"id":{"description":"内容 ID","type":"integer","rules":"required|integer","attribute":null}},"type":"object"}}},"_content":{"properties":{"id":{"description":"内容 ID","type":"integer","rules":"required|integer","attribute":null}},"type":"object"}},"responses":{"200":{"content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/ContentSchema"}}}}}}},"\/login":{"post":{"tags":["注册登录"],"summary":"小程序登录","operationId":"af704524b829a3c6cea821006f70e2b0","requestBody":{"content":{"application\/json":{"schema":{"properties":{"code":{"description":"微信授权码","type":"string","rules":"required|string","attribute":null}},"type":"object"}}},"_content":{"properties":{"code":{"description":"微信授权码","type":"string","rules":"required|string","attribute":null}},"type":"object"}},"responses":{"200":{"content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/LoginSchema"}}}}}}},"\/secret\/create":{"post":{"tags":["密码管理"],"summary":"创建密码","operationId":"27217b189e2bb645206816f6fd7bb30d","requestBody":{"content":{"application\/json":{"schema":{"properties":{"secret":{"description":"密码","type":"string","rules":"required|string","attribute":null}},"type":"object"}}},"_content":{"properties":{"secret":{"description":"密码","type":"string","rules":"required|string","attribute":null}},"type":"object"}},"responses":{"200":{"content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/SavedSchema"}}}}}}},"\/secret\/check":{"post":{"tags":["密码管理"],"summary":"验证密码","operationId":"d5a3412a21c72fb0ee41e2361d1e91c5","requestBody":{"content":{"application\/json":{"schema":{"properties":{"secret":{"description":"密码","type":"string","rules":"required|string","attribute":null}},"type":"object"}}},"_content":{"properties":{"secret":{"description":"密码","type":"string","rules":"required|string","attribute":null}},"type":"object"}},"responses":{"200":{"content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/SecretSchema"}}}}}}},"\/secret\/message":{"get":{"tags":["密码管理"],"summary":"密码提示","operationId":"f78ffe669ecbf2f55d12dd2c977c6c40","responses":{"200":{"content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/MessageSchema"}}}}}}},"\/user\/info":{"get":{"tags":["注册登录"],"summary":"用户信息","operationId":"c39dc625b20bc8ec41aeb09f2b7a98a0","responses":{"200":{"content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/UserSchema"}}}}}}}},"components":{"schemas":{"ContentListSchema":{"title":"内容列表","properties":{"list":{"title":"列表","type":"array","items":{"$ref":"#\/components\/schemas\/ContentSchema"},"rules":null,"attribute":null},"count":{"title":"总数","type":"integer","rules":null,"attribute":null}},"type":"object"},"ContentSchema":{"title":"内容详情","properties":{"id":{"title":"","type":"integer","rules":null,"attribute":null},"user_id":{"title":"用户 ID","type":"integer","rules":null,"attribute":null},"secret_id":{"title":"密码 ID","type":"integer","rules":null,"attribute":null},"title":{"title":"标题","type":"string","rules":null,"attribute":null},"content":{"title":"内容","type":"string","rules":null,"attribute":null},"type":{"title":"类型 0 文本 1 音频 2 视频","type":"integer","rules":null,"attribute":null},"created_at":{"title":"","type":"mixed","rules":null,"attribute":null},"updated_at":{"title":"","type":"mixed","rules":null,"attribute":null}},"type":"object"},"LoginSchema":{"title":"LoginSchema","properties":{"token":{"title":"Token","type":"string","rules":null,"attribute":null}},"type":"object"},"MessageSchema":{"title":"消息数据","properties":{"message":{"title":"消息内容","type":"string","rules":null,"attribute":null}},"type":"object"},"SavedSchema":{"title":"SavedSchema","properties":{"saved":{"title":"是否保存成功","type":"boolean","rules":null,"attribute":null}},"type":"object"},"SecretSchema":{"title":"密码详情","properties":{"id":{"title":"","type":"integer","rules":null,"attribute":null},"user_id":{"title":"用户 ID","type":"integer","rules":null,"attribute":null},"created_at":{"title":"","type":"mixed","rules":null,"attribute":null},"updated_at":{"title":"","type":"mixed","rules":null,"attribute":null}},"type":"object"},"UserSchema":{"title":"用户详情","properties":{"id":{"title":"","type":"integer","rules":null,"attribute":null},"openid":{"title":"小程序 OpenID","type":"string","rules":null,"attribute":null},"has_secret":{"title":"是否已经创建过密码","type":"boolean","rules":null,"attribute":null},"created_at":{"title":"","type":"string","rules":null,"attribute":null},"updated_at":{"title":"","type":"string","rules":null,"attribute":null}},"type":"object"}}}}
10 changes: 10 additions & 0 deletions test/Cases/SecretTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use App\Model\Secret;
use App\Service\SubService\UserAuth;
use HyperfTest\HttpTestCase;
use PHPUnit\Framework\Attributes\WithoutErrorHandler;

/**
* @internal
Expand Down Expand Up @@ -45,4 +46,13 @@ public function testSecretCheck()

$this->assertSame(0, $res['code']);
}

public function testSecretMessage()
{
$res = $this->get('/secret/message', [], [
UserAuth::X_TOKEN => self::$token,
]);

$this->assertSame(0, $res['code']);
}
}

0 comments on commit 91ba3cd

Please sign in to comment.