's'
This commit is contained in:
@@ -7,7 +7,7 @@ import threading
|
||||
import time
|
||||
|
||||
import requests
|
||||
from fastapi import APIRouter, HTTPException, Request
|
||||
from fastapi import APIRouter, File, HTTPException, Request, UploadFile
|
||||
from fastapi.responses import JSONResponse, RedirectResponse
|
||||
from requests.adapters import HTTPAdapter
|
||||
|
||||
@@ -20,6 +20,7 @@ from ..payment import (
|
||||
)
|
||||
from ..payment.zpay import ZPayProvider
|
||||
from ..services import handle_payment_success, processed_orders
|
||||
from ..services.discount_proof import recognize_discount_proof
|
||||
|
||||
router = APIRouter(prefix="/nomadvip", tags=["nomadvip"])
|
||||
|
||||
@@ -978,3 +979,34 @@ async def nomadvip_zpay_notify(request: Request):
|
||||
)
|
||||
raise
|
||||
return provider.success_response()
|
||||
|
||||
|
||||
@router.post("/recognize_discount_proof")
|
||||
async def nomadvip_recognize_discount_proof(image: UploadFile = File(...)):
|
||||
"""识别优惠凭证:提取头像区域与昵称(独立接口,不影响现有支付链路)。"""
|
||||
content_type = (image.content_type or "").lower()
|
||||
if not content_type.startswith("image/"):
|
||||
return JSONResponse(
|
||||
status_code=400, content={"ok": False, "error": "仅支持图片文件"}
|
||||
)
|
||||
|
||||
raw = await image.read()
|
||||
if not raw:
|
||||
return JSONResponse(
|
||||
status_code=400, content={"ok": False, "error": "图片内容为空"}
|
||||
)
|
||||
if len(raw) > 12 * 1024 * 1024:
|
||||
return JSONResponse(
|
||||
status_code=400, content={"ok": False, "error": "图片大小超过 12MB"}
|
||||
)
|
||||
|
||||
try:
|
||||
result = recognize_discount_proof(raw)
|
||||
status = 200 if result.get("ok") else 400
|
||||
return JSONResponse(status_code=status, content=result)
|
||||
except Exception as error:
|
||||
logging.warning("[payjsapi] recognize_discount_proof failed: %s", error)
|
||||
return JSONResponse(
|
||||
status_code=500,
|
||||
content={"ok": False, "error": "识别服务异常,请稍后重试"},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user