一、工具和环境:eclipse+springBoot+Maven+jquery+51手机模拟器
二、阅读官方开发文档
[attachment=126183]
三、请参考帖子:【创联云】钉钉免登demo https://bbs.aliyun.com/read/317081.html?spm=0.0.0.0.xIkNnr 获取access_token
四、部门与成员查看,创建,删除方法
//获取部门列表
五、控制层访问方法代码
public String getDepartmentList(String accessToken) throws OApiException{
String url= Env.OAPI_HOST+"/department/list?access_token="+accessToken;
JSONObject response = HttpHelper.httpGet(url);
return response.toJSONString();
}
//创建部门
public void createDepartment(String accessToken, String name,
String parentId, String order, boolean createDeptGroup ) throws Exception {
CorpDepartmentService corpDepartmentService = ServiceFactory.getInstance().getOpenService(CorpDepartmentService.class);
corpDepartmentService.deptCreate(accessToken, name, parentId, order, createDeptGroup);
}
//删除部门
public void deleteDepartment(String accessToken, Long id) throws Exception{
CorpDepartmentService corpDepartmentService = ServiceFactory.getInstance().getOpenService(CorpDepartmentService.class);
corpDepartmentService.deptDelete(accessToken, id);
}
//获取部门下成员
public String getuserbydepart(String accessToken, Long id) throws Exception{
String url= Env.OAPI_HOST+"/user/simplelist?access_token="+accessToken + "&department_id=" + id;
JSONObject response = HttpHelper.httpGet(url);
return response.toJSONString();
}
//创建成员
public JSONObject createUser(String accessToken, String name,List department, String mobile) throws Exception {
JSONObject json = new JSONObject();
json.put("name", name);
json.put("department", department);
json.put("mobile", mobile);
String url = Env.OAPI_HOST + "/user/create?access_token=" + accessToken ;
JSONObject reponseJson = null;
try {
reponseJson = HttpHelper.httpPost(url,json);
} catch (OApiException e) {
e.printStackTrace();
}
return reponseJson;
}
//删除成员
public void deleteUser(String accessToken, String userid) throws Exception{
String url= Env.OAPI_HOST+"/user/delete?access_token="+accessToken + "&userid=" + userid;
JSONObject response = HttpHelper.httpGet(url);
}
@CrossOrigin
六、页面js调用
@RequestMapping("/get-departmentList")
@ResponseBody
public JSONObject getDepartmentList() throws OApiException{
return JSONObject.parseObject(serviceHelper.getDepartmentList(AuthHelper.getAccessToken()));
}
@CrossOrigin
@RequestMapping("/create-department")
@ResponseBody
public void createDepartment(String name) throws Exception{
String parentId = "1";
String order = "1";
boolean createDeptGroup = true;
serviceHelper.createDepartment(AuthHelper.getAccessToken(), name, parentId, order, createDeptGroup);
}
@CrossOrigin
@RequestMapping("/del-department")
@ResponseBody
public void deleteDepartment(Long departmentId) throws Exception{
serviceHelper.deleteDepartment(AuthHelper.getAccessToken(), departmentId);
}
@CrossOrigin
@RequestMapping("/get-user-department")
@ResponseBody
public JSONObject getuserbydepart(Long departmentId) throws Exception{
return JSONObject.parseObject(serviceHelper.getuserbydepart(AuthHelper.getAccessToken(), departmentId));
}
@CrossOrigin
@RequestMapping("/create-user")
@ResponseBody
public void createUser(String name,String departmentId,String mobile) throws Exception{
List<String> departList = new ArrayList<String>();
departList.add(departmentId);
serviceHelper.createUser(AuthHelper.getAccessToken(), name, departList, mobile);
}
@CrossOrigin
@RequestMapping("/del-userbydepartmentid")
@ResponseBody
public void deleteUser(String userId) throws Exception{
serviceHelper.deleteUser(AuthHelper.getAccessToken(), userId);
}
function getdepartmentList(){
七、模拟器演示图
$.get(
'get-departmentList',
function(result){
$("#departmentList").empty();
var html="";
$.each( result.department, function(index, depar)
{
html+= '<table align="center"><tr><td align="center" valign="middle" width="80px">'+depar.name+'</td><td align="center" valign="middle"><button class="btn" onclick="getUserList('+depar.id+')">获取部门成员</button><br/></td><td align="center" valign="middle"><button class="btn" onclick="delDepartment('+depar.id+')">删除部门</button></td></tr></table>'
});
$("#departmentList").append(html);
}
);
}
function createDepartment(){
var name = $("#deparName").val();
$.get(
'create-department',
{
"name":name
},
function(result){
getdepartmentList();
}
);
}
function delDepartment(departmentId){
$.get(
'del-department',
{
"departmentId":departmentId
},
function(result){
getdepartmentList();
}
);
}
function getUserList(departmentId){
$.get(
'get-user-department',
{
"departmentId":departmentId
},
function(result){
$("#userList").empty();
var html="";
$.each(result.userlist, function(index, user)
{
html+= '<table align="center"><tr><td align="center" valign="middle" width="100px">'+user.name+'</td><td align="center" valign="middle"><button class="btn" onclick="delUser('+user.userid+','+departmentId+')">删除成员</button><input id="departmentId" type="hidden" value="'+departmentId+'"/></td></tr></table>'
});
$("#userList").append(html);
}
);
}
function delUser(userId,departmentId){
alert(userId);
alert(departmentId);
$.get(
'del-userbydepartmentid',
{
"userId":userId
},
function(result){
getUserList(departmentId);
}
);
}
function createUser(){
var name = $("#userName").val();
var departmentId = $("#departmentId").val();
var mobile = $("#mobile").val();
$.get(
'create-user',
{
"name":name,
"departmentId":departmentId,
"mobile":mobile
},
function(result){
$("#userName").empty();
$("#mobile").empty();
getUserList(departmentId);
}
);
}
[attachment=126184]
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。