diff --git a/README.md b/README.md index e9799f1..3013902 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ ZhipuAI (智谱清言) 接口转API [glm-free-api](https://github.com/LLM-Red-Te * [AI绘图](#AI绘图) * [文档解读](#文档解读) * [图像解析](#图像解析) + * [login_tongyi_ticket存活检测](#login_tongyi_ticket存活检测) * [注意事项](#注意事项) * [Nginx反代优化](#Nginx反代优化) @@ -52,23 +53,23 @@ https://udify.app/chat/qOXzVl5kkvhQXM8r ## 效果示例 -### 验明正身 +### 验明正身Demo ![验明正身](./doc/example-1.png) -### 多轮对话 +### 多轮对话Demo ![多轮对话](./doc/example-2.png) -### AI绘图 +### AI绘图Demo ![AI绘图](./doc/example-3.png) -### 长文档解读 +### 长文档解读Demo ![AI绘图](./doc/example-5.png) -### 图像解析 +### 图像解析Demo ![AI绘图](./doc/example-6.png) @@ -398,6 +399,26 @@ Authorization: Bearer [refresh_token] } ``` +### login_tongyi_ticket存活检测 + +检测login_tongyi_ticket是否存活,如果存活live未true,否则为false,请不要频繁(小于10分钟)调用此接口。 + +**POST /token/check** + +请求数据: +```json +{ + "token": "QIhaHrrXUaIrWMUmL..." +} +``` + +响应数据: +```json +{ + "live": true +} +``` + ## 注意事项 ### Nginx反代优化 diff --git a/src/api/controllers/chat.ts b/src/api/controllers/chat.ts index cf4079e..ed3b45a 100644 --- a/src/api/controllers/chat.ts +++ b/src/api/controllers/chat.ts @@ -897,9 +897,35 @@ function generateCookie(ticket: string) { ].join("; "); } +/** + * 获取Token存活状态 + */ +async function getTokenLiveStatus(ticket: string) { + const result = await axios.post( + "https://qianwen.biz.aliyun.com/dialog/session/list", + {}, + { + headers: { + Cookie: generateCookie(ticket), + ...FAKE_HEADERS, + }, + timeout: 15000, + validateStatus: () => true, + } + ); + try { + const { data } = checkResult(result); + return _.isArray(data); + } + catch(err) { + return false; + } +} + export default { createCompletion, createCompletionStream, generateImages, + getTokenLiveStatus, tokenSplit, }; diff --git a/src/api/routes/index.ts b/src/api/routes/index.ts index 706525a..cc1ac33 100644 --- a/src/api/routes/index.ts +++ b/src/api/routes/index.ts @@ -4,6 +4,7 @@ import Response from '@/lib/response/Response.ts'; import chat from "./chat.ts"; import images from "./images.ts"; import ping from "./ping.ts"; +import token from './token.ts'; export default [ { @@ -21,5 +22,6 @@ export default [ }, chat, images, - ping + ping, + token ]; \ No newline at end of file diff --git a/src/api/routes/token.ts b/src/api/routes/token.ts new file mode 100644 index 0000000..c69c512 --- /dev/null +++ b/src/api/routes/token.ts @@ -0,0 +1,25 @@ +import _ from 'lodash'; + +import Request from '@/lib/request/Request.ts'; +import Response from '@/lib/response/Response.ts'; +import chat from '@/api/controllers/chat.ts'; +import logger from '@/lib/logger.ts'; + +export default { + + prefix: '/token', + + post: { + + '/check': async (request: Request) => { + request + .validate('body.token', _.isString) + const live = await chat.getTokenLiveStatus(request.body.token); + return { + live + } + } + + } + +} \ No newline at end of file