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

Tích hợp Go

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

Tích hợp Go

Gọi API

package main

import (
    "encoding/json"
    "fmt"
    "net/http"
    "io"
)

const apiKey = "YOUR_API_KEY"
const baseURL = "https://thueapi.vn/api/v1"

func getTransactions() {
    req, _ := http.NewRequest("GET", baseURL+"/transactions?from=2026-03-01&to=2026-03-31", nil)
    req.Header.Set("Authorization", "Bearer "+apiKey)

    resp, _ := http.DefaultClient.Do(req)
    defer resp.Body.Close()
    body, _ := io.ReadAll(resp.Body)

    var result map[string]interface{}
    json.Unmarshal(body, &result)
    fmt.Println(string(body))
}

Nhận Webhook

package main

import (
    "crypto/hmac"
    "crypto/sha256"
    "encoding/hex"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
)

const webhookSecret = "YOUR_WEBHOOK_SECRET"

func webhookHandler(w http.ResponseWriter, r *http.Request) {
    body, _ := io.ReadAll(r.Body)
    signature := r.Header.Get("X-Webhook-Signature")

    mac := hmac.New(sha256.New, []byte(webhookSecret))
    mac.Write(body)
    expected := hex.EncodeToString(mac.Sum(nil))

    if !hmac.Equal([]byte(expected), []byte(signature)) {
        http.Error(w, , 401)
        return
    }

    var data map[string]interface{}
    json.Unmarshal(body, &data)
    fmt.Printf("Received webhook: %s\n", string(body))

    w.Header().Set("Content-Type", "application/json")
    w.Write([]byte())
}

func main() {
    http.HandleFunc("/webhook/thueapi", webhookHandler)
    fmt.Println("Listening on :8080")
    http.ListenAndServe(":8080", nil)
}
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?