|
|
@@ -0,0 +1,56 @@
|
|
|
+package com.uas.eis.controller;
|
|
|
+
|
|
|
+import com.uas.eis.beans.arg.CrmCallBackArg;
|
|
|
+import com.uas.eis.beans.result.CrmCallBackResult;
|
|
|
+import com.uas.eis.utils.SignUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+@RequestMapping("/event/")
|
|
|
+public class EventCallbackController extends BaseController{
|
|
|
+ private static final String SUCCESS = "success";
|
|
|
+ private String aesKey = "cXdlcnR5dWlvcGFzZGZnaGprbHp4Y3Zibm1xd2VycXc=";
|
|
|
+
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping(value = "crmCallback", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
|
|
|
+ public CrmCallBackResult crmCallBack(CrmCallBackArg arg) throws Exception {
|
|
|
+ Integer retryTimes = arg.getRetryTimes();
|
|
|
+ String signature = null;
|
|
|
+ if (retryTimes != null) {
|
|
|
+ signature = SignUtil.shaEncode(arg.getTimestamp() + arg.getNonce() + arg.getMessageId() + retryTimes + arg.getEnterpriseAccount() + arg.getEncryptedContent() + aesKey);
|
|
|
+ } else {
|
|
|
+ signature = SignUtil.shaEncode(arg.getTimestamp() + arg.getNonce() + arg.getMessageId() + arg.getEnterpriseAccount() + arg.getEncryptedContent() + aesKey);
|
|
|
+ }
|
|
|
+ //校验signature
|
|
|
+ if (!arg.getSignature().equals(signature)) {
|
|
|
+ Long returnTimestamp = System.currentTimeMillis();
|
|
|
+ String returnEncryptedResult = SignUtil.encryptAes("sinature is wrong", aesKey);
|
|
|
+ String returnNonce = (int) (Math.random() * 100000) + "";
|
|
|
+ String returnSignature = SignUtil.shaEncode(returnTimestamp + returnNonce + returnEncryptedResult + aesKey);
|
|
|
+ CrmCallBackResult crmCallBackResult = new CrmCallBackResult();
|
|
|
+ crmCallBackResult.setTimestamp(returnTimestamp);
|
|
|
+ crmCallBackResult.setEncryptedResult(returnEncryptedResult);
|
|
|
+ crmCallBackResult.setNonce(returnNonce);
|
|
|
+ crmCallBackResult.setSignature(returnSignature);
|
|
|
+ log.warn("crmCallBack={}", crmCallBackResult);
|
|
|
+ return crmCallBackResult;
|
|
|
+ }
|
|
|
+ //处理第三方业务逻辑
|
|
|
+ String json = SignUtil.decryptAes(arg.getEncryptedContent(), aesKey);
|
|
|
+ //....
|
|
|
+ //返回结果
|
|
|
+ Long returnTimestamp = System.currentTimeMillis();
|
|
|
+ String returnEncryptedResult = SignUtil.encryptAes("success", aesKey);
|
|
|
+ String returnNonce = (int) (Math.random() * 1000000) + "";
|
|
|
+ String returnSignature = SignUtil.shaEncode(returnTimestamp + returnNonce + returnEncryptedResult + aesKey);
|
|
|
+ CrmCallBackResult crmCallBackResult = new CrmCallBackResult();
|
|
|
+ crmCallBackResult.setTimestamp(returnTimestamp);
|
|
|
+ crmCallBackResult.setEncryptedResult(returnEncryptedResult);
|
|
|
+ crmCallBackResult.setNonce(returnNonce);
|
|
|
+ crmCallBackResult.setSignature(returnSignature);
|
|
|
+ log.info("json={},crmCallBack={}", json, crmCallBackResult);
|
|
|
+ return crmCallBackResult;
|
|
|
+ }
|
|
|
+}
|