yangys
2024-03-28 25475f31cd0d52ff328bbea9e80f15647dedd80b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package com.qianwen.smartman.modules.notify.api;
 
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.request.OapiGettokenRequest;
import com.dingtalk.api.request.OapiV2DepartmentGetRequest;
import com.dingtalk.api.request.OapiV2UserGetbymobileRequest;
import com.dingtalk.api.response.OapiGettokenResponse;
import com.dingtalk.api.response.OapiV2DepartmentGetResponse;
import com.dingtalk.api.response.OapiV2UserGetbymobileResponse;
import com.taobao.api.ApiException;
import java.lang.invoke.SerializedLambda;
import java.util.Map;
import com.qianwen.core.notify.DefaultNotifyType;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.modules.notify.entity.NotifyConfigEntity;
import com.qianwen.smartman.modules.notify.service.INotifyConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
 
@Component
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/notify/api/DingTalkApi.class */
public class DingTalkApi {
    @Autowired
    @Lazy
    private INotifyConfigService notifyConfigService;
 
    private static /* synthetic */ Object $deserializeLambda$(SerializedLambda lambda) {
        String implMethodName = lambda.getImplMethodName();
        boolean z = true;
        switch (implMethodName.hashCode()) {
            case -75106384:
                if (implMethodName.equals("getType")) {
                    z = false;
                    break;
                }
                break;
            case 803533544:
                if (implMethodName.equals("getStatus")) {
                    z = true;
                    break;
                }
                break;
        }
        switch (z) {
            case false:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/notify/entity/NotifyConfigEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getType();
                    };
                }
                break;
            case true:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
                    return (v0) -> {
                        return v0.getStatus();
                    };
                }
                break;
        }
        throw new IllegalArgumentException("Invalid lambda deserialization");
    }
 
    public String getToken() {
        DingTalkConfig dingTalkDTO = getDingTalkConfig();
        try {
            DefaultDingTalkClient defaultDingTalkClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
            OapiGettokenRequest req = new OapiGettokenRequest();
            req.setHttpMethod("GET");
            req.setAppkey(dingTalkDTO.getAppkey());
            req.setAppsecret(dingTalkDTO.getAppsecret());
            OapiGettokenResponse rsp = defaultDingTalkClient.execute(req);
            if (Func.equals(rsp.getErrorCode(), "0")) {
                return rsp.getAccessToken();
            }
            return null;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
 
    public String getUserIdByMobile(String mobile) {
        try {
            DefaultDingTalkClient defaultDingTalkClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/getbymobile");
            OapiV2UserGetbymobileRequest req = new OapiV2UserGetbymobileRequest();
            req.setMobile(mobile);
            OapiV2UserGetbymobileResponse rsp = defaultDingTalkClient.execute(req, getToken());
            OapiV2UserGetbymobileResponse.UserGetByMobileResponse result = rsp.getResult();
            return Func.equals(rsp.getErrorCode(), "0") ? result.getUserid() : "";
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }
 
    private DingTalkConfig getDingTalkConfig() {
        NotifyConfigEntity config = (NotifyConfigEntity) this.notifyConfigService.getOne((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getType();
        }, DefaultNotifyType.dingTalk.name())).eq((v0) -> {
            return v0.getStatus();
        }, 1));
        Map<String, Object> configuration = config.getConfiguration();
        Object appKey = configuration.get("appKey");
        Object appSecret = configuration.get("appSecret");
        DingTalkConfig dingTalkConfig = new DingTalkConfig();
        dingTalkConfig.setAppkey(String.valueOf(appKey));
        dingTalkConfig.setAppsecret(String.valueOf(appSecret));
        return dingTalkConfig;
    }
 
    public String getCompanyName() {
        DefaultDingTalkClient defaultDingTalkClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/get");
        OapiV2DepartmentGetRequest req = new OapiV2DepartmentGetRequest();
        req.setDeptId(1L);
        req.setLanguage("zh_CN");
        try {
            OapiV2DepartmentGetResponse rsp = defaultDingTalkClient.execute(req, getToken());
            if (Func.equals(rsp.getErrorCode(), "0")) {
                OapiV2DepartmentGetResponse.DeptGetResponse result = rsp.getResult();
                return result.getName();
            }
            return "";
        } catch (ApiException e) {
            e.printStackTrace();
            return "";
        }
    }
}