钉钉企业通知消息接口(二)

上一篇实现的是给整个部门发送消息,接下来要实现的是给具体到某个人发送消息。

接口测试平台:http://coolaf.com/

  • access_token

https://oapi.dingtalk.com/gettoken?corpid=id&corpsecret=secrect

{
    "expires_in": 7200,
    "errmsg": "ok",
    "access_token": "be3fc3e7f93736ca85058bb0dc2922f1",
    "errcode": 0
}

 

  • 获取CorpSecret授权范围 

 https://oapi.dingtalk.com/auth/scopes?access_token=6e3a682561983ea5bb3dbde04f0e9e07

{
    "auth_org_scopes": {
        "authed_dept": [
            60958364
        ],
        "authed_user": [
            
        ]
    },
    "auth_user_field": [
        "avatar",
        "department",
        "deviceId",
        "email",
        "extattr",
        "name",
        "openId",
        "position",
        "userid",
        "jobnumber",
        "mobile",
        "isAdmin",
        "isHide",
        "isLeader",
        "dingId",
        "tel",
        "remark",
        "workPlace"
    ],
    "condition_field": [
        
    ],
    "errmsg": "ok",
    "errcode": 0
}

钉钉开放平台改版以后只能拿到部门id(authed_dept),并不能拿到部门下面的员工id列表(authed_user)

authed_dept 也就是 t发送消息oparty

 

  • 获取部门详情

https://oapi.dingtalk.com/department/get?access_token=ACCESS_TOKEN&id=2
https://oapi.dingtalk.com/department/get?access_token=6e3a682561983ea5bb3dbde04f0e9e07&id=60958364

{
    "deptHiding": false,
    "parentid": 25046256,
    "outerPermitDepts": "",
    "groupContainSubDept": false,
    "deptManagerUseridList": "",
    "errcode": 0,
    "id": 60958364,
    "outerPermitUsers": "",
    "createDeptGroup": false,
    "order": 5,
    "outerDept": false,
    "name": "网络管理",
    "orgDeptOwner": "",
    "autoAddUser": false,
    "deptPerimits": "",
    "errmsg": "ok",
    "userPerimits": ""
}

 

  • 获取部门成员

https://oapi.dingtalk.com/user/simplelist?access_token=ACCESS_TOKEN&department_id=1
https://oapi.dingtalk.com/user/simplelist?access_token=6e3a682561983ea5bb3dbde04f0e9e07&department_id=60958364

{
    "userlist": [
        {
            "name": "小综(测试使用)",
            "userid": "1801284365-280247429"
        },
        {
            "name": "王灵生",
            "userid": "370523199206072410"
        },
        {
            "name": "张杰",
            "userid": "15227411782879353"
        },
        {
            "name": "卢蒙蒙",
            "userid": "071466652721599746"
        }
    ],
    "errmsg": "ok",
    "errcode": 0
}

 

  • 企业发送消息 (POST)

https://oapi.dingtalk.com/message/send?access_token=ACCESS_TOKEN

https://oapi.dingtalk.com/message/send?access_token=6e3a682561983ea5bb3dbde04f0e9e07

 

Header中默认是 Content-Type:application/x-www-form-urlencoded

POST请求请在HTTP Header中设置 Content-Type:application/json,否则接口调用失败。

 

POST参数:

{
"touser":"370523199206072410", //员工id列表(消息接收者,多个接收者用|分隔)
"toparty":"", //部门id列表,多个接收者用|分隔。touser或者toparty 二者有一个必填,不支持递归发送,如果需要给部门下面子部门发送消息则需要查询出子部门id
"agentid":"188024843", //企业应用id,这个值代表以哪个应用的名义发送消息,
"msgtype":"text",
"text":{
	"content":"车辆管理系统消息推送测试"
}

}


//简化以后的:

{
"touser":"370523199206072410", 
"toparty":"", 
"agentid":"188024843", 
"msgtype":"text",
"text":{
	"content":"车辆管理系统消息推送测试"
}
}

touser和toparty 必填一个

发送部门个人消息结果:

{
    "invalidparty": "",
    "forbiddenUserId": "15227411782879353|370523199206072410|1801284365-280247429|071466652721599746",
    "messageId": "71bb5b9e9254304cb94b8808429ecc0a",
    "errmsg": "ok",
    "invaliduser": "",
    "errcode": 0
}

 

出现 forbiddenUserId 表示发送消息接口被限流了

限流规则包括:1、给同一用户发相同内容消息一天仅允许一次;2、给同一用户发消息一天不超过100次

https://open-doc.dingtalk.com/docs/doc.htm?spm=a2c4e.11155515.0.0.uSoVc4&treeId=172&articleId=104973&docType=1

 

 

 

 

你可能感兴趣的:(钉钉)