其中下列部分用到了Hutool中的工具,可先导入Hutool依赖
<dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.8.16</version></dependency>
钉钉
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();}
邮件
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);}
手机信息
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;}