SendWeChatHandle.java 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package cn.com.ctop.notice.handler;
  2. import cn.com.ctop.common.module.mapper.MailLogMapper;
  3. import cn.com.ctop.common.module.utils.CorpWexinUtils;
  4. import lombok.extern.slf4j.Slf4j;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.stereotype.Service;
  7. import java.util.Arrays;
  8. import java.util.List;
  9. @Slf4j
  10. @Service
  11. public class SendWeChatHandle {
  12. @Autowired
  13. MailLogMapper mailLogMapper;
  14. public void sendWeChatByMail(String mail,String message){
  15. String weChatId=mailLogMapper.getWeChatByMail(mail);
  16. if(weChatId.isEmpty()){
  17. log.error(String.format("mail's WeChat not found. mail =%s", mail));
  18. //TODO 通知管理员添加邮箱
  19. }else{
  20. CorpWexinUtils.sendMessageByWeChatId(weChatId,message);
  21. }
  22. }
  23. /**
  24. * 发送多人,邮箱逗号隔开
  25. * @param mails
  26. * @param message
  27. */
  28. public void sendWeChatByMails(String mails,String message){
  29. List<String> mail= Arrays.asList(mails.split(","));
  30. mail.forEach(m->{
  31. this.sendWeChatByMail(m,message);
  32. });
  33. }
  34. }