بدون توضیح

qyl 3884412051 完成 gRPC 文件信息发送,让服务器向量转换 1 سال پیش
api 3884412051 完成 gRPC 文件信息发送,让服务器向量转换 1 سال پیش
db 3884412051 完成 gRPC 文件信息发送,让服务器向量转换 1 سال پیش
douyin 3884412051 完成 gRPC 文件信息发送,让服务器向量转换 1 سال پیش
grpc_m 3884412051 完成 gRPC 文件信息发送,让服务器向量转换 1 سال پیش
static c56490c72c 待办事项 1 سال پیش
test 3884412051 完成 gRPC 文件信息发送,让服务器向量转换 1 سال پیش
.gitignore 5ca3531385 文档分类 1 سال پیش
config.py 3884412051 完成 gRPC 文件信息发送,让服务器向量转换 1 سال پیش
main.py 3884412051 完成 gRPC 文件信息发送,让服务器向量转换 1 سال پیش
readme.md 20ff604e22 完成登录鉴权 1 سال پیش
待办事项.md 5ca3531385 文档分类 1 سال پیش

readme.md

项目框架

参考文档: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

# 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

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 POST Content-Type string "application/json" 请求示例 curl --location 'https://open.douyin.com/oauth/access_token/' \ --header 'Content-Type: application/json' \ --data '{

"grant_type": "authorization_code",
"client_key": "aw05az2qjv4b****",
"client_secret": "7802f4e6f243e659d51135445fe******",
"code": "676a1101ea02bc5dTaUVtKg8c5enYaGqB4dT"

}' 响应示例 {

"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": {

"description": "Parameter error",
"error_code": 2100005

}, "extra": {

"logid": "2020070614111601022506808001045D59",
"now": 1594015876138

} }

第三步:获取用户信息 参考文档: https://developer.open-douyin.com/docs/resource/zh-CN/dop/develop/openapi/account-management/get-account-open-info 请求示例:

curl --location --request POST 'https://open.douyin.com/oauth/userinfo/' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'open_id=ba253642-0590-40bc-9bdf-9a1334******' \
--data-urlencode 'access_token=act.1d1021d2aee3d41fee2d2add43456badMFZnrhFhfWotu3Ecuiuka2******'

响应示例 正常示例

{
  "data": {
    "avatar": "https://example.com/x.jpeg",
    "avatar_larger": "https://example.com/x.jpeg",
    "client_key": "ExampleClientKey",
    "e_account_role": "",
    "error_code": 0,
    "log_id": "202212011600080101351682282501F9E7",
    "nickname": "TestAccount",
    "open_id": "0da22181-d833-447f-995f-1beefe******",
    "union_id": "1ad4e099-4a0c-47d1-a410-bffb4f******"
  },
  "message": "success"
}

异常示例

{
  "data": {
    "description": "Parameter error",
    "error_code": 2100005
  },
  "extra": {
    "logid": "2020070614111601022506808001045D59",
    "now": 1594015876138
  }
}

以下是我的代码:

app = FastAPI()  
  
@app.get("/")  
async def read_root(request: Request):  
    return FileResponse(os.path.join("static", "index.html"))  

@app.get("/jsbridge")  
async def verify_callback(request: Request):  
    return FileResponse(os.path.join("static", "douyin_open.umd.js"))  

@app.get("/verify_callback")  
async def verify_callback(request: Request):  
    # 打印请求方法  
    print(f"Method: {request.method}")  
      
    # 打印请求头  
    print(f"Headers:")  
    for key, value in request.headers.items():  
        print(f"{key}: {value}")  

    # 打印查询参数  
    print(f"Query Parameters:")  
    for key, value in request.query_params.items():  
        print(f"{key}: {value}")  
    return HTMLResponse("<h1>Callback Received! Verification Successful.</h1>")

用 Fastapi fastapi_amis_admin 完成以上文档功能。将 verify_callback 获得的 code 获取 access_token 。然后将 access_token 、 expires_in、open_id、refresh_expires_in、refresh_token 存入数据库。不要给太多说明,直接写代码