| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- package com.uas.eis.utils;
- import com.alibaba.fastjson.JSONObject;
- import com.fasterxml.jackson.core.JsonProcessingException;
- import com.uas.eis.core.config.DingCallbackCrypto;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.web.bind.annotation.*;
- import com.alibaba.fastjson.JSON;
- import java.util.Map;
- @RestController
- @RequestMapping("approval")
- public class ApprovalResult {
- @Value("${dingTalk.appKey}")
- private String appKey;
- @Value("${dingTalk.callToken}")
- private String callToken;
- @Value("${dingTalk.callAesKey}")
- private String callAesKey;
- @Autowired
- private OaUtils oaUtils;
- @PostMapping
- public Map<String, String> approval(@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 {
- // 1. 从http请求中获取加解密参数
- // 2. 使用加解密类型
- // Constant.OWNER_KEY 说明:
- // 1、开发者后台配置的订阅事件为应用级事件推送,此时OWNER_KEY为应用的APP_KEY。
- // 2、调用订阅事件接口订阅的事件为企业级事件推送,
- // 此时OWNER_KEY为:企业的appkey(企业内部应用)或SUITE_KEY(三方应用)
- DingCallbackCrypto callbackCrypto = new DingCallbackCrypto(callToken, callAesKey, appKey);
- String encryptMsg = json.getString("encrypt");
- String decryptMsg = callbackCrypto.getDecryptMsg(msg_signature, timeStamp, nonce, encryptMsg);
- // 3. 反序列化回调事件json数据
- JSONObject eventJson = JSON.parseObject(decryptMsg);
- String eventType = eventJson.getString("EventType");
- // 4. 根据EventType分类处理
- if ("check_url".equals(eventType)) {
- // 测试回调url的正确性
- System.out.println("测试回调url的正确性");
- } else if ("bpms_instance_change".equals(eventType)) {
- // 处理审批事件 TODO
- String processInstanceId = eventJson.get("processInstanceId").toString();
- String aeecssToken = oaUtils.getAeecssToken();
- Map<String, String> processInsDetail = oaUtils.getProcessInsDetail(processInstanceId, aeecssToken);
- System.out.println("审批事件----------------->响应结果为----------------->");
- System.out.println(aeecssToken);
- System.out.println(processInsDetail);
- System.out.println("审批事件结束----------------------------------------》");
- } else {
- // 添加其他已注册的
- System.out.println("发生了:" + eventType + "事件");
- }
- // 5. 返回success的加密数据
- Map<String, String> successMap = callbackCrypto.getEncryptedMap("success");
- return successMap;
- } catch (DingCallbackCrypto.DingTalkEncryptException | JsonProcessingException e) {
- e.printStackTrace();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
- }
|