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();
|
}
|
}
|
}
|