彩票系统接口文档

服务地址: https://api.639986.top
认证方式: HTTP Basic Authentication(部分接口需要,用户名: admin, 密码: admin123456)
响应格式: JSON


1. 健康检查

GET /health

检查服务和数据库连接状态。

  • 请求参数: 无
  • 响应: json { "status": "healthy", "database": "connected" }
  • 错误响应: json { "status": "unhealthy", "database": "错误信息" }

2. 管理员登录

POST /api/login

验证管理员身份,通过 HTTP Basic Authentication 输入账号密码。

  • 请求头:
  • Authorization: Basic <base64_encoded_credentials>
  • 生成 Base64 凭据:
    • 格式: 用户名:密码 编码为 Base64
    • 示例: 用户名 admin,密码 admin123456,编码为 YWRtaW46YWRtaW4xMjM0NTY=
    • 使用命令生成: bash echo -n "admin:admin123456" | base64 输出: YWRtaW46YWRtaW4xMjM0NTY=
  • 请求示例: bash curl -X POST "http://localhost:5001/api/login" \ -H "Authorization: Basic YWRtaW46YWRtaW4xMjM0NTY="
  • 响应: json { "message": "登录成功" }
  • 错误响应:
  • 401 Unauthorized: json { "detail": "用户名或密码错误" }

3. 管理端-获取历史记录

GET /api/history

查询指定年份和彩票类型的开奖历史(包括已开奖和未开奖),按 issue 倒序排列。

  • 查询参数:
  • year: 年份 (可选, 默认 2025, 例: 2024)
  • lottery_type: 彩票类型 (可选, 默认 "hongkong")
  • 响应: json { "data": [ { "id": 1, "issue": "2024002", "lottery_type": "hongkong", "draw_date": "20240102", "status": "未开奖", "predictions": { "one_code": {"value": 5, "result": 0} }, "pic1": "", "pic2": "", "pic3": "", "main_numbers": [], "main_attributes": [], "special_number": null, "special_attributes": {} }, { "id": 2, "issue": "2024001", "lottery_type": "hongkong", "draw_date": "20240101", "status": "已开奖", "predictions": { "one_code": {"value": 3, "result": 1}, "one_zodiac": {"value": "兔", "result": 0} }, "pic1": "", "pic2": "", "pic3": "", "main_numbers": [1, 10, 23, 27, 35, 47], "main_attributes": [ {"zodiac": "鼠", "wuxing": "水", "colors": "红", ...}, ... ], "special_number": 3, "special_attributes": {"zodiac": "狗", "wuxing": "土", ...} } ] }

4. 添加或更新预测

POST /api/prediction

添加或更新指定期数的预测数据,若期数不存在则自动插入。

  • 请求头:
  • Authorization: Basic YWRtaW46YWRtaW4xMjM0NTY=
  • Content-Type: application/json
  • 请求体: json { "issue": "2024001", "lottery_type": "hongkong", "draw_date": "20240101", "predictions": { "one_code": {"value": 3, "result": 0}, "one_zodiac": {"value": "兔", "result": 0}, "double_colors": {"value": ["红", "蓝"], "result": 0}, "four_zodiacs_eight_codes": {"value": ["鼠", "兔"], "result": 0} }, "pic1": "", "pic2": "", "pic3": "", "poetry_zodiacs": "" #对应的是大湾区的那个诗,猜生肖 }
  • 请求示例: bash curl -X POST "http://localhost:5001/api/prediction" \ -H "Authorization: Basic YWRtaW46YWRtaW4xMjM0NTY=" \ -H "Content-Type: application/json" \ -d '{ "issue": "2024001", "lottery_type": "hongkong", "draw_date": "20240101", "predictions": { "one_code": {"value": 3, "result": 0}, "one_zodiac": {"value": "兔", "result": 0}, "double_colors": {"value": ["红", "蓝"], "result": 0}, "four_zodiacs_eight_codes": {"value": ["鼠", "兔"], "result": 0} }, "pic1": "", "pic2": "", "pic3": "" }'
  • predictions JSON 格式(24 种预测类型):: { "one_code": {"value": 36, "result": 0}, "three_codes": {"value": [19, 22, 36], "result": 0}, "five_codes": {"value": [19, 22, 36, 5, 9], "result": 0}, "seven_codes": {"value": [19, 22, 36, 5, 9, 47, 33], "result": 0}, "nine_codes": {"value": [19, 22, 36, 5, 9, 47, 33, 46, 2], "result": 0}, "one_zodiac": {"value": "马", "result": 0}, "three_zodiacs": {"value": ["猪", "猴", "龙"], "result": 0}, "five_zodiacs": {"value": ["猪", "猴", "龙", "鼠", "羊"], "result": 0}, "six_zodiacs": {"value": ["猪", "猴", "龙", "鼠", "羊"], "result": 0}, "seven_zodiacs": {"value": ["猪", "猴", "龙", "鼠", "羊", "虎", "马"], "result": 0}, "nine_zodiacs": {"value": ["猪", "猴", "龙", "鼠", "羊", "虎", "马", "兔", "牛"], "result": 0}, "double_colors": {"value": ["蓝波", "绿波"], "result": 0}, "seven_tails": {"value": ["8", "5", "9", "6", "1", "7", "2"], "result": 0}, "flat_one_zodiac": {"value": "兔", "result": 0}, "four_zodiacs_eight_codes": {"value": {"虎": [4, 28], "猪": [19, 43], "狗": [8, 44], "兔": [15, 39]}, "result": 0}, "three_issue_zodiacs": {"value": ["虎", "马", "鸡"], "result": 0}, "domestic_wild_two": {"value": ["家禽", "蛇"], "result": 0}, "single_double_four": {"value": {"单肖": ["兔", "牛"], "双肖": ["马", "鼠"]}, "result": 0}, "seasons_three": {"value": ["春", "夏", "秋"], "result": 0}, "arts_three": {"value": ["琴", "棋", "画"], "result": 0}, "three_elements": {"value": ["土", "金", "火"], "result": 0}, "three_heads": {"value": ["2", "1", "0"], "result": 0}, "kill_head": {"value": "3", "result": 0}, "kill_two_zodiacs": {"value": ["兔", "虎"], "result": 0}, "kill_ten_codes": {"value": [16, 45, 41, 31, 34, 5, 9, 49, 44, 22], "result": 0}, "twenty_codes": {"value": [16, 45, 41, 31, 34, 5, 9, 49, 44, 22,16, 45, 41, 31, 34, 5, 9, 49, 44, 22], "result": 0}, "bold_timidity": {"value": "胆大", "result": 0}, "single_double": {"value": "单", "result": 0}, "big_small": {"value": "大", "result": 0} } pic1 pic2 pic3 对应的的是码头诗 龙门客栈 挂牌天数,虽说是预测,但这个需要创建期数的时候,就要上传

  • 响应: json { "message": "预测已更新或插入", "issue": "2024001" }

  • 错误响应:
  • 403 Forbidden (已开奖): json { "detail": "已开奖的预测不可修改" }

5. 管理端-设置开奖

POST /api/draw

设置指定期数的开奖号码和属性。

  • 请求头:
  • Authorization: Basic YWRtaW46YWRtaW4xMjM0NTY=
  • Content-Type: application/json
  • 请求体: json { "issue": "2024001", "lottery_type": "hongkong", "main_numbers": [1, 10, 23, 27, 35, 47], "special_number": 3 }
  • 请求示例: bash curl -X POST "http://localhost:5001/api/draw" \ -H "Authorization: Basic YWRtaW46YWRtaW4xMjM0NTY=" \ -H "Content-Type: application/json" \ -d '{ "issue": "2024001", "lottery_type": "hongkong", "main_numbers": [1, 10, 23, 27, 35, 47], "special_number": 3 }'
  • 响应: json { "message": "开奖已设置", "issue": "2024001" }
  • 错误响应:
  • 400 Bad Request (号码无效): json { "detail": "请输入6个1-49的正码和1个1-49的特别号码" }
  • 403 Forbidden (已开奖): json { "detail": "已开奖,不可重复设置" }
  • 404 Not Found (期数不存在): json { "detail": "期数不存在" }
  • 400 Bad Request (配置不存在): json { "detail": "配置不存在" }

6. 获取配置

GET /api/config

获取指定年份的彩票配置。

  • 查询参数:
  • year: 年份 (可选, 默认 2025, 例: 2024)
  • 请求示例: bash curl "http://localhost:5001/api/config?year=2024"
  • 响应: json { "data": [ { "id": 1, "year": 2024, "lottery_type": "hongkong", "config": { "zodiac": { "鼠": [1, 13, 25, 37, 49], "狗": [3, 15, 27, 39], ... }, "wuxing": { "金": {"numbers": [4, 5, 16, 17, 28, 29, 40, 41], "zodiacs": ["猴", "鸡"]}, ... }, ... } } ] }
  • 错误响应:
  • 无配置数据: json { "data": [] }

7. 前端统计-获取已开奖列表

GET /api/draws/completed

查询指定年份和彩票类型的已开奖记录,按 issue 倒序排列。

  • 查询参数:
  • year: 年份 (可选, 默认 2025, 例: 2024)
  • lottery_type: 彩票类型 (可选, 默认 "hongkong")
  • 请求示例: bash curl "http://localhost:5001/api/draws/completed?year=2024&lottery_type=hongkong"
  • 响应: json { "data": [ { "id": 2, "issue": "2024002", "lottery_type": "hongkong", "draw_date": "20240102", "status": "已开奖", "predictions": {...}, "pic1": "", "pic2": "", "pic3": "", "main_numbers": [1, 10, 23, 27, 35, 47], "main_attributes": [...], "special_number": 3, "special_attributes": {"zodiac": "狗", "wuxing": "土", ...} }, { "id": 1, "issue": "2024001", "lottery_type": "hongkong", "draw_date": "20240101", "status": "已开奖", "predictions": {...}, "pic1": "", "pic2": "", "pic3": "", "main_numbers": [1, 10, 23, 27, 35, 47], "main_attributes": [...], "special_number": 3, "special_attributes": {"zodiac": "狗", "wuxing": "土", ...} } ] }

8. 前端首页-获取包含下一期未开

GET /api/draws/completed_with_next

查询指定年份的已开奖记录,并附加最新一期未开奖记录,按 issue 倒序排列。

  • 查询参数:
  • year: 年份 (可选, 默认 2025, 例: 2024)
  • lottery_type: 彩票类型 (可选, 默认 "hongkong")
  • 请求示例: bash curl "http://localhost:5001/api/draws/completed_with_next?year=2024&lottery_type=hongkong"
  • 响应: json { "data": [ { "id": 2, "issue": "2024002", "lottery_type": "hongkong", "draw_date": "20240102", "status": "已开奖", "predictions": {...}, "pic1": "", "pic2": "", "pic3": "", "main_numbers": [1, 10, 23, 27, 35, 47], "main_attributes": [...], "special_number": 3, "special_attributes": {"zodiac": "狗", "wuxing": "土", ...} }, { "id": 1, "issue": "2024001", "lottery_type": "hongkong", "draw_date": "20240101", "status": "已开奖", "predictions": {...}, "pic1": "", "pic2": "", "pic3": "", "main_numbers": [1, 10, 23, 27, 35, 47], "main_attributes": [...], "special_number": 3, "special_attributes": {"zodiac": "狗", "wuxing": "土", ...} }, { "id": 3, "issue": "2024003", "lottery_type": "hongkong", "draw_date": "20240103", "status": "未开奖", "predictions": {...}, "pic1": "", "pic2": "", "pic3": "", "main_numbers": [], "main_attributes": [], "special_number": null, "special_attributes": {} } ] }

9. 图片上传接口-需登录-传

pic1 pic2 pic3 使用 POST /api/upload_images

释例

curl -X POST "http://localhost:5001/api/upload_images" \
     -H "Authorization: Basic YWRtaW46YWRtaW4xMjM0NTY=" \
     -F "file=@/path/to/image.jpg"

注意事项

  • 认证: /api/login, /api/prediction, /api/draw 需要 Basic Auth,需将用户名和密码编码为 Base64。
  • 示例: echo -n "admin:admin123456" | base64
  • CORS: 支持跨域请求(allow_origins=["*"])。
  • 号码范围: main_numbersspecial_number 必须为 1-49。
  • 期数格式: issue 为字符串,如 "2024001"。
  • 日期格式: draw_date 为字符串,格式 "YYYYMMDD"。
  • 排序: 所有列表接口(/api/history, /api/draws/completed, /api/draws/completed_with_next)按 issue 倒序排列。