yangys
2024-05-07 ec2552d891e163bd9054e0554188afc575bcdb70
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
package com.qianwen.smartman.modules.sync.controller;
 
import com.alibaba.fastjson.JSONObject;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.qianwen.smartman.common.constant.CommonConstant;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.modules.sync.constant.DingConstant;
import com.qianwen.smartman.modules.sync.constant.OuterAppConfigConstant;
import com.qianwen.smartman.modules.sync.constant.QyWechatConstant;
import com.qianwen.smartman.modules.sync.entity.OuterAppConfig;
import com.qianwen.smartman.modules.sync.service.IDingEventService;
import com.qianwen.smartman.modules.sync.service.IOuterAppConfigService;
import com.qianwen.smartman.modules.sync.util.DingCallbackCrypto;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
@RequestMapping({"blade-sync/ding"})
@RestController
public class DingEventCallBackController {
    private static final Logger log = LoggerFactory.getLogger(DingEventCallBackController.class);
    private final IDingEventService dingEventService;
    private final IOuterAppConfigService outerAppConfigService;
 
    public DingEventCallBackController(final IDingEventService dingEventService, final IOuterAppConfigService outerAppConfigService) {
        this.dingEventService = dingEventService;
        this.outerAppConfigService = outerAppConfigService;
    }
 
    @PostMapping({"dingCallback"})
    public Map<String, String> callBack(HttpServletRequest request, @RequestParam(value = "msg_signature", required = false) String msg_signature, @RequestParam(value = "timestamp", required = false) String timeStamp, @RequestParam(value = "nonce", required = false) String nonce, @RequestBody(required = false) JSONObject json) {
        try {
            OuterAppConfig outerAppConfig = this.outerAppConfigService.getAppConfig(OuterAppConfigConstant.DING);
            DingCallbackCrypto callbackCrypto = new DingCallbackCrypto(outerAppConfig.getDingCallbackToken(), outerAppConfig.getDingAesKey(), outerAppConfig.getDingAppKey());
            if (Func.isNotEmpty(outerAppConfig) && outerAppConfig.getStatus().equals(CommonConstant.ENABLE)) {
                String encryptMsg = json.getString("encrypt");
                String decryptMsg = callbackCrypto.getDecryptMsg(msg_signature, timeStamp, nonce, encryptMsg);
                this.dingEventService.handleEvent(callbackCrypto, decryptMsg, outerAppConfig);
            }
            Map<String, String> successMap = callbackCrypto.getEncryptedMap(QyWechatConstant.CALLBACK_RESULT);
            return successMap;
        } catch (DingCallbackCrypto.DingTalkEncryptException e) {
            e.printStackTrace();
            return null;
        }
    }
 
    public static void main(String[] args) {
        try {
            DingCallbackCrypto callbackCrypto = new DingCallbackCrypto(DingConstant.AES_TOKEN, DingConstant.AES_KEY, DingConstant.OWNER_KEY);
            String result = callbackCrypto.getDecryptMsg(DingConstant.AES_TOKEN, "1660726099662", "NSSkKApu", "bg0JooSnFmsmy605VIHDnp2u1QFCrkYhdUUJ75miOvpDFANCzDP2YuE3J7o2rorRRAriRqnnmI4IxNsVJDCU62Ym5zwCoYX5sTiAG5PRX2NXnf3tKoBwqkDnGDgtIdH9JbzGOVaUHnEzb4aibDXPlbe/VdXeyJCmHSA/mE0V6j2CGn2jkVrlK0PDGS+tdb9HP/SlJWWuya6agC29dD7hLmlRqYjrZ8NciAYWpTRJrVForDpoQlHOuCgrQO2/tyq8");
            System.out.println(result);
        } catch (DingCallbackCrypto.DingTalkEncryptException e) {
            e.printStackTrace();
        }
    }
}