Your Name 1 سال پیش
والد
کامیت
c56490c72c
5فایلهای تغییر یافته به همراه81 افزوده شده و 10 حذف شده
  1. 5 2
      config.py
  2. 27 5
      main.py
  3. 21 2
      readme.md
  4. 2 1
      static/index.html
  5. 26 0
      待办事项.md

+ 5 - 2
config.py

@@ -5,5 +5,8 @@ import socket
 os.environ["CLIENT_KEY"] = 'aw6aipmfdtplwtyq'
 os.environ["CLIENT_SECRET"] = '53cf3dcd2663629e8a773ab59df0968b'
 
-HOST = socket.gethostbyname(socket.gethostname())
-PORT = 18888
+# HOST = socket.gethostbyname(socket.gethostname())
+# 这个网址 https://open-douyin.magong.site 对应这台服务器的 192.168.1.32:8600 端口,因为这台服务器没有公网ip,所以在本地计算机无法通过  http://192.168.1.32:8600/ 访问到 fastapi 接口,只能通过 https://open-douyin.magong.site/ 访问
+HOST = '::'
+PORT = 8600
+# print(HOST)

+ 27 - 5
main.py

@@ -9,7 +9,7 @@ from fastapi.responses import FileResponse
 from fastapi import FastAPI, Depends, HTTPException, Form  
 import httpx
 import os
-from db.user import UserOAuthToken
+# from db.user import UserOAuthToken
 from config import HOST, PORT
 
 app = FastAPI()  
@@ -43,18 +43,36 @@ async def get_access_token(request: Request):
   
     if response.status_code != 200:  
         raise HTTPException(status_code=response.status_code, detail=response.text)  
-  
+    '''
+    {
+    "data": {
+        "access_token": "act.f7094fbffab2ecbfc45e9af9c32bc241oYdckvBKe82BPx8T******",
+        "captcha": "",
+        "desc_url": "",
+        "description": "",
+        "error_code": 0,
+        "expires_in": 1296000,
+        "log_id": "20230525105733ED3ED7AC56A******",
+        "open_id": "b9b71865-7fea-44cc-******",
+        "refresh_expires_in": 2592000,
+        "refresh_token": "rft.713900b74edde9f30ec4e246b706da30t******",
+        "scope": "user_info"
+        },
+        "message": "success"
+    }
+    '''
     data = response.json()["data"]  
   
     print(data)
-  
+    # magong_user = UserOAuthToken(access_token=data['access_token'], open_id=data['open_id'])
     return {"message": "Access token stored successfully"}  
 
 @app.get("/verify_callback")  
 async def verify_callback(request: Request):  
     # 打印请求方法  
     print(f"Method: {request.method}")  
-      
+    # open-douyin.magong.site/verify_callback?code=676a1101ea02bc5dTaUVtKg8c5enYaGqB4dT&state=&scopes=user_info,trial.whitelist
+    print(request.url)
     # 打印请求头  
     print(f"Headers:")  
     for key, value in request.headers.items():  
@@ -67,7 +85,11 @@ async def verify_callback(request: Request):
     return HTMLResponse("<h1>Callback Received! Verification Successful.</h1>")
 
 def main():
-    uvicorn.run(app, host=HOST, port=PORT, log_level="info")
+    print(f"https://open-douyin-cf.magong.site  公网代理地址,cloudflare dns proxy ,由 caddy 转发到 8600 端口")
+    print(f"https://open-douyin-wk.magong.site  公网代理地址,cloudflare workers 转发到 8600 端口")
+    print(f"http://sv-v2.magong.site:{PORT}  ⭐ 推荐,仅支持 ipv6 ,直连、满速、无延迟。缺点是不支持 https 协议,因为不经过 Caddy 代理,直达 Fastapi 没有配置 https")
+    print(f"https://open-douyin.magong.site  内网穿透隧道,cloudflare tunnel ,经常访问不了")
+    uvicorn.run(app, host=None, port=PORT, log_level="info")
 
 if __name__ == "__main__":
     main()

+ 21 - 2
readme.md

@@ -1,11 +1,25 @@
 
+# 项目框架
+参考文档:https://developer.open-douyin.com/docs/resource/zh-CN/dop/develop/sdk/web-app/web/permission
+
+这个网址应该在网站加载,让用户扫码(mrh):
+https://open.douyin.com/platform/oauth/connect/?client_key=aw6aipmfdtplwtyq&response_type=code&scope=user_info,renew_refresh_token,trial.whitelist&redirect_uri=https://open-douyin.magong.site/verify_callback 
+
+(qyl)
+扫码登录后, 服务器 open-douyin.magong.site/verify_callback 收到回调请求,C:\Users\Administrator\Documents\WeChat Files\wxid_0ebvyyalfi4r22\FileStorage\File\2024-01\main.py
+回调的内容是:
+
+
+把扫码登录的结果存到数据库(sqlmodel)
+官方文档: https://github.com/tiangolo/sqlmodel
+
 ```shell
 # WEB扫码接入 参考 https://developer.open-douyin.com/docs/resource/zh-CN/dop/develop/sdk/web-app/web/permission
 # 打开链接,扫码登录 
 GET https://open.douyin.com/platform/oauth/connect/?client_key=aw6aipmfdtplwtyq&response_type=code&scope=user_info,renew_refresh_token,trial.whitelist&redirect_uri=https://api.magong.site/verify_callback HTTP/1.1  
 Host: open.douyin.com
 
-# 服务器收到返回信息。程序员马工
+# 服务器收到返回信息。扫码的抖音号是:程序员马工
 GET /verify_callback?code=936c3671e073703cnzV93iYzyWbdLIZmFPQJ&state=&scopes=user_info,trial.whitelist HTTP/1.1
 # 渣渣辉
 GET /verify_callback?code=676a1101ea02bc5dTaUVtKg8c5enYaGqB4dT&state=&scopes=user_info,trial.whitelist HTTP/1.1
@@ -14,13 +28,14 @@ GET /verify_callback?code=676a1101ea02bc5dTaUVtKg8c5enYaGqB4dT&state=&scopes=use
 GPT:
 以下是接口文档:
 步骤一:获取授权码 code
+参考文档: https://developer.open-douyin.com/docs/resource/zh-CN/dop/develop/openapi/account-permission/douyin-get-permission-code/
 请求示例:
 https://open.douyin.com/platform/oauth/connect?client_key=awf4xgy8cibvhzuv&response_type=code&scope=user_info&redirect_uri=https://api.magong.site/verify_callback
 成功示例:
 GET /verify_callback?code=676a1101ea02bc5dTaUVtKg8c5enYaGqB4dT&state=&scopes=user_info,trial.whitelist HTTP/1.1
 
-
 步骤二:通过授权码 code 获取 access_token
+参考文档: https://developer.open-douyin.com/docs/resource/zh-CN/dop/develop/openapi/account-permission/get-access-token
 HTTP URL
 https://open.douyin.com/oauth/access_token/
 HTTP Method
@@ -64,6 +79,10 @@ curl --location 'https://open.douyin.com/oauth/access_token/' \
   }
 }
 
+
+第三步:获取用户信息
+参考文档: https://developer.open-douyin.com/docs/resource/zh-CN/dop/develop/openapi/account-management/get-account-open-info
+
 以下是我的代码:
 ```python
 app = FastAPI()  

+ 2 - 1
static/index.html

@@ -4,7 +4,8 @@
     <title>FastAPI Callback Verification</title>  
 </head>  
 <body>  
-    <h1>Welcome to the FastAPI Callback Verification Page</h1>  
+    <h1>Welcome to the FastAPI Callback Verification Page</h1>
+    <h1>hello c</h1>  
     <p>This is the homepage for callback verification.</p>  
 </body>  
 </html>

+ 26 - 0
待办事项.md

@@ -0,0 +1,26 @@
+# qyl
+- [ ] **了解数据库**
+  - [ ] 数据库模型 sqlmodel ,官方文档: https://github.com/tiangolo/sqlmodel  
+  - [ ] 数据库软件 PostgreSQL 。 2023 最流行的开源数据库,超越 MySQL 。官网: https://github.com/postgres/postgres ,github 地址:https://github.com/postgres/postgres
+  - [ ] 根据 sqlmodel 的方式编写代码,定义数据库模型,连接至 PostgreSQL ,代码存放在 db/ 目录中
+- [ ] **获取抖音用户信息**
+  - [ ] 参考文档 https://developer.open-douyin.com/docs/resource/zh-CN/dop/develop/sdk/web-app/web/permission
+  - [ ] 扫码后,抖音将扫码结果推送到 /verify_callback 地址,将 code 解析出来。获取用户 access-token 、 expires_in、open_id、refresh_expires_in、refresh_token。参考文档 https://developer.open-douyin.com/docs/resource/zh-CN/dop/develop/openapi/account-permission/get-access-token
+  - [ ] 利用 access-token 获取用户公开信息。
+- [ ] **接入 LangChain (代补充)**
+  - [ ] 向量数据库服务器部署
+  - [ ] 评估大模型记忆框架 MemoryBank https://zhuanlan.zhihu.com/p/674220905?utm_campaign=shareopn&utm_medium=social&utm_oi=766444166291935232&utm_psn=1730836140159057920&utm_source=wechat_session
+
+# mrh
+- [ ] **了解数据库**
+  - [ ] 数据库模型 sqlmodel ,官方文档: https://github.com/tiangolo/sqlmodel  
+  - [ ] 数据库软件 PostgreSQL 。 2023 最流行的开源数据库,超越 MySQL 。官网: https://github.com/postgres/postgres ,github 地址:https://github.com/postgres/postgres
+  - [ ] 部署数据库服务器 PostgreSQL ,确定分布式数据库可行性 https://blog.csdn.net/qq_23934063/article/details/120267886
+- [ ] **编写前端代码**
+  - [ ] 扫码登录,页面跳转
+  - [ ] 了解用户鉴权, element-plus-admin + Fastapi + Oauth2
+  - [ ] 从数据库获取用户数据,展示到用户登录页中
+  - [ ] 文档上传、下载、更新、删除
+- [ ] **接入 LangChain (代补充)**
+  - [ ] 向量数据库服务器部署
+  - [ ] 评估大模型记忆框架 MemoryBank https://zhuanlan.zhihu.com/p/674220905?utm_campaign=shareopn&utm_medium=social&utm_oi=766444166291935232&utm_psn=1730836140159057920&utm_source=wechat_session