From 491230399133031ad045c11359116c9f16f77397 Mon Sep 17 00:00:00 2001 From: liubiren Date: Wed, 3 Jun 2026 21:08:26 +0800 Subject: [PATCH] =?UTF-8?q?260603=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/agent.py | 17 ++++++++--------- 安全加密请求/main.py | 44 ++++++++++++++++++++++++++++++++------------ 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/utils/agent.py b/utils/agent.py index e42a662..533de34 100644 --- a/utils/agent.py +++ b/utils/agent.py @@ -10,7 +10,6 @@ from typing import List, Optional, Union, cast from typing import TypeVar from uuid import uuid4 -from mistralai.client.models import Op from pydantic_ai import Agent as BaseAgent, AgentRunResult from pydantic_ai.capabilities import AgentCapability from pydantic_ai.models.openai import OpenAIChatModel @@ -141,7 +140,7 @@ class Agent: from pydantic_ai.ui.vercel_ai import VercelAIAdapter from pydantic_ai.capabilities import NativeTool - async def options(request: Request) -> Response: + async def chat_options(request: Request) -> Response: """处理跨域预检请求""" return Response() @@ -179,7 +178,7 @@ class Agent: ) return JSONResponse(content=configurations.model_dump(by_alias=True)) - async def chat(request: Request) -> Response: + async def chat_post(request: Request) -> Response: """处理对话请求""" # 实例 Vercel AI 适配器 adapter = await VercelAIAdapter[ @@ -216,10 +215,10 @@ class Agent: return Starlette( routes=[ - Route("/chat", options, methods=["OPTIONS"]), - Route("/configure", configurations, methods=["GET"]), - Route("/chat", chat, methods=["POST"]), - Route("/health", health, methods=["GET"]), + Route(path="/chat", endpoint=chat_options, methods=["OPTIONS"]), + Route(path="/configure", endpoint=configurations, methods=["GET"]), + Route(path="/chat", endpoint=chat_post, methods=["POST"]), + Route(path="/health", endpoint=health, methods=["GET"]), ] ) @@ -244,7 +243,7 @@ class Agent: ) ] ) - application.router.add_route("/", index, methods=["GET"]) - application.router.add_route("/{id}", index, methods=["GET"]) + application.router.add_route(path="/", endpoint=index, methods=["GET"]) + application.router.add_route(path="/{id}", endpoint=index, methods=["GET"]) return application diff --git a/安全加密请求/main.py b/安全加密请求/main.py index 21d865e..ccb5b75 100644 --- a/安全加密请求/main.py +++ b/安全加密请求/main.py @@ -8,6 +8,7 @@ from base64 import b64decode, b64encode from json import dumps, loads from pathlib import Path from secrets import token_bytes +import sys from time import time_ns from typing import cast from typing import Any, Dict, Literal, Optional, Tuple @@ -21,10 +22,7 @@ from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from cryptography.hazmat.primitives.serialization import load_pem_public_key -import sys - sys.path.append(Path(__file__).parent.parent.as_posix()) - from utils.request import Request @@ -222,21 +220,24 @@ if __name__ == "__main__": # 实例加密器 encryptor = Encryptor() + # 杭州汤然请求同步响应 + # https://risk-gw.pangjukeji.com/api/v1/riskgateway/product/invokeSync.json + # 杭州汤然请求异步响应(创建任务) + # https://risk-gw.pangjukeji.com/api/v1/riskgateway/product/submitAsyncTask.json + # 杭州汤然请求异步响应(查询任务) + # https://risk-gw.pangjukeji.com/api/v1/riskgateway/result/queryAsyncResult.json # 实例请求客户端 request = Request() # 不使用缓存 response = request.post( - url="https://risk-gw.pangjukeji.com/api/v1/riskgateway/product/invokeSync.json", + url="https://risk-gw.pangjukeji.com/api/v1/riskgateway/result/queryAsyncResult.json", headers={ "Authorization": "Bearer 337162980141699072", "Content-Type": "application/json;charset=utf-8", }, json=encryptor.encrypt( payload={ - "productId": "BANK_CARD_4", - "name": "刘弼仁", - "certNo": "131002198705024619", - "mobilephone": "18058798752", - "bankCardNo": "6214835712066453", + "productId": "CAR_ACCIDENT_DETAIL", + "recordId": "337471805314961408", }, fields_mapping={ "aes_key_encoded": "encryptedAesKey", @@ -267,8 +268,27 @@ if __name__ == "__main__": "certNo": "131002196212124620" } +{ + "productId": "BANK_CARD_4", + "name": "刘弼仁", + "certNo": "131002198705024619", + "mobilephone": "18058798752", + "bankCardNo": "6228480328744527172", + }, - - - +{ + "productId": "SOCIAL_CAPACITY", + "name": "刘弼仁", + "certNo": "131002198705024619", + "mobilephone": "18058798752", + }, +{ + "productId": "CREDIT_RISK_PRE_SCREEN", + "mobilephone": "13833652939", + "certNo": "131002196212124620" + }, +{ + "productId": "CAR_ACCIDENT_DETAIL", + "vin": "L6T7712Z2GN076782", + } """