95 lines
3.8 KiB
Java
95 lines
3.8 KiB
Java
package com.evo.common.controller;
|
||
|
||
import com.alibaba.fastjson2.JSON;
|
||
import com.alibaba.fastjson2.JSONArray;
|
||
import com.alibaba.fastjson2.JSONObject;
|
||
import com.evo.attendance.processor.impl.KQDeviceExchangeProcessor;
|
||
import com.evo.attendance.service.IRzAttendanceService;
|
||
import com.evo.common.core.controller.BaseController;
|
||
import com.evo.common.utils.StringUtils;
|
||
import com.evo.ding.DingGlobalParams;
|
||
import com.evo.ding.DingCallbackCrypto;
|
||
import lombok.extern.slf4j.Slf4j;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.scheduling.annotation.Async;
|
||
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.RestController;
|
||
|
||
import javax.annotation.Resource;
|
||
import java.util.Map;
|
||
|
||
/**
|
||
* CallbackController
|
||
*
|
||
* @author andy.shi
|
||
* @ClassName:CallbackController
|
||
* @date: 2026年03月04日 11:27
|
||
* @remark: 开发人员联系方式 1042025947@qq.com/微信同步
|
||
*/
|
||
@RestController
|
||
@RequestMapping("/callback")
|
||
@Slf4j
|
||
public class CallbackController extends BaseController {
|
||
|
||
|
||
@Autowired
|
||
IRzAttendanceService rzAttendanceService;
|
||
|
||
@PostMapping("/ding/clock")
|
||
public Map<String, String> dingDingClock(@RequestBody Map<String, Object> params){
|
||
System.out.println(JSONObject.toJSONString(params));
|
||
try {
|
||
// 1. 从http请求中获取加解密参数
|
||
|
||
// 2. 使用加解密类型
|
||
// 2、调用订阅事件接口订阅的事件为企业级事件推送,此时OWNER_KEY为:开发者后台应用的Client ID(原企业内部应用 appKey )
|
||
DingCallbackCrypto callbackCrypto = new DingCallbackCrypto(DingGlobalParams.getToken(), DingGlobalParams.getAesKey(), DingGlobalParams.getClientId());
|
||
String encryptMsg = String.valueOf(params.get("encrypt"));
|
||
String decryptMsg = callbackCrypto.getDecryptMsg(String.valueOf(params.get("msg_signature")), String.valueOf(params.get("timestamp")), String.valueOf(params.get("nonce")), encryptMsg);
|
||
|
||
System.out.println("==============>"+decryptMsg);
|
||
// 3. 反序列化回调事件json数据
|
||
JSONObject eventJson = JSON.parseObject(decryptMsg);
|
||
String eventType = eventJson.getString("EventType");
|
||
|
||
// 4. 根据EventType分类处理
|
||
if ("check_url".equals(eventType)) {
|
||
// 测试回调url的正确性
|
||
log.info("测试回调url的正确性");
|
||
} else if ("attendance_check_record".equals(eventType)) { //打卡推送
|
||
JSONArray dataList = eventJson.getJSONArray("DataList");
|
||
if(dataList!= null && dataList.size() > 0){
|
||
JSONObject jsonObject = dataList.getJSONObject(0);
|
||
String userId = jsonObject.getString("userId");
|
||
if(StringUtils.isNotEmpty(userId)){
|
||
rzAttendanceService.dingDing(userId, jsonObject.getString("bizId"));
|
||
}
|
||
}
|
||
//加班审批订阅
|
||
}else if ("bpms_instance_change".equals(eventType)) {
|
||
|
||
|
||
// 处理通讯录用户增加事件
|
||
}else if ("user_add_org".equals(eventType)) {
|
||
// 处理通讯录用户增加事件
|
||
log.info("发生了:" + eventType + "事件");
|
||
|
||
|
||
} else {
|
||
// 添加其他已注册的
|
||
log.info("发生了:" + eventType + "事件");
|
||
}
|
||
|
||
// 5. 返回success的加密数据
|
||
Map<String, String> successMap = callbackCrypto.getEncryptedMap("success");
|
||
return successMap;
|
||
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
return null;
|
||
}
|
||
}
|