API docsAPI docs
  • English
  • zh-CN
  • English
  • zh-CN
    • 概述
    • 请求 & 响应
    • 获取Auth Token
    • 使用 Auth Token
    • Api Example
    • 区域API
    • 部门API
    • 职位API
    • 人员API
    • 离职API
    • 设备API
    • 考勤记录API
    • 考勤报表API

使用 Auth Token

Python 示例

import json
import requests


url = "http://{host}:{port}/personnel/api/areas/"
# use General token
headers = {
    "Content-Type": "application/json",
    "Authorization": "Token ae600......2b7",
}
# or use JWT tokn
headers = {
    "Content-Type": "application/json",
    "Authorization": "JWT ey.........oQi98",
}

response = requests.get(url, headers=headers)
print(response.text)

Postman 示例

postman3

Java 示例

Postman example

postman3

Java example

public static String doGet(String httpUrl, String token){
    HttpURLConnection connection = null;
    InputStream is = null;
    OutputStream os = null;
    BufferedReader br = null;
    String result = null;
    try {
        URL url = new URL(httpUrl);
        connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.setConnectTimeout(15000);
        connection.setReadTimeout(60000);
        connection.setRequestProperty("Content-Type", "application/json");
        connection.setRequestProperty("Authorization", token);
        connection.connect();
        if (connection.getResponseCode() == 200) {

            is = connection.getInputStream();
            br = new BufferedReader(new InputStreamReader(is, "UTF-8"));

            StringBuffer sbf = new StringBuffer();
            String temp = null;
            while ((temp = br.readLine()) != null) {
                sbf.append(temp);
                sbf.append("\r\n");
            }
            result = sbf.toString();
        }
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (null != br) {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (null != os) {
            try {
                os.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (null != is) {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        connection.disconnect();
    }
    return result;
}

public static void main(String[] args){
    final String url = "http://{host}:{port}/personnel/api/areas/";
    final String token = "Token ae600......2b7";
    String result = doGet(url, token);
}
Prev
获取Auth Token
Next
Api Example