菜单
HTTP数据接口 > API Reference > token与权限
token与权限 最近更新时间:2022-08-29 16:14:14

# 接口描述

本接口为登陆与权限接口。
通过调用此接口可以获得权限token与权限相关说明。
获取的token存在有效期,请及时更新。
请求所需要的账号与密码请与项目工程师或销售服务人员联系获取。

# 接口调用

  •       POST /api/permission/token HTTP/1.1
    Host: dev.thuwater.com
    Content-Type: application/x-www-form-urlencoded
    
    username=xxxx&password=yyyy
  •       servers:
      - url: https://dev.thuwater.com
        description: 域名
    paths:
      /api/permission/token:
        post:
          tags:
            - token与权限
          summary: 登陆,获取token与权限信息
          description: 登陆,获取token与权限信息
          operationId: token
          requestBody:
            description: 请求体
            required: true
            content:
              application/x-www-form-urlencoded:
                schema:
                  type: object
                  properties:
                    username:
                      type: string
                      description: 用户名,请与项目工程师或销售服务人员联系获取。
                    password:
                      type: string
                      description: 密码,请与项目工程师或销售服务人员联系获取。
  •       var request = require("request");
    
    var options = {
      method: 'POST',
      url: 'https://dev.thuwater.com/api/permission/token',
      headers: {
        'Host': 'dev.thuwater.com',
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      form: { username: 'xxxx', password: 'yyyy' }
    };
    
    request(options, function (error, response, body) {
      if (error) throw new Error(error);
      console.log(body);
    });
  •       OkHttpClient client = new OkHttpClient();
    
    MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
    RequestBody body = RequestBody.create(mediaType, "username=xxxx&password=yyyy");
    Request request = new Request.Builder()
      .url("https://dev.thuwater.com/api/permission/token")
      .post(body)
      .addHeader("Content-Type", "application/x-www-form-urlencoded")
      .addHeader("Host", "dev.thuwater.com")
      .build();
    
    Response response = client.newCall(request).execute();

# 调用参数

参数名称必填说明
username用户名,请与项目工程师或销售服务人员联系获取。
password密码,请与项目工程师或销售服务人员联系获取。

# 接口响应

  •       HTTP/1.1 200 OK
    Content-Type: application/json
    
    {
        "token": "26b0e5bfcbc.214ce96c1f7c9f0a33549b81087579b38b6a8.e9ba17523a25d766",
        "username": "xxxx",
        "projects": "20190010,20190011",
        "places": "6513,5777,5778",
        "validDate": "2019-10-08 01:01:01",
        "valid": true
    }

# 响应参数

参数名称说明
httpcode200-正常,401-无权限,500-其他错误。
token用于后续请求的权限验证,注意token长度是不一定的。
username当前用户名。
projects当前用户有权限的项目ID列表。
places当前用户有权限的点位ID例表。
validDate当前token的过期时间,请在过期前及时刷新token,旧token在获取新token后依然有效,直到过期。
validtrue说明用户名密码正确,false说明用户名密码不正确。

token存在有效期,调用后续接口的时候注意当token过期时及时更新