提交修改
This commit is contained in:
parent
0cd5e13657
commit
22a2b16cb7
@ -52,6 +52,7 @@ public class ShiroConfig {
|
||||
Map<String, String> filterMap = new LinkedHashMap<>();
|
||||
filterMap.put("/webjars/**", "anon");
|
||||
filterMap.put("/oneCode/**", "anon");
|
||||
filterMap.put("/dingding/**", "anon");
|
||||
filterMap.put("/file/**", "anon");
|
||||
filterMap.put("/test/**", "anon");
|
||||
filterMap.put("/druid/**", "anon");
|
||||
|
||||
@ -0,0 +1,125 @@
|
||||
package com.lz.modules.app.controller;
|
||||
|
||||
|
||||
import com.dingtalk.api.DefaultDingTalkClient;
|
||||
import com.dingtalk.api.DingTalkClient;
|
||||
import com.dingtalk.api.request.OapiMessageCorpconversationAsyncsendV2Request;
|
||||
import com.dingtalk.api.response.OapiMessageCorpconversationAsyncsendV2Response;
|
||||
import com.lz.common.utils.DingTalkUtil;
|
||||
import com.lz.common.utils.R;
|
||||
import com.lz.common.utils.StringUtil;
|
||||
import com.lz.modules.app.entity.StaffEntity;
|
||||
import com.lz.modules.app.service.StaffService;
|
||||
import com.lz.modules.third.entity.ThirdAppConfig;
|
||||
import com.lz.modules.third.service.ThirdAppConfigService;
|
||||
import com.taobao.api.ApiException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequestMapping("/dingding")
|
||||
public class DingDingController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private ThirdAppConfigService thirdAppConfigService;
|
||||
|
||||
@Autowired
|
||||
private DingTalkUtil dingTalkUtil;
|
||||
|
||||
@Autowired
|
||||
private StaffService staffService;
|
||||
|
||||
|
||||
static String homeUrl = "https://lzmanagement.ldxinyong.com/digitization";
|
||||
|
||||
//http://localhost:8080/lz_management/dingding/msg?username=18458195149&title=%E8%AF%B7%E6%B3%A8%E6%84%8F&content=%E9%A1%B9%E7%9B%AE%E8%A6%81%E8%BF%87%E6%9C%9F%E4%BA%86
|
||||
@RequestMapping("/msg")
|
||||
public R dingdingxiaoxi(String username, String title, String content) {
|
||||
String appid = "856016278";
|
||||
StaffEntity staffEntity = staffService.selectByPhone(username);
|
||||
ThirdAppConfig thirdAppConfig = thirdAppConfigService.getByAppId(appid);
|
||||
String token = dingTalkUtil.getAccessTokenWitchEntity(thirdAppConfig);
|
||||
String url = homeUrl;
|
||||
if (url.contains("?")) {
|
||||
url += "&halokit=" + System.currentTimeMillis();
|
||||
} else {
|
||||
url += "?halokit=" + System.currentTimeMillis();
|
||||
}
|
||||
url += "&detail=1&id=1&detailId=" + 1;
|
||||
url = URLEncoder.encode(url);
|
||||
|
||||
url = "dingtalk://dingtalkclient/action/openapp?corpid=" + thirdAppConfig.getCorpId() +
|
||||
"&container_type=work_platform&app_id=0_" +
|
||||
appid + "&redirect_type=jump&redirect_url=" + url;
|
||||
try {
|
||||
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2");
|
||||
OapiMessageCorpconversationAsyncsendV2Request req = new OapiMessageCorpconversationAsyncsendV2Request();
|
||||
req.setAgentId(Long.parseLong(appid));
|
||||
req.setUseridList(staffEntity.getEmployeeId());//员工 id
|
||||
OapiMessageCorpconversationAsyncsendV2Request.Msg obj1 = new OapiMessageCorpconversationAsyncsendV2Request.Msg();
|
||||
obj1.setMsgtype("action_card");
|
||||
OapiMessageCorpconversationAsyncsendV2Request.ActionCard obj2 = new OapiMessageCorpconversationAsyncsendV2Request.ActionCard();
|
||||
obj2.setSingleTitle(title);
|
||||
obj2.setSingleUrl(url);
|
||||
obj2.setMarkdown(
|
||||
getMarkDown(content)
|
||||
);
|
||||
obj2.setTitle(title);
|
||||
obj1.setActionCard(obj2);
|
||||
req.setMsg(obj1);
|
||||
OapiMessageCorpconversationAsyncsendV2Response rsp = client.execute(req, token);
|
||||
log.info("钉钉请求返回{}", rsp.getBody());
|
||||
//插入数据库
|
||||
} catch (ApiException e) {
|
||||
e.printStackTrace();
|
||||
return R.error("抛出异常");
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
public static String getMarkDown(String content) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
char[] cs = content.toCharArray();
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
for (char c : cs) {
|
||||
if (i == 0) {
|
||||
if (c == '/') {
|
||||
sb.append("#");
|
||||
} else {
|
||||
sb.append("# ").append(c);
|
||||
}
|
||||
} else {
|
||||
if (c == '/') {
|
||||
if (j == 0) {
|
||||
sb.append("\n");
|
||||
}
|
||||
j++;
|
||||
sb.append("#");
|
||||
continue;
|
||||
} else {
|
||||
j = 0;
|
||||
String xx = sb.toString();
|
||||
if(StringUtil.isNotBlank(xx)){
|
||||
char [] yy = xx.toCharArray();
|
||||
if(yy[yy.length -1 ] == '#'){
|
||||
sb.append(" ");
|
||||
}
|
||||
}
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
log.info(" getmarkdown :" + sb.toString());
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@ -3,6 +3,11 @@ package com.lz.modules.app.controller;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.dingtalk.api.DefaultDingTalkClient;
|
||||
import com.dingtalk.api.DingTalkClient;
|
||||
import com.dingtalk.api.request.OapiMessageCorpconversationAsyncsendV2Request;
|
||||
import com.dingtalk.api.response.OapiMessageCorpconversationAsyncsendV2Response;
|
||||
import com.lz.common.utils.DingTalkUtil;
|
||||
import com.lz.common.utils.NumberUtil;
|
||||
import com.lz.common.utils.R;
|
||||
import com.lz.modules.app.dto.ApprovalDto;
|
||||
@ -29,6 +34,9 @@ import com.lz.modules.sys.entity.app.ResultRecord;
|
||||
import com.lz.modules.sys.service.SysUserService;
|
||||
import com.lz.modules.sys.service.app.ResultDetailService;
|
||||
import com.lz.modules.sys.service.app.ResultRecordService;
|
||||
import com.lz.modules.third.entity.ThirdAppConfig;
|
||||
import com.lz.modules.third.service.ThirdAppConfigService;
|
||||
import com.taobao.api.ApiException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -36,6 +44,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.net.URLEncoder;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
@ -176,7 +185,6 @@ public class TestController {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@RequestMapping("/test/userinfo")
|
||||
public void userinfo() {
|
||||
|
||||
@ -204,7 +212,6 @@ public class TestController {
|
||||
}
|
||||
|
||||
|
||||
|
||||
// http://localhost:8080/lz_management/test/restore
|
||||
@RequestMapping("/test/restore")
|
||||
public void restore() throws Exception {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user