主要代码类如下java.util.List;导入java.util.Map;导入org.apache.http.HttpResponse;导入org.apache.http.client.ClientProtocolException;导入org.apache.http.client.methods.HttpPost;导入org.apache.http。entity.StringEntity;导入org.apache.http.impl.client.CloseableHttpClient;导入org.apache.http.impl.client.HttpClients;导入org.json.JSONObject;/**文件名:com.test.common;。SendRobotMsgUtils.java*简要描述:TODO*详细描述:*新增时间:2022-05-2112:31:41*修改内容:[新增]*修改时间:2022-05-0212:31:41*版本:1.0**/publicclassSendRobotMsgUtils{@SuppressWarnings({"rawtypes","unchecked"})publicbooleanwechatRobotTxtMsg(StringwebhookUrl,StringmsgContent,Listmentioned_mobile_list){booleanfalg=false;//webhook地址Stringmsgtype="文本";HttpResponse响应=空;尝试{if(webhookUrl!=null&&msgContent!=null){HttpPosthttpPost=newHttpPost(webhookUrl);CloseableHttpClienthttpclient=HttpClients.createDefault();httpPost.setHeader("Content-Type","application/json;charset=utf-8");Mapparam=newHashMap();param.put("消息类型",消息类型);Mapparam_msg=newHashMap();param_msg.put("内容",msgContent);if(mentioned_mobile_list!=null&&mentioned_mobile_list.size()>0){param_msg.put("mentioned_mobile_list",mentioned_mobile_list);}//封装消息体param.put(msgtype,param_msg);字符串txtmsg=JSONObject.valueToString(param);System.out.println("*************执行前txtmsg:"+tx消息);StringEntityentity=newStringEntity(txtmsg,"utf-8");httpPost.setEntity(实体);System.out.println("*************执行前:"+httpPost.toString());响应=httpclient.execute(httpPost);if(response!=null&&response.getStatusLine()!=null&&response.getStatusLine().getStatusCode()==200){字符串responseStr=response.getEntity().toString();falg=真;System.out.println("*************执行结果:"+responseStr);}}else{System.out.println("*************输入参数为空********************************”);}}catch(ClientProtocolExceptione){e.printStackTrace();}catch(IOExceptione){e.printStackTrace();}返回falg;}@SuppressWarnings({"rawtypes","unchecked"})publicbooleanwechatRobotMarkdownMsg(StringwebhookUrl,StringmsgContent,Listmentioned_mobile_list){booleanfalg=false;//webhook地址Stringmsgtype="markdown";HttpResponse响应=空;尝试{if(webhookUrl!=null&&msgContent!=null){HttpPosthttpPost=newHttpPost(webhookUrl);CloseableHttpClienthttpclient=HttpClients.createDefault();httpPost.setHeader("Content-Type","application/json;charset=utf-8");Mapparam=newHashMap();param.put("消息类型",消息类型);Mapparam_msg=newHashMap();param_msg.put("内容",msgContent);if(mentioned_mobile_list!=null){param_msg.put("mentioned_mobile_list",mentioned_mobile_list);}//封装消息体param.put(msgtype,参数消息);字符串txtmsg=JSONObject.valueToString(param);System.out.println("*************执行前的txtmsg:"+txtmsg);StringEntityentity=newStringEntity(txtmsg,"utf-8");httpPost.setEntity(实体);System.out.println("**************执行前:"+httpPost.toString());响应=http客户端。执行(httpPost);if(response!=null&&response.getStatusLine()!=null&&response.getStatusLine().getStatusCode()==200){字符串responseStr=response.getEntity().toString();falg=真;系统。out.println("**************执行结果:"+responseStr);}}else{System.out.println("**************输入参数为空********************************”);}}catch(ClientProtocolExceptione){e.printStackTrace();}赶上(IOExceptione){e.printStackTrace();}返回falg;}publicstaticvoidmain(String[]args){SendRobotMsgUtilssrmu=newSendRobotMsgUtils();SimpleDateFormatsdf=newSimpleDateFormat("yyyy-MM-ddHH:mm:SSS");Stringnowstr=sdf.format(newDate());StringwebhookUrl="https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=c17661d0c2e6";StringmsgContent="监控机器人-普通短信\n消息时间:"+nowstr+";\n交易日期+支付渠道+渠道交易笔数+当天总交易笔数\n"+"大家可以关闭这条群消息!!!";列表<字符串>mlist=newArrayList<字符串>();mlist.add("@all");mlist.add("18688888888");//srmu.wechatRobotTxtMsg(webhookUrl,msgContent,mlist);StringmsgmkContent="监控名称
\r\n"+"\r\n"+"number\r\n"+"用户名\r\n"+"姓名\r\n"+"联系电话\r\n"+"\r\n"+"\r\n"+"\r\n"+"01\r\n"+"张三 | \r\n"+"姓名 | \r\n"+"18688888888 | \r\n"+"
\r\n"+"\r\n";srmu.wechatRobotMarkdownMsg(webhookUrl,msgmkContent,mlist);}}实际开发的功能效果可以访问:https://www.onekbit.com/微信...使用体验。使用微信机器人定时发群消息: