| | |
| | | package com.xcong.excoin.utils.dingtalk; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.dingtalk.api.DefaultDingTalkClient; |
| | | import com.dingtalk.api.DingTalkClient; |
| | |
| | | @Slf4j |
| | | public class DingTalkUtils { |
| | | |
| | | private static final String SECRET = "SECe4afed333b31b66e1d16c87733a29a0b4a3051c71a2960d13e606bfc1dd88b14"; |
| | | private static final String SECRET = "SECbc84fd6c2edb9f2f440f9f969981ca310ba553e7c7994cf68cf26e4607cc5943"; |
| | | |
| | | private static DingTalkClient initClient() throws Exception { |
| | | String url = "https://oapi.dingtalk.com/robot/send?access_token=54a0d627111f3667f7e98691c15becadb742c4da895e60f6d77392389e49658a"; |
| | | Long timestamp = System.currentTimeMillis(); |
| | | String sign = generateSign(timestamp); |
| | | url = url + "×tamp=" + timestamp + "&sign=" + sign; |
| | | return new DefaultDingTalkClient(url); |
| | | } |
| | | |
| | | public static void sendActionCard(int type) { |
| | | log.info("send dingtalk"); |
| | | String url = "https://oapi.dingtalk.com/robot/send?access_token=161d5e5b60ae5d6b4c80f2a9c35f9f212961a7c7154aa7e94b99503eca3886b0"; |
| | | Long timestamp = System.currentTimeMillis(); |
| | | |
| | | try { |
| | | String sign = generateSign(timestamp); |
| | | url = url + "×tamp=" + timestamp + "&sign=" + sign; |
| | | DingTalkClient client = new DefaultDingTalkClient(url); |
| | | DingTalkClient client = initClient(); |
| | | OapiRobotSendRequest request = new OapiRobotSendRequest(); |
| | | request.setMsgtype("actionCard"); |
| | | OapiRobotSendRequest.Actioncard actionCard = new OapiRobotSendRequest.Actioncard(); |
| | |
| | | log.info(JSONObject.toJSONString(response)); |
| | | } catch (Exception e) { |
| | | log.error("#dingtalk send error#", e); |
| | | } finally { |
| | | log.error("#dingtalk finally#"); |
| | | } |
| | | } |
| | | |
| | | public static void sendMsg(String title, String msg, Long id) { |
| | | try { |
| | | String text = "### {} \n\n {}"; |
| | | DingTalkClient client = initClient(); |
| | | |
| | | OapiRobotSendRequest request = new OapiRobotSendRequest(); |
| | | request.setMsgtype("actionCard"); |
| | | OapiRobotSendRequest.Actioncard actionCard = new OapiRobotSendRequest.Actioncard(); |
| | | actionCard.setTitle("异常消息"); |
| | | actionCard.setBtnOrientation("0"); |
| | | actionCard.setText(StrUtil.format(text, title, msg)); |
| | | actionCard.setSingleURL("http://123.60.45.251/common/getExceptionMsg?id=" + id); |
| | | actionCard.setSingleTitle("查询详情"); |
| | | |
| | | request.setActionCard(actionCard); |
| | | OapiRobotSendResponse response = client.execute(request); |
| | | log.info(JSONObject.toJSONString(response)); |
| | | } catch (Exception e) { |
| | | log.error("#dingtalk send error#", e); |
| | | } |
| | | } |
| | | |
| | |
| | | return sign; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | // sendMsg("测试一下", "内容"); |
| | | } |
| | | |
| | | } |