1、注册企业账号。
2、普通企业版Demo地址:
https://github.com/ddtalk/HarleyCorp
下载后导入eclipse jdk修改为1.7
4.将您的CorpID和CorpSecret配置在Env.java文件
这2个值在钉钉OA管理后台(https://oa.dingtalk.com/)微应用》微应用设置里面5.如果测试demo代码
关键点agentid如果得来,点击微应用》应用中心》可以新建一个也可以用已有的,随便一个》点击查看agentid,都可以用来发消息。
package com.alibaba.dingtalk.openapi.demo;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.alibaba.dingtalk.openapi.demo.auth.AuthHelper;
import com.alibaba.dingtalk.openapi.demo.department.DepartmentHelper;
import com.alibaba.dingtalk.openapi.demo.media.MediaHelper;
import com.alibaba.dingtalk.openapi.demo.message.ConversationMessageDelivery;
import com.alibaba.dingtalk.openapi.demo.message.LightAppMessageDelivery;
import com.alibaba.dingtalk.openapi.demo.message.MessageHelper;
import com.alibaba.dingtalk.openapi.demo.user.User;
import com.alibaba.dingtalk.openapi.demo.user.UserHelper;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.dingtalk.open.client.api.model.corp.CorpUserDetail;
import com.dingtalk.open.client.api.model.corp.CorpUserDetailList;
import com.dingtalk.open.client.api.model.corp.CorpUserList;
import com.dingtalk.open.client.api.model.corp.Department;
import com.dingtalk.open.client.api.model.corp.MessageBody;
import com.dingtalk.open.client.api.model.corp.MessageBody.OABody.Body;
import com.dingtalk.open.client.api.model.corp.MessageBody.OABody.Body.Form;
import com.dingtalk.open.client.api.model.corp.MessageBody.OABody.Body.Rich;
import com.dingtalk.open.client.api.model.corp.MessageBody.OABody.Head;
import com.dingtalk.open.client.api.model.corp.MessageType;
import com.dingtalk.open.client.api.model.corp.UploadResult;
public class Demo {
public static void main(String[] args) throws Exception {
try {
List departments = new ArrayList();
departments = DepartmentHelper.listDepartments(AuthHelper.getAccessToken(), "1");
JSONObject usersJSON = new JSONObject();
System.out.println("depart num:"+departments.size());
for(int i = 0;i list = DepartmentHelper.listDepartments(accessToken, parentId);
log("成功获取部门列表", list);
// 更新部门
name = "hahahaha";
boolean autoAddUser = true;
String deptManagerUseridList = null;
boolean deptHiding = false;
String deptPerimits = "aa|qq";
DepartmentHelper.updateDepartment(accessToken, departmentId, name, parentId, order, createDeptGroup,
autoAddUser, deptManagerUseridList, deptHiding, deptPerimits, null,
null, null, null, null);
log("成功更新部门", " 部门id=", departmentId);
CorpUserDetail userDetail = new CorpUserDetail();
userDetail.setUserid("id_yuhuan");
userDetail.setName("name_yuhuan");
userDetail.setEmail("yuhuan@abc.com");
userDetail.setMobile("18612124567");
userDetail.setDepartment(new ArrayList());
userDetail.getDepartment().add(departmentId);
UserHelper.createUser(accessToken, userDetail);
log("成功创建成员", "成员信息=", userDetail);
// 上传图片
File file = new File("/Users/ian/Downloads/lALOAVYgbc0DIM0Bwg_450_800.png");
UploadResult uploadResult = MediaHelper.upload(accessToken, MediaHelper.TYPE_IMAGE, file);
log("成功上传图片", uploadResult);
// 下载图片
String fileDir = "/Users/ian/Desktop/";
MediaHelper.download(accessToken, uploadResult.getMedia_id(), fileDir);
log("成功下载图片");
MessageBody.TextBody textBody = new MessageBody.TextBody();
textBody.setContent("TextMessage");
MessageBody.ImageBody imageBody = new MessageBody.ImageBody();
imageBody.setMedia_id(uploadResult.getMedia_id());
MessageBody.LinkBody linkBody = new MessageBody.LinkBody();
linkBody.setMessageUrl("http://www.baidu.com");
linkBody.setPicUrl("@lALOACZwe2Rk");
linkBody.setTitle("Link Message");
linkBody.setText("This is a link message");
// 创建oa消息
MessageBody.OABody oaBody = new MessageBody.OABody();
oaBody.setMessage_url("message_url");
Head head = new Head();
head.setText("head.text");
head.setBgcolor("FFBBBBBB");
oaBody.setHead(head);
Body body = new Body();
body.setAuthor("author");
body.setContent("content");
body.setFile_count("file_count");
body.setImage("@image");
body.setTitle("body.title");
Rich rich = new Rich();
rich.setNum("num");
rich.setUnit("unit");
body.setRich(rich);
List