数字工厂提供第三方应用把提醒、故障和报警消息通知到指定员工、组织或者角色。

比如说物料管理的第三方应用判断A类原材料低于安全库存水位以后会自动创建补货单,同时需要发出报警消息通知到“原材料仓管员”这样的角色,那么首先通过应用鉴权获得角色列表,然后提供页面选择“原材料管理员”这个角色,获得角色标识以后,可以通过消息集成接口发送报警消息。

消息集成方法请参看触发用户自定义内容和级别的报警消息

Demo代码参考

public class AlarmApplication {

    public static String postBody(String path, IoTApiRequest request, Map<String, String> headers) {

        IoTApiClientBuilderParams ioTApiClientBuilderParams = new IoTApiClientBuilderParams();

        ioTApiClientBuilderParams.setAppKey("");
        ioTApiClientBuilderParams.setAppSecret("");

        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);
            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.0");

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

        String path = "/industry/message/alarm/triggerByContent";
        request.putParam("level", 0);
        request.putParam("title", "testTitle");
        request.putParam("content", "testContent");
        request.putParam("receiverType", "role");
        request.putParam("receiverList", Arrays.asList("role1", "role2", "role3"));
        String response = postBody(path, request, headers);
        System.out.println(response);
    }
}