Search in sources :

Example 6 with DefaultDingTalkClient

use of com.dingtalk.api.DefaultDingTalkClient in project dingtalk-app-server by nju-softeng.

the class OAApi method deleteAbsentOA.

public boolean deleteAbsentOA(String processInstanceId, User user) {
    try {
        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/process/instance/terminate");
        OapiProcessInstanceTerminateRequest req = new OapiProcessInstanceTerminateRequest();
        OapiProcessInstanceTerminateRequest.TerminateProcessInstanceRequestV2 processInstanceRequestV2 = new OapiProcessInstanceTerminateRequest.TerminateProcessInstanceRequestV2();
        processInstanceRequestV2.setProcessInstanceId(processInstanceId);
        processInstanceRequestV2.setIsSystem(false);
        processInstanceRequestV2.setRemark("取消请假");
        processInstanceRequestV2.setOperatingUserid(user.getUserid());
        req.setRequest(processInstanceRequestV2);
        OapiProcessInstanceTerminateResponse rsp = client.execute(req, getAccessToken());
        return rsp.getResult();
    } catch (Exception e) {
        throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
    }
}
Also used : DefaultDingTalkClient(com.dingtalk.api.DefaultDingTalkClient) OapiProcessInstanceTerminateResponse(com.dingtalk.api.response.OapiProcessInstanceTerminateResponse) OapiProcessInstanceTerminateRequest(com.dingtalk.api.request.OapiProcessInstanceTerminateRequest) DefaultDingTalkClient(com.dingtalk.api.DefaultDingTalkClient) DingTalkClient(com.dingtalk.api.DingTalkClient) ResponseStatusException(org.springframework.web.server.ResponseStatusException) ApiException(com.taobao.api.ApiException) ResponseStatusException(org.springframework.web.server.ResponseStatusException)

Example 7 with DefaultDingTalkClient

use of com.dingtalk.api.DefaultDingTalkClient in project MaxKey by dromara.

the class DingtalkOrganizationService method requestDepartmentList.

public OapiV2DepartmentListsubResponse requestDepartmentList(String access_token, Long deptId) throws ApiException {
    DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/listsub");
    OapiV2DepartmentListsubRequest req = new OapiV2DepartmentListsubRequest();
    req.setDeptId(deptId);
    req.setLanguage("zh_CN");
    OapiV2DepartmentListsubResponse rspDepts = client.execute(req, access_token);
    _logger.trace("response : " + rspDepts.getBody());
    return rspDepts;
}
Also used : OapiV2DepartmentListsubResponse(com.dingtalk.api.response.OapiV2DepartmentListsubResponse) DefaultDingTalkClient(com.dingtalk.api.DefaultDingTalkClient) DefaultDingTalkClient(com.dingtalk.api.DefaultDingTalkClient) DingTalkClient(com.dingtalk.api.DingTalkClient) OapiV2DepartmentListsubRequest(com.dingtalk.api.request.OapiV2DepartmentListsubRequest)

Example 8 with DefaultDingTalkClient

use of com.dingtalk.api.DefaultDingTalkClient in project MaxKey by dromara.

the class DingtalkOrganizationService method requestDepartment.

public OapiV2DepartmentGetResponse requestDepartment(String access_token, Long deptId) throws ApiException {
    DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/get");
    OapiV2DepartmentGetRequest req = new OapiV2DepartmentGetRequest();
    req.setDeptId(deptId);
    req.setLanguage("zh_CN");
    OapiV2DepartmentGetResponse rspDepts = client.execute(req, access_token);
    _logger.trace("response : " + rspDepts.getBody());
    return rspDepts;
}
Also used : DefaultDingTalkClient(com.dingtalk.api.DefaultDingTalkClient) OapiV2DepartmentGetRequest(com.dingtalk.api.request.OapiV2DepartmentGetRequest) OapiV2DepartmentGetResponse(com.dingtalk.api.response.OapiV2DepartmentGetResponse) DefaultDingTalkClient(com.dingtalk.api.DefaultDingTalkClient) DingTalkClient(com.dingtalk.api.DingTalkClient)

Example 9 with DefaultDingTalkClient

use of com.dingtalk.api.DefaultDingTalkClient in project MaxKey by dromara.

the class DingtalkUsersService method sync.

public void sync() {
    _logger.info("Sync Dingtalk Users...");
    try {
        List<SynchroRelated> synchroRelateds = synchroRelatedService.findOrgs(this.synchronizer);
        for (SynchroRelated relatedOrg : synchroRelateds) {
            DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/list");
            OapiV2UserListRequest req = new OapiV2UserListRequest();
            _logger.debug("DingTalk deptId : {}", relatedOrg.getOriginId());
            req.setDeptId(Long.parseLong(relatedOrg.getOriginId()));
            req.setCursor(0L);
            req.setSize(100L);
            req.setOrderField("modify_desc");
            req.setContainAccessLimit(true);
            req.setLanguage("zh_CN");
            OapiV2UserListResponse rsp = client.execute(req, access_token);
            _logger.trace("response : {}", rsp.getBody());
            if (rsp.getErrcode() == 0) {
                for (ListUserResponse user : rsp.getResult().getList()) {
                    _logger.debug("name : {} , {} , {}", user.getName(), user.getLoginId(), user.getUserid());
                    UserInfo userInfo = buildUserInfo(user, relatedOrg);
                    _logger.trace("userInfo {}", userInfo);
                    userInfo.setPassword(userInfo.getUsername() + UserInfo.DEFAULT_PASSWORD_SUFFIX);
                    userInfoService.saveOrUpdate(userInfo);
                    SynchroRelated synchroRelated = new SynchroRelated(userInfo.getId(), userInfo.getUsername(), userInfo.getDisplayName(), UserInfo.CLASS_TYPE, synchronizer.getId(), synchronizer.getName(), user.getUnionid(), user.getName(), user.getUserid(), "", synchronizer.getInstId());
                    synchroRelatedService.updateSynchroRelated(this.synchronizer, synchroRelated, UserInfo.CLASS_TYPE);
                    socialsAssociate(synchroRelated, "dingtalk");
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : OapiV2UserListRequest(com.dingtalk.api.request.OapiV2UserListRequest) DefaultDingTalkClient(com.dingtalk.api.DefaultDingTalkClient) ListUserResponse(com.dingtalk.api.response.OapiV2UserListResponse.ListUserResponse) SynchroRelated(org.maxkey.entity.SynchroRelated) UserInfo(org.maxkey.entity.UserInfo) OapiV2UserListResponse(com.dingtalk.api.response.OapiV2UserListResponse) DefaultDingTalkClient(com.dingtalk.api.DefaultDingTalkClient) DingTalkClient(com.dingtalk.api.DingTalkClient)

Example 10 with DefaultDingTalkClient

use of com.dingtalk.api.DefaultDingTalkClient in project metersphere by metersphere.

the class DingNoticeSender method sendNailRobot.

public void sendNailRobot(MessageDetail messageDetail, NoticeModel noticeModel, String context) {
    List<Receiver> receivers = noticeModel.getReceivers();
    DingTalkClient client = new DefaultDingTalkClient(messageDetail.getWebhook());
    OapiRobotSendRequest request = new OapiRobotSendRequest();
    request.setMsgtype("text");
    OapiRobotSendRequest.Text text = new OapiRobotSendRequest.Text();
    text.setContent("消息通知: \n" + context);
    request.setText(text);
    if (CollectionUtils.isNotEmpty(receivers)) {
        OapiRobotSendRequest.At at = new OapiRobotSendRequest.At();
        List<String> userIds = receivers.stream().map(Receiver::getUserId).distinct().collect(Collectors.toList());
        List<String> phoneList = super.getUserDetails(userIds).stream().map(UserDetail::getPhone).distinct().collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(phoneList)) {
            LogUtil.info("钉钉收件人地址: {}", userIds);
            at.setAtMobiles(phoneList);
            request.setAt(at);
        }
    }
    try {
        client.execute(request);
    } catch (ApiException e) {
        LogUtil.error(e.getMessage(), e);
    }
}
Also used : DefaultDingTalkClient(com.dingtalk.api.DefaultDingTalkClient) Receiver(io.metersphere.notice.domain.Receiver) DefaultDingTalkClient(com.dingtalk.api.DefaultDingTalkClient) DingTalkClient(com.dingtalk.api.DingTalkClient) UserDetail(io.metersphere.notice.domain.UserDetail) OapiRobotSendRequest(com.dingtalk.api.request.OapiRobotSendRequest) ApiException(com.taobao.api.ApiException)

Aggregations

DefaultDingTalkClient (com.dingtalk.api.DefaultDingTalkClient)13 DingTalkClient (com.dingtalk.api.DingTalkClient)13 ApiException (com.taobao.api.ApiException)9 OapiRobotSendRequest (com.dingtalk.api.request.OapiRobotSendRequest)6 Mac (javax.crypto.Mac)3 SecretKeySpec (javax.crypto.spec.SecretKeySpec)3 ResponseStatusException (org.springframework.web.server.ResponseStatusException)3 OapiGettokenRequest (com.dingtalk.api.request.OapiGettokenRequest)1 OapiProcessInstanceTerminateRequest (com.dingtalk.api.request.OapiProcessInstanceTerminateRequest)1 OapiProcessinstanceCreateRequest (com.dingtalk.api.request.OapiProcessinstanceCreateRequest)1 OapiProcessinstanceGetRequest (com.dingtalk.api.request.OapiProcessinstanceGetRequest)1 OapiV2DepartmentGetRequest (com.dingtalk.api.request.OapiV2DepartmentGetRequest)1 OapiV2DepartmentListsubRequest (com.dingtalk.api.request.OapiV2DepartmentListsubRequest)1 OapiV2UserListRequest (com.dingtalk.api.request.OapiV2UserListRequest)1 OapiGettokenResponse (com.dingtalk.api.response.OapiGettokenResponse)1 OapiProcessInstanceTerminateResponse (com.dingtalk.api.response.OapiProcessInstanceTerminateResponse)1 OapiProcessinstanceCreateResponse (com.dingtalk.api.response.OapiProcessinstanceCreateResponse)1 OapiProcessinstanceGetResponse (com.dingtalk.api.response.OapiProcessinstanceGetResponse)1 OapiV2DepartmentGetResponse (com.dingtalk.api.response.OapiV2DepartmentGetResponse)1 OapiV2DepartmentListsubResponse (com.dingtalk.api.response.OapiV2DepartmentListsubResponse)1