Files
kami_ctrip/app.py
danial 752ef17fc8 feat: 添加 Drone CI 配置和 Docker 镜像构建
- 新增 .drone.yml 文件,配置 Drone CI/CD 流程
- 添加 Dockerfile,定义应用的 Docker 镜像构建过程
- 新增 app.py 文件,实现携程卡绑定功能
- 添加 __pycache__ 目录,存放编译后的 Python 文件
2025-03-06 00:28:02 +08:00

60 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import json
from flask import Flask, g, request, jsonify
from ctrip import CtripLogin
from logger import get_logger
app = Flask(__name__)
logger = get_logger()
@app.before_request
def before_request():
g.ip_list = None
g.order_num = None
g.ck = None
g.card_num = None
g.card_pwd = None
g.money = None
g.proxies = {}
@app.route('/xiecheng/v3/card/bind', methods=['GET', 'POST'])
def bind_card_v3():
if request.method == 'GET':
return 'okk'
elif request.method == 'POST':
# 接收参数
data = json.loads(request.get_data())
g.ck = data.get("ck")
g.card_num = data.get("card_num")
g.card_pwd = data.get("card_pwd")
g.order_num = data.get("order_num")
g.money = data.get("money")
# 绑卡
trip = CtripLogin(
cookies=g.ck,
card_num=g.card_num,
card_pwd=g.card_pwd,
price=g.money,
order_num=g.order_num
)
res = trip.run()
logger.info(f"订单ID{g.order_num},返回速代充:{res}")
if res.get("code") == 111:
for _ in range(5):
res = trip.check_card()
logger.info(f"订单ID{g.order_num},未知重新查卡返回:{res}")
if res.get("code") in [110, 2001]:
res = {'code': 110, 'msg': '重新查卡返回可重新绑卡', 'data': {}}
return jsonify(res)
if res.get("code") == 111:
continue
res = {'code': 111, 'msg': '重新查卡未知', 'data': {}}
return jsonify(res)
if __name__ == '__main__':
app.run()