|
|
@@ -2,11 +2,16 @@ package com.malk.cloudpure.controller;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alibaba.fastjson.parser.Feature;
|
|
|
+import com.malk.cloudpure.helper.ApiRequestWrapper;
|
|
|
import com.malk.server.common.McException;
|
|
|
import com.malk.server.common.McR;
|
|
|
+import com.malk.server.xbongbong.DigestUtil;
|
|
|
import com.malk.server.xbongbong.XBBConf;
|
|
|
import com.malk.service.dingtalk.DDClient;
|
|
|
import com.malk.service.dingtalk.DDClient_Contacts;
|
|
|
+import com.malk.service.dingtalk.DDClient_Notable;
|
|
|
import com.malk.service.dingtalk.DDClient_Personnel;
|
|
|
import com.malk.service.xbongbong.XBBClient;
|
|
|
import com.malk.utils.UtilMap;
|
|
|
@@ -14,6 +19,9 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.IOException;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -32,6 +40,9 @@ public class XBBController {
|
|
|
@Autowired
|
|
|
private DDClient_Contacts ddClientContacts;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private DDClient_Notable ddClientNotable;
|
|
|
+
|
|
|
private static List<Integer> AUTH_WHITELIST_DEPFIDS=Arrays.asList(95172190,333372743); // 权限白名单
|
|
|
|
|
|
/**
|
|
|
@@ -165,6 +176,85 @@ private Long getWorkOrderInfo(@RequestParam String workOrderSerierNO) {
|
|
|
ddClientContacts.getUserInfoById(ddClient.getAccessToken(), "16608972969409067");
|
|
|
return McR.success();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 测试token
|
|
|
+ */
|
|
|
+ private static final String TOKEN = "b88c3b27b11fa252500ce3041cc918fe";
|
|
|
+ @RequestMapping(value = "/callback", method = RequestMethod.POST)
|
|
|
+ public String test(HttpServletRequest httpServletRequest) {
|
|
|
+ String response;
|
|
|
+ try {
|
|
|
+ // 获取请求体中的参数
|
|
|
+ JSONObject params = getParams(httpServletRequest);
|
|
|
+// System.out.println(JSON.toJSONString(params));
|
|
|
+ log.info("callback request= " + JSON.toJSONString(params));
|
|
|
+ // 获取请求头中的sign
|
|
|
+ String sign = httpServletRequest.getHeader("sign");
|
|
|
+ if (checkSign(params, sign)) {
|
|
|
+ log.info("callback check success!");
|
|
|
+ if(params.getString("type").equals("customerCommunicate")
|
|
|
+ && params.getString("operate").equals("new")){
|
|
|
+ Map map=xbbClient.getDataDetail(XBBConf.API_DETAIL_communicate,params.getLong("dataId"));
|
|
|
+ Map data = (Map) map.get("data");
|
|
|
+ System.out.println(JSONObject.toJSONString(map));
|
|
|
+ String creatorId=UtilMap.getString(UtilMap.getMap(data,"creatorId"),"id");
|
|
|
+ String content=String.valueOf(data.get("text_6"));
|
|
|
+ String merName=UtilMap.getString(UtilMap.getMap(data,data.containsKey("text_1")?"text_1":"text_5"),"name");
|
|
|
+ System.out.println(merName+":"+content);
|
|
|
+
|
|
|
+ Map<String,Object> paramsMap = new HashMap<>();
|
|
|
+ paramsMap.put("filter", UtilMap.map("combination, conditions","and", Arrays.asList(UtilMap.map("field, operator, value","客户全称","equal",Arrays.asList(merName)))));
|
|
|
+ List<Map> list=ddClientNotable.getRecords(ddClient.getAccessToken(),"bxgzX5wq4YoJPQG3jLvR8Ry2OB79ALPD","dulvlx8e4ru1wmna9lt8m","0LeoESGUiSKn272PRD8Qv3AiEiE",paramsMap);
|
|
|
+ for(Map detail:list){
|
|
|
+ String id=UtilMap.getString(detail,"id");
|
|
|
+ Map <String,Object> map1=new HashMap<>();
|
|
|
+ map1.put("id",id);
|
|
|
+ map1.put("fields",UtilMap.map("详情", content));
|
|
|
+ List<Map> updateRecords= Arrays.asList(map1);
|
|
|
+ ddClientNotable.updateRecords(ddClient.getAccessToken(),"bxgzX5wq4YoJPQG3jLvR8Ry2OB79ALPD","dulvlx8e4ru1wmna9lt8m","0LeoESGUiSKn272PRD8Qv3AiEiE",updateRecords);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ response = "request analysis success!";
|
|
|
+ } catch (Exception e) {
|
|
|
+ response = "request analysis error!";
|
|
|
+ }
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * sign校验,如果需要对回调请求进行合法性校验,需要对传过来的sign做验证
|
|
|
+ * @param params 有序的接收到的参数
|
|
|
+ * @param orSign 请求传过来的sign
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private boolean checkSign(JSONObject params, String orSign) {
|
|
|
+ // 将请求参数与token进行SHA256运算,得到校验签名sign
|
|
|
+ String sign = DigestUtil.Encrypt(params.toJSONString() + TOKEN, "SHA-256");
|
|
|
+ // 将请求过来的checkSign与生成的sign进行匹配,匹配成功则证明到达该接口的请求是由销帮帮发出的安全的请求
|
|
|
+ if (Objects.equals(orSign, sign)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取参数
|
|
|
+ * @param request
|
|
|
+ * @return JSONObject 将请求参数有序接收后格式示例:{"corpid":"XXX","dataId":123456,"formId":714275,"operate":"EDIT","saasMark":1,"type":"CUSTOMER"}
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ public static JSONObject getParams(HttpServletRequest request) throws IOException {
|
|
|
+ ApiRequestWrapper requestWrapper = new ApiRequestWrapper(request);
|
|
|
+ byte[] requestWrapperBody = requestWrapper.getBody();
|
|
|
+ String requestWrapperString = new String(requestWrapperBody, StandardCharsets.UTF_8);
|
|
|
+ LinkedHashMap params = JSON.parseObject(requestWrapperString, LinkedHashMap.class, Feature.OrderedField);
|
|
|
+ JSONObject requestJsonObject = new JSONObject(true);
|
|
|
+ requestJsonObject.putAll(params);
|
|
|
+ return requestJsonObject;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|