> ## Documentation Index
> Fetch the complete documentation index at: https://doc.va777.net/llms.txt
> Use this file to discover all available pages before exploring further.

# 簽章規則

> 每次呼叫 API 都必須帶入的 sign 參數產生方式與範例。

每次呼叫我方服務時都必須帶入 `sign` 參數。`sign` 由此次傳遞的參數加上 API Key 組合後產生。

各 API 參數表中標示「參與簽章」的欄位，都要納入簽章計算；`sign` 本身不納入。

## 產生步驟

**1. 依 key 升序排序**

將參數陣列依 key 值升序排序。

**2. URL-encode 並組成 query string**

將各參數轉換為 URL-encoded 後組成 query string。編碼結果須為**大寫**，例如 `:` 應轉換為 `%3A`，而非 `%3a`。

**3. 接上 API Key 並計算 MD5**

在 query string 後方直接接上 API Key，計算 MD5 即為 `sign`。

## 範例

以[取得遊戲列表](https://doc.va777.net/api-reference/game/list.md)為例，假設 API Key 為 `a188va`：

| 步驟 | 結果 |
| - | - |
| 參數 | `lang=en-US` |
| 接上 API Key | `lang=en-USa188va` |
| MD5 結果（`sign`） | `1e223cbbb0d30b1d3cc5e5764e1d88fa` |

## PHP 範例

```php sign.php theme={null}
<?php
    $data = array(
     "start_time" => "2020-07-01T00:00:00.000+08:00",
     "end_time" => "2020-07-02T00:00:00.000+08:00",
     "page_size" => 2000,
     "page" => 1
    );

    // $data: 傳遞的參數陣列，若沒傳遞參數則放空陣列
    // $apiKey: 代理商的 API KEY
    function generateSign($data, $apiKey)
    {
       ksort($data);

       $httpQuery = http_build_query($data);
       // end_time=2020-07-02T00%3A00%3A00.000%2B08%3A00&page=1&page_size=2000&start_time=2020-07-01T00%3A00%3A00.000%2B08%3A00

       $sign = md5($httpQuery . "$apiKey");
       // 4dc6c36f26c18020fe871d000789c611

       return $sign;
    }
?>
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.