数字工厂中系统管理员能通过设置中心的权限管理为企业的数字工厂管理登录账号,定义和授予用户角色权限。数字工厂账号和权限集成详细请查看SaaS应用租户对接

查询

获取全部角色列表,接口详细描述

java demo

import com.alibaba.cloudapi.sdk.model.ApiResponse;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.iotx.api.client.IoTApiClientBuilderParams;
import com.aliyun.iotx.api.client.IoTApiRequest;
import com.aliyun.iotx.api.client.SyncApiClient;
import org.apache.commons.collections4.CollectionUtils;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;

public class DemoApplication {

    private static String postBody(String path, IoTApiRequest request, Map<String, String> headers) {
        String appKey = "";
        String appSecret = "";

        IoTApiClientBuilderParams ioTApiClientBuilderParams = new IoTApiClientBuilderParams();

        ioTApiClientBuilderParams.setAppKey(appKey);
        ioTApiClientBuilderParams.setAppSecret(appSecret);

        SyncApiClient syncApiClient = new SyncApiClient(ioTApiClientBuilderParams);

        try {
            //设置请求参数域名、path、request ,如果使用HTTPS,设置为true
            ApiResponse response = syncApiClient.postBody("api.link.aliyun.com", path, request, true, headers);
            String responseString = new String(response.getBody(), "UTF-8");
            System.out.println("response code = " + response.getCode() + " response = " + responseString);
            return responseString;
        } catch (UnsupportedEncodingException uee) {
            System.out.println(uee.getMessage());
            uee.printStackTrace();
            return null;
        }
    }

    public static void main(String[] args) {
        IoTApiRequest request = new IoTApiRequest();
        //设置协议版本号
        request.setVersion("1.0");
        String uuid = UUID.randomUUID().toString();
        String id = uuid.replace("-", "");
        //设置请求ID
        request.setId(id);
        System.out.println("id = " + id);
        //设置API版本号
        request.setApiVer("1.0.1");

        Map<String, String> headers = new HashMap<>();

        String path = "/industry/user/role/all/list";
        String metaDataListString = postBody(path, request, headers);
        JSONObject jsonData = JSON.parseObject(metaDataListString);

        int code = jsonData.getInteger("code");
        if (code == 200) {
            JSONArray dtoList = jsonData.getJSONArray("data");
            dtoList.stream().forEach(dto -> System.out.print("角色: " + dto.toJSONString()));
        }
    }
}

组织树查询,接口详细描述

分页查询账号列表,接口详细描述

获取账号信息,接口详细描述

变更订阅通知

集成工作概述中的数据变更通知订阅说明了接口的使用方式,其中serviceType参数设置为2,表示账号、组织和角色数据通知,action分别对应新增/修改/删除操作,data是一个json对象或对象数组,根据type参数表示不同类型的数据,账号、组织和角色数据格式与查询接口返回的数据对象一致。

账号数据通知格式

{
  "appId": "xxxxx",//对于SaaS应用,这个对应的是应用的实例id
  "serviceType": 2,//对于账号、组织和角色权限固定为2
  "action": "INSERT"/"MODIFY"/"DELETE",
  "data": {
    "organizationId": "xxxxxxxx",
    "organizationShowName": "研发部",
    "roleCode": "ADMINISTRATOR",
    "roleName": "系统集成商",
    "auid": "xxxxxx",
    "phone": "xxxxxxx",
    "email": "test_1@xxxxx.com",
    "nickName": "tpc",
    "admin": false,
    "main": false,
    "roleList": [
      {
        "roleCode": "ADMINISTRATOR",
        "roleName": "系统集成商"
      }
    ],
    "orgList": [
      {
        "organizationId": "xxxxxx",
        "organizationName": "研发部"
      }
    ]
  }
}

组织变更通知格式

{
  "appId": "xxxxx",//对于SaaS应用,这个对应的是应用的实例id
  "serviceType": 2,//对于账号、组织和角色权限固定为2
  "action": "INSERT"/"MODIFY"/"DELETE",
  "data": {
    "organizationId": "xxxxx",
    "organizationName": "公司",
    "order": 1,
    "parentId": null,
    "childList": [
      {
        "organizationId": "xxxxx",
        "organizationName": "工厂",
        "order": 1,
        "creator": null,
        "modifier": null,
        "leaf": false,
        "parentId": "xxxxx",
        "childList": [
          {
            "organizationId": "xxxxx",
            "organizationName": "财务部",
            "order": 1,
            "parentId": "xxxxx",
            "leaf": true,
            "childList": null
          },
          {
            "organizationId": "xxxxx",
            "organizationName": "生产部",
            "order": 2,
            "parentId": "xxxxx",
            "leaf": true,
            "childList": null
          }
        ]
      }
    ]
  }
}

角色变更通知格式

{
  "appId": "xxxxx",//对于SaaS应用,这个对应的是应用的实例id
  "serviceType": 2,//对于账号、组织和角色权限固定为2
  "action": "INSERT"/"MODIFY"/"DELETE",
  "data": {
      "roleCode": "xxxx_FF0E86C1DA8446009A5581844C244097_xxxx",
      "roleName": "车间主管"
    }
}