Initial commit with 2026 World Cup Quant Platform core modules and CI/CD
This commit is contained in:
41
platform/backend/app/api/affiliate.py
Normal file
41
platform/backend/app/api/affiliate.py
Normal file
@@ -0,0 +1,41 @@
|
||||
from fastapi import APIRouter, Request, HTTPException
|
||||
from fastapi.responses import RedirectResponse
|
||||
import uuid
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
# 模擬的 affiliate_clicks 記錄,實務上應寫入 TimescaleDB / PostgreSQL
|
||||
# affiliate_clicks_db = []
|
||||
|
||||
@router.get("/api/v1/go/{bookmaker_id}")
|
||||
async def affiliate_redirect(bookmaker_id: str, request: Request):
|
||||
"""
|
||||
動態聯盟行銷與防廣告攔截引擎
|
||||
- Server-side redirect
|
||||
- 紀錄點擊以計算 CR
|
||||
"""
|
||||
|
||||
# 模擬博彩公司對應表與追蹤碼
|
||||
bookmakers = {
|
||||
"bet365": "https://www.bet365.com/?affiliate=QUANT2026",
|
||||
"pinnacle": "https://www.pinnacle.com/?ref=QUANT2026",
|
||||
"draftkings": "https://www.draftkings.com/?track=QUANT2026"
|
||||
}
|
||||
|
||||
if bookmaker_id not in bookmakers:
|
||||
raise HTTPException(status_code=404, detail="Bookmaker not found")
|
||||
|
||||
target_url = bookmakers[bookmaker_id]
|
||||
|
||||
# 記錄點擊資料 (User-Agent, IP, Timestamp, etc)
|
||||
click_data = {
|
||||
"click_id": str(uuid.uuid4()),
|
||||
"bookmaker_id": bookmaker_id,
|
||||
"user_agent": request.headers.get("user-agent", "unknown"),
|
||||
"client_ip": request.client.host if request.client else "unknown"
|
||||
}
|
||||
|
||||
# affiliate_clicks_db.append(click_data)
|
||||
# print(f"Logged affiliate click: {click_data}")
|
||||
|
||||
return RedirectResponse(url=target_url, status_code=302)
|
||||
Reference in New Issue
Block a user