项目对接浙政钉发送工作消息到浙政钉用户
一:项目背景
项目需要将设备采集的异常信息,推送给浙政钉的运维用户。
二对接浙政钉消息组件
- 首先需要注册isv,注册地址为 专有钉钉门户 (dg-work.cn),完成注册1到3个工作日,平台会将账号密码以短信方式通知, 然后登录管理平台后创建组织,组织成员的添加。
- 登录开放平台(注意管理工作台与开放平台的区别,开放平台用于创建应用以及组件开发等)
- 进入系统后开始创建应用
进入应用详情会生成 appley 跟 secret用户本地环境测试
点击文档中心下载需要的组件的sdk
将下载的sd集成到本地项目,以工作消息通知为例,进行对接
客户端调用demo
public class IntelligentClientTest {
private static ExecutableClient executableClient;
static {
executableClient = ExecutableClient.getInstance();
//DomainName不同环境对应不同域名,示例为sass域名
executableClient.setDomainName("openplatform.dg-work.cn");
executableClient.setProtocal("https");
//应用App Key
executableClient.setAccessKey("App Key");
//应用App Secret
executableClient.setSecretKey("App Secret");
executableClient.init();
}
public static void main(String[] args) {
//executableClient保证单例
IntelligentGetClient intelligentGetClient = executableClient.newIntelligentGetClient("/message/workNotification");
OapiMessageWorkNotificationRequest oapiMessageWorkNotificationRequest = new OapiMessageWorkNotificationRequest();
//接收者的部门id列表
oapiMessageWorkNotificationRequest.setOrganizationCodes("字符串");
//接收人用户ID
oapiMessageWorkNotificationRequest.setReceiverIds("字符串");
//租户ID
oapiMessageWorkNotificationRequest.setTenantId("字符串");
//业务消息id
oapiMessageWorkNotificationRequest.setBizMsgId("字符串");
//消息对象
oapiMessageWorkNotificationRequest.setMsg("字符串");
//获取结果
OapiMessageWorkNotificationResponse apiResult = intelligentGetClient.get(oapiMessageWorkNotificationRequest);
}
}
成功返回案例
{
"success": true,
"content": "{\"success\":true,\"content\":{\"msgId\":\"aeb07a615a5e4294a55d65925f84bb3a\"}}"
}
特别注意消息内容必须为json格式,按照此格式填充消息发送内容
{
"msgtype": "text",
"text": {
"content": "张三的请假申请"
}
}
其中参数配置做一下:domainName :测试环境为专有钉钉域名 openplatform.dg-work.cn
tenantId:通过登录管理平台。任意右击获取网页源码,中realmId 即为租户id
App key 和 app secret 为创建应用应用详情里面的参数.完成配置后进行测试 注意通知的用户id为人员账号的(uid)
进行测试结果为