diff --git a/doc/api.md b/doc/api.md deleted file mode 100644 index 163f668..0000000 --- a/doc/api.md +++ /dev/null @@ -1,51 +0,0 @@ -# auth-api - -## 登录 - -### 发起登录 -`GET https://auth.yiwen.ai/idp/:idp/authorize?next_url=encodedUrl` - -其中 `idp` 为登录服务提供方,如 `github`, `google`, `wechat`。 - -`encodedUrl` 为可选参数,登录成功后会重定向到该地址,默认为 `https://www.yiwen.ai/login/state`。若提供,其域名必须为白名单中的域名。 - -例如通过 github Oauth2 登录: -``` -GET https://auth.yiwen.ai/idp/github/authorize -``` - -登录成功后,重定向 url 会追加 `status=200` 的参数,如重定向到: -``` -https://www.yiwen.ai/login/state?status=200 -``` - -登录失败时,重定向 url 会追加 `status` 和 `x-request-id` 参数,其中 `status` 为 4xx 或 5xx 的 http 状态码,`x-request-id` 可用于定位详细错误,如重定向到: -``` -https://www.yiwen.ai/login/state?status=403&x-request-id=xxxxxxx -``` - -### 登录成功获取用户信息 -`GET https://auth.yiwen.ai/userinfo` - -返回数据: -```json -{ - "cn": "clmby76knvc", // 用户名,全局唯一,但用户可以修改 - "name": "0xZensh", // 用户昵称 - "locale": "zho", // 用户默认语言 - "picture": "https://cdn.yiwen.pub/dev/pic/L3J7GFPpLLwapz0UF7H8wQ", - "status":0 // 用户状态,-2: Disabled -1: Suspended, 0: Normal, 1: Verified, 2: Protected -} -``` - -### 登录成功获取 access_token -`GET https://auth.yiwen.ai/access_token` - -返回数据: -```json -{ - "sub": "2f727b18-53e9-2cbc-1aa7-3d1417b1fcc1", // 用户在应用主体下的永久唯一标识,不同应用主体下 sub 不同 - "access_token": "hE2iAScESDIwM...YymcaaKQL8K", // access_token,用于 API 调用 - "expires_in": 3600 // 有效期 1 小时 -} -``` diff --git a/doc/yiwen-api.md b/doc/yiwen-api.md new file mode 100644 index 0000000..e450d53 --- /dev/null +++ b/doc/yiwen-api.md @@ -0,0 +1,35 @@ +# yiwen-api + +## 读取网页 + +`GET https://api.yiwen.ltd/v1/scraping?url=encodedUrl` + +示例: +``` +GET https://api.yiwen.ltd/v1/scraping?url=https%3A%2F%2Fmp.weixin.qq.com%2Fs%2F6iCpGzsqnXcGZPoEhqJE4Q +Accept: application/json +Cookie: YW_DID=ciqui8xxxx; YW_SESS=HFmzbngWbxxxxxWAkAk +Authorization: Bearer hE2iAScESDIxxxxxxxeCMK +``` + +返回: +```json +{ + "retry": 0, + "result": { + "id": "cis0vcgcert0052hqvbg", + "url": "https://mp.weixin.qq.com/s/6iCpGzsqnXcGZPoEhqJE4Q", + "src": "", + "title": "网络平台提供代币充值服务合规要点——以抖音抖币充值为例", + "meta": { + "og:article:author": "夏梦雅团队", + "og:description": "本文共4803字,预计阅读时长为20分钟", + "og:image": "https://mmbiz.qpic.cn/mmbiz_jpg/qjp6a5pznC2zfliaqxET0c8bia4gicA3BnMIb5dCNwGKTvTJPSpaicc4Ht920xH7MJlH9cLPA2RibcPyms1bjZ4g8GA/0?wx_fmt=jpeg", + "og:site_name": "Weixin Official Accounts Platform", + "og:type": "article", + "og:url": "http://mp.weixin.qq.com/s?__biz=MzU2NzgzODEzMw==\u0026mid=2247485848\u0026idx=1\u0026sn=f7dd03a96e23d92dff462f754d528a70\u0026chksm=fc965d42cbe1d45473de15cb435468bb97d106f3d4f3a980fb9a0067aeee07ec0e80e1ab1449#rd" + }, + "content": "WVqUuQACZHR5cGVjZG9jZ2Nvb...base64_url_raw_encode_cbor...5ZCI6KeE6KaB54K54oCU4oCU" + } +} +``` diff --git a/doc/yiwen-api.yml b/doc/yiwen-api.yml new file mode 100644 index 0000000..90f1c8f --- /dev/null +++ b/doc/yiwen-api.yml @@ -0,0 +1,103 @@ +openapi: '3.0.1' +info: + title: Yiwen-API + version: 'v1' +servers: + - url: https://api.yiwen.ltd +tags: + - name: Scraping + description: 读取 web 文章内容 + - name: Creation + description: 草稿、稿件 + - name: Publication + description: 作品、出版物 +components: + securitySchemes: + CookieSession: + name: Session + type: apiKey + in: cookie + HeaderAuthorizationCWT: + type: http + scheme: bearer + bearerFormat: CWT + parameters: + QueryEncodedUrl: + name: url + in: query + required: true + description: '' + schema: + type: string + schemas: + ScrapingDocument: + type: object + properties: + id: + type: string + format: byte + description: Xid 对象,scraping id + url: + type: string + description: 经过服务器处理的 url + src: + type: string + description: 用户原始输入的 url + title: + type: string + description: 从 web 读取到的文章标题 + meta: + type: object + description: 从 web 读取到的文章元数据,一般以 `og:` 为前缀 + content: + type: string + format: byte + description: CBOR 格式的文章内容 + responses: + ErrorResponse: + description: 标准错误返回结果 + content: + application/json: + schema: + type: object + properties: + error: + type: string + description: 错误代号 + example: NotFound + message: + type: string + description: 错误详情 + example: some thing not found + ScrapingResponse: + description: 读取 web 文章的返回结果 + content: + application/cbor: + schema: + type: object + properties: + result: + type: object + $ref: '#/components/schemas/ScrapingDocument' + application/json: + schema: + type: object + properties: + result: + type: object + $ref: '#/components/schemas/ScrapingDocument' +paths: + /v1/scraping: + get: + tags: + - Scraping + summary: 获取指定 url 文章内容。 + security: + - CookieSession: [] + - HeaderAuthorizationCWT: [] + parameters: + - $ref: '#/components/parameters/QueryEncodedUrl' + responses: + '200': + description: OK + $ref: '#/components/responses/ScrapingResponse'