# 签到

签到接口用于获取最新的终端密钥（terminal_key）。建议每日在首次交易前进行设备秘钥更换，然后使用最新秘钥进行签名。

## 接口说明

- 请求方式：`POST`
- 请求地址：`https://vsi-api.shouqianba.com/terminal/checkin`
- Operation ID：`checkin`

## 请求参数

无请求参数。

## 请求体

| 字段名 | 类型 | 必填 | 描述 |
| --- | --- | --- | --- |
| device_id | string | 是 | 设备唯一身份ID |
| os_info | string | 否 | 当前系统信息，如：Android5.0 |
| sdk_version | string | 否 | SDK版本 |
| terminal_sn | string | 是 | 终端号 |

## 请求示例

```json
{
  "device_id": "ZARA001P01",
  "terminal_sn": "10298371039"
}
```

## 响应体

| 字段名 | 类型 | 必填 | 描述 |
| --- | --- | --- | --- |
| biz_response | object | 否 | 业务响应数据。签到成功时包含最新的终端号和终端密钥。 |
| biz_response.terminal_key | string | 是 | 终端密钥（最新） |
| biz_response.terminal_sn | string | 是 | 终端号 |
| error_code | string | 否 | 通讯错误码。通讯失败时返回。见附录《公共错误码》 |
| error_message | string | 否 | 通讯错误信息描述。通讯失败时返回。 |
| result_code | string | 是 | 通讯响应码。200：通讯成功；400：客户端错误；500：服务端错误 |

## 响应示例

```json
{
  "biz_response": {
    "terminal_key": "68d499beda5f72116592f5c527465656",
    "terminal_sn": "10298371039"
  },
  "result_code": "200"
}
```

## 示例代码

### cURL

```bash
curl -X POST "https://vsi-api.shouqianba.com/terminal/checkin" \
  -H "Authorization: 100000000000000000 0123456789abcdef0123456789abcdef" \
  -H "Content-Type: application/json" \
  -d '{"device_id":"ZARA001P01","terminal_sn":"10298371039"}'
```

### Python

```python
import requests

url = "https://vsi-api.shouqianba.com/terminal/checkin"
headers = {"Content-Type": "application/json",
    "Authorization": "100000000000000000 0123456789abcdef0123456789abcdef",
}
json_data = {
    "device_id": "ZARA001P01",
    "terminal_sn": "10298371039"
}

response = requests.post(
    url,
    headers=headers,
    json=json_data,
)

print(response.json())
```

### Java

```java
// 签到
OkHttpClient client = new OkHttpClient();
String json = "{\"device_id\":\"ZARA001P01\",\"terminal_sn\":\"10298371039\"}";
RequestBody body = RequestBody.create(json, MediaType.parse("application/json"));

Request request = new Request.Builder()
    .url("https://vsi-api.shouqianba.com/terminal/checkin")
    .addHeader("Authorization", "100000000000000000 0123456789abcdef0123456789abcdef")
    .post(body)
    .build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());
```

### Go

```go
package main

import (
    "fmt"
    "io"
    "net/http"
    "bytes"
)

func main() {
	jsonBody := []byte(`{"device_id":"ZARA001P01","terminal_sn":"10298371039"}`)
	reqBody := bytes.NewBuffer(jsonBody)
	req, err := http.NewRequest("POST", "https://vsi-api.shouqianba.com/terminal/checkin", reqBody)
	if err != nil {
		panic(err)
	}
	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("Authorization", "100000000000000000 0123456789abcdef0123456789abcdef")
	resp, err := (&http.Client{}).Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()
	respBytes, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(respBytes))
}
```

### Node.js

```javascript
const https = require("https");

const options = {
  method: "POST",
  hostname: "vsi-api.shouqianba.com",
  path: "/terminal/checkin",
  headers: {
    "Authorization": "100000000000000000 0123456789abcdef0123456789abcdef",
    "Content-Type": "application/json"
  }
};

const postData = JSON.stringify({"device_id":"ZARA001P01","terminal_sn":"10298371039"});

const req = https.request(options, (res) => {
  let data = "";
  res.on("data", (chunk) => { data += chunk; });
  res.on("end", () => { console.log(JSON.parse(data)); });
});
req.write(postData);
req.end();
```
