发送钉钉、邮件、手机信息

其中下列部分用到了Hutool中的工具,可先导入Hutool依赖

java 复制代码
 <dependency>
      <groupId>cn.hutool</groupId>
      <artifactId>hutool-all</artifactId>
      <version>5.8.16</version>
 </dependency>

钉钉

java 复制代码
 public void sendDingDing(PoMaster poMaster){
        String url="钉钉机器人的opai";
        JSONObject js = new JSONObject();
        js.set("msgtype","markdown");
        js.set("markdown",new JSONObject()
                .set("title"," 益达律师所邀请您审核采购单")
                .set("text","益达律师所邀您查看编号:"+poMaster.getId()+"的订单 ![screenshot](https://pic.3gbizhi.com/uploads/20231129/0750e85fa5fd97e19dfb879770d7f7db.jpg)\n"));
		//js.set("at",new JSONObject().set("atMobiles",new JSONArray().set("tel"))); 按照手机号发送
        js.set("at",new JSONObject().set("isAtAll",true));
        String s = JSONUtil.toJsonStr(js);
        HttpRequest.post(url).body(s).execute().body();
    }

邮件

java 复制代码
 public Integer sendEmail(String email) {
        MailAccount account = new MailAccount();
        account.setHost("smtp.aliyun.com");
        account.setPort(25);
        account.setAuth(true);
        account.setFrom("your Email");
        account.setUser("your Email");
        account.setPass("your Password");
        int code = RandomUtil.randomInt(1000, 10000);
        String url="https://baike.baidu.com/item/%E5%A4%A9%E4%B8%8A%E4%BA%BA%E9%97%B4/11074119";
        String content = "天上人间提醒您,您的验证码为:"+code+"请勿给他人观看及使用🥰🥰";
        TelMap.put(email,code);
        MailUtil.send(account, CollUtil.newArrayList(email), "天上人间", content, false);
        return 0;
    }



//发送带样式Email
ublic void sendEmail(PoMaster poMaster){
        MailAccount account = new MailAccount();
        account.setHost("smtp.aliyun.com");
        account.setPort(25);
        account.setAuth(true);
        account.setFrom("your Email");
        account.setUser("your Email");
        account.setPass("your Password");
        StringBuilder body = new StringBuilder();
        body.append(StrUtil.format("<h1>采购单:{},总金额:{}, 需要您的审核🥰🥰</h1>", poMaster.getId(), poMaster.getTotalPrice()));
        body.append(" <table border='1'> ");
        body.append(" <tr> ");
        body.append(" <td> ");
        body.append("商品名称");
        body.append(" </td>");
        body.append(" <td> ");
        body.append("采购数量");
        body.append(" </td>");
        body.append(" <td> ");
        body.append("采购单价");
        body.append(" </td>");
        body.append(" <td> ");
        body.append(" 商品金额");
        body.append(" </td>");
        body.append(" </tr> ");
        poMaster.getItems().forEach(item -> {
            body.append(" <tr> ");
            body.append(" <td> ");
            body.append(StrUtil.format("<a href='http://localhost:8080/#/po/detail?id={}' target='_blank'>{}</a>", item.getId(), item.getProductName()));
            body.append(" </td>");
            body.append(" <td> ");
            body.append(item.getQty());
            body.append(" </td>");
            body.append(" <td> ");
            body.append("¥"+item.getPrice());
            body.append(" </td>");
            body.append(" <td> ");
            body.append("¥"+item.getPrice().multiply(new BigDecimal(item.getQty())));
            body.append(" </td>");
            body.append(" </tr> ");
        });

        body.append(" </table>");
        MailUtil.send(account,"需要发送的Email","天上人间提醒您请对采购单审核-"+ poMaster.getId(),body.toString(),true);
    }

手机信息

java 复制代码
public Integer sendTel(String tel) {
        //发送信息调用地址
        String url="https://dfsns.market.alicloudapi.com/data/send_sms";
        //请求放法
        String method = "POST";
        //我的appcode号
        String appcode = "eb666bd7a6474c37aee78f8fe886a763";
        int code = RandomUtil.randomInt(1000, 10000);
        TelMap.put(tel,code);
        String result = HttpRequest.post(url)
                .header("Authorization", "APPCODE "+appcode)//头信息,多个头信息多次调用此方法即可
                .body("content=code:"+code+"&template_id=TPL_0000&phone_number="+tel)
                .execute().body();
        JSONObject entries = JSONUtil.parseObj(result);
        if(!entries.get("status").equals("OK")){
            throw new BizException(401,"验证码发送失败");
        }
        return 0;
    }
相关推荐
爱健身的小刘同学2 天前
H5页面在钉钉浏览器上动态修改标题
前端·钉钉
国通快递驿站2 天前
AntFlow 0.11.0版发布,增加springboot starter模块,一款设计上借鉴钉钉工作流的免费企业级审批流平台
spring boot·后端·钉钉
HelpLook HelpLook3 天前
降本增效新策略:对比飞书和钉钉,HelpLook如何更灵活管理知识库访客权限?
人工智能·aigc·钉钉·飞书·企业知识库·ai知识库·访问权限
女王の专属领地5 天前
深入浅出《钉钉AI》产品体验报告
人工智能·钉钉·语音识别·ai协同办公
da pai ge6 天前
zabbix搭建钉钉告警流程
钉钉·zabbix
Dark_programmer6 天前
钉钉小程序 - - - - - overflow无效?
小程序·钉钉
肖老师xy6 天前
对接钉钉审批详情
钉钉
树下熊猫6 天前
企业案例:钉钉宜搭对接金蝶云星空
数据库·钉钉
国通快递驿站6 天前
AntFlow:一款高效灵活的开源工作流引擎
java·spring boot·后端·开源·钉钉
sun_weitao11 天前
钉钉扫码登录(DTFrameLogin) 用户注销后重新登录出现回调叠加的问题
前端·javascript·钉钉