当前位置: 首页 > news >正文

【JAVA】java 企业微信信息推送

前言

JAVA中 将信息 推送到企业微信

	// 企微消息推送messageprivate String getMessage(String name, String problemType, String pushResults, Long orderId,java.util.Date submitTime, java.util.Date payTime) {String message = "对接方:+<font color=\"info\">" + name + "</font>" + "\n" + ">问题类型:+<font color=\"info\">"+ problemType + "</font>" + "\n" + ">推送结果:+<font color=\"info\">" + pushResults + "</font>" + "\n"+ ">订单号:+<font color=\"info\">" + orderId + "</font>" + "\n" + ">订单产生时间:+<font color=\"info\">"+ submitTime + "</font>" + "\n" + ">订单支付时间:+<font color=\"info\">" + payTime + "</font>" + "\n"+ ">最后重推时间:+<font color=\"info\">" + new Date() + "</font>";return message;}

业务逻辑实现

                    LoggerFactory.getLogger(CtgExtendController.class).info("企业微信消息发送开始");String message = getMessage(log);String url = ConfigDao.getAppConfig().getConfig("fail_order_push_robot","https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=49308bf4-3e4c-47d8-95a9-1dbfd7984b66");ExceptionMessageModel exceptionMessageModel = new ExceptionMessageModel();exceptionMessageModel.setMessage(message);exceptionMessageModel.setRobotUrl(url);exceptionMessageModel.setTemplateCode(WxEtpRobotMsgEnum.MSG_ORDER_PUSH_H5.msgCode);exceptionMessageModel.setJsonParam(JSONUtility.objectToNotNullJson(resVo));//发送消息实现if (StringUtils.isNotBlank(exceptionMessageModel.getTemplateCode()) && StringUtils.isNotBlank(exceptionMessageModel.getJsonParam())) {//优先取配置项中的模板配置String msg = WxEtpRobotMsgEnum.covertMsg(exceptionMessageModel.getTemplateCode(), exceptionMessageModel.getJsonParam());if(StringUtils.isNotBlank(msg)){exceptionMessageModel.setMessage(msg);}}LoggerFactory.getLogger(CtgExtendController.class).info("异常信息推送埋点进入,入参:"+ exceptionMessageModel.toString());WxRobotUtil.sendMsg(exceptionMessageModel.getRobotUrl(), exceptionMessageModel.getMessage());LoggerFactory.getLogger(CtgExtendController.class).info("企业微信消息发送成功");

public class WxRobotUtil {
    private static final Logger logger= LoggerFactory.getLogger(WxRobotUtil.class);

    public static void sendMsg(String url,String msg){
        new CommonThread("","WxRobotUtil"){
            @Override
            public void run() {
               try {
                   //拼装发送消息
                   Map<String, Object> map = new HashMap<>();
                   Map<String, String> param = new HashMap<>();
                   map.put("msgtype", "markdown");
                   param.put("content","时间:"+new Date().getDateTimeStr()+"\n"+msg);
                   map.put("markdown", param);
                   String result = HttpUtility.doPost(url, JSONUtility.objectToJson(map), ContentType.APPLICATION_JSON.getMimeType());
                   logger.info("微信机器人消息:"+url+"---"+msg);
               }
               catch (Exception e){
                   logger.error("异常:"+url+"---"+msg,e);
               }
            }
        }.start();
    }
}

public class WxRobotUtil {private static final Logger logger= LoggerFactory.getLogger(WxRobotUtil.class);public static void sendMsg(String url,String msg){new CommonThread("","WxRobotUtil"){@Overridepublic void run() {try {//拼装发送消息Map<String, Object> map = new HashMap<>();Map<String, String> param = new HashMap<>();map.put("msgtype", "markdown");param.put("content","时间:"+new Date().getDateTimeStr()+"\n"+msg);map.put("markdown", param);String result = HttpUtility.doPost(url, JSONUtility.objectToJson(map), ContentType.APPLICATION_JSON.getMimeType());logger.info("微信机器人消息:"+url+"---"+msg);}catch (Exception e){logger.error("异常:"+url+"---"+msg,e);}}}.start();}
}

http://www.lryc.cn/news/479606.html

相关文章:

  • 介绍一下数组(c基础)(smart 版)
  • Java项目实战II基于Spring Boot的个人云盘管理系统设计与实现(开发文档+数据库+源码)
  • 探索数据科学与大数据技术专业本科生的广阔就业前景
  • 微服务架构面试内容整理-Zuul
  • 解决Knife4j 接口界面UI中文乱码问题
  • 微服务架构面试内容整理-Sleuth
  • Go语言的接口示例
  • 【Apache ECharts】<农作物病害发生防治面积>
  • 基于vue3实现的聊天机器人前端(附代码)
  • DICOM标准:深入详解DICOM医学影像中的传输语法
  • sql server 文件备份恢复
  • Gradle命令编译Android Studio工程项目并签名
  • lua入门教程:垃圾回收
  • 基于前后端分离架构,SaaS云平台与私有云部署的智慧校园源码,java电子班牌源码
  • 知识总结五
  • 一、初识C语言(1)
  • petty 状态管理库文档
  • SpringMVC学习记录(三)之响应数据
  • ENSP GVRP动态学习VLAN
  • 怎么给llama3.2-vision:90b模型进行量化剪枝蒸馏
  • flutter 专题四 Flutter渲染流程
  • 刘艳兵-DBA028-您可以在 ORCL1 和 ORCL2 数据库都运行其实例的主机上安装“独立服务器的 Oracle 网格基础结构“。哪两个陈述是正确的?
  • 前端三件套-css
  • 实验(未完成)
  • Python基础学习_01
  • 鸿萌数据迁移服务: 企业服务器整机在线热迁移, 实现不停机业务转移
  • 【C】无类型指针及函数指针
  • VR的左右眼渲染方法
  • 爬虫-------字体反爬
  • vue2组件封装和UI组件的二次封装,方法,属性,ref的传递