from flask import Flask, jsonify, request

app = Flask(__name__)

@app.route("/qw", methods=["POST"])
def qw():
    try:
        data = request.get_json()  # 获取请求中的JSON数据
        username = data.get("username")  # 使用 .get() 方法获取字段值
        password = data.get("password")

        if not all([username, password]):  # 检查所有必需字段是否存在
            return jsonify(msg="缺少参数"), 400

        if username == "123" and password == "123":
            return jsonify(msg="登录成功"), 200
        else:
            return jsonify(msg="密码或用户名错误"), 401
    except Exception as e:
        return jsonify(error=str(e)), 500

if __name__ == '__main__':
    app.run(host="0.0.0.0", port=5000)  # 运行应用，并指定主机和端口