Tài liệu / Tích hợp/ Tích hợp Python

Tích hợp Python

Tích hợp Cập nhật: 22/03/2026

Tích hợp Python

Cài đặt

pip install requests flask

Gọi API lấy giao dịch

import requests

API_KEY = "YOUR_API_KEY"
BASE_URL = "https://thueapi.vn/api/v1"

headers = {"Authorization": f"Bearer {API_KEY}"}

# Lấy danh sách giao dịch
response = requests.get(f"{BASE_URL}/transactions", headers=headers, params={
    "from": "2026-03-01",
    "to": "2026-03-31",
    "per_page": 50
})

transactions = response.json()["data"]
for tx in transactions:
    print(f"[{tx['transferType']}] {tx['transferAmount']:,}đ - {tx['content']}")

Nhận Webhook (Flask)

import hmac, hashlib, json
from flask import Flask, request, jsonify

app = Flask(__name__)
SECRET = b"YOUR_WEBHOOK_SECRET"

@app.route("/webhook/thueapi", methods=["POST"])
def webhook():
    payload = request.get_data()
    signature = request.headers.get("X-Webhook-Signature", "")
    expected = hmac.new(SECRET, payload, hashlib.sha256).hexdigest()

    if not hmac.compare_digest(expected, signature):
        return jsonify({"error": "Invalid signature"}), 401

    data = json.loads(payload)
    for tx in data.get("transactions", []):
        # Kiểm tra trùng lặp bằng checksum
        print(f"Giao dịch: {tx['transferAmount']}đ - {tx['content']}")
        # TODO: Lưu DB, cập nhật đơn hàng

    return jsonify({"success": True})

if __name__ == "__main__":
    app.run(port=5000)
ThueAPI.VN
Đăng nhập với Google
hoặc đăng nhập bằng email
Quên mật khẩu?

Chưa có tài khoản?

Đăng ký với Google
hoặc đăng ký bằng email

Bằng cách đăng ký, bạn đồng ý với Điều khoản dịch vụChính sách bảo mật của chúng tôi.

Đã có tài khoản?