提交 b49932c5 编写于 作者: zhouweidong's avatar zhouweidong

钉钉、微信、阿里消息集成

上级 b523a3c9
......@@ -98,6 +98,25 @@
<artifactId>jobs-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>alibaba-dingtalk-service-sdk</artifactId>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-ecs</artifactId>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-dm</artifactId>
</dependency>
</dependencies>
......
package cn.ibizlab.core.extensions.aspect;
import cn.ibizlab.core.extensions.service.NotifyCoreService;
import cn.ibizlab.core.notify.domain.MsgOpenAccess;
import cn.ibizlab.core.notify.service.IMsgOpenAccessService;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
/**
* 新建或更新时刷新token
*/
@Aspect
@Order(0)
@Component
public class RefreshTokenAspect {
@Autowired
@Lazy
IMsgOpenAccessService smsConfigService;
@Autowired
@Lazy
NotifyCoreService notifyCoreService;
@Before(value = "execution(* cn.ibizlab.core.notify.service.IMsgOpenAccessService.create*(..))")
public void afterCreate(JoinPoint point) throws Exception {
refreshToken(point);
}
@Before(value = "execution(* cn.ibizlab.core.notify.service.IMsgOpenAccessService.update*(..))")
public void afterUpdate(JoinPoint point) throws Exception {
refreshToken(point);
}
/**
* 刷新token
* @param point
*/
private void refreshToken(JoinPoint point){
Object[] args = point.getArgs();
if (args.length > 0) {
MsgOpenAccess msgOpenAccess = (MsgOpenAccess) args[0];
if(msgOpenAccess.getOpenType().equals("wechat") || msgOpenAccess.getOpenType().equals("dingtalk")){
notifyCoreService.refreshToken(msgOpenAccess);
}
}
}
}
package cn.ibizlab.core.extensions.config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
@Configuration
public class RedisConfig {
@Bean
// @LoadBalanced
@ConditionalOnMissingBean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
\ No newline at end of file
package cn.ibizlab.core.extensions.service;
import cn.ibizlab.core.notify.domain.MsgOpenAccess;
import cn.ibizlab.core.notify.service.IMsgOpenAccessService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* 定时刷新token
*/
@Service
@Slf4j
public class RefreshTokenService{
@Autowired
IMsgOpenAccessService smsConfigService;
@Autowired
NotifyCoreService notifyCoreService;
@Scheduled(fixedRate = 1800000)
public void refreshToken() {
QueryWrapper<MsgOpenAccess> qw=new QueryWrapper();
qw.eq("disabled",0).isNotNull("access_key").isNotNull("secret_key").and(i -> i.eq("open_type","wechat").or().eq("open_type","dingtalk"));
List<MsgOpenAccess> accessList= smsConfigService.list(qw);
if(accessList.size()==0)
return ;
List<MsgOpenAccess> refreshAccessList=new ArrayList<>();
for(MsgOpenAccess openAccess : accessList){
String accessToken = openAccess.getAccessToken();
Timestamp expiresTime = openAccess.getExpiresTime();
if(StringUtils.isEmpty(accessToken)){
notifyCoreService.refreshToken(openAccess);
refreshAccessList.add(openAccess);
}
else{
if(expiresTime!=null && expiresTime.before(new Timestamp(new Date().getTime()))){
notifyCoreService.refreshToken(openAccess);
refreshAccessList.add(openAccess);
}
}
}
if(refreshAccessList.size()>0)
smsConfigService.updateBatch(refreshAccessList);
}
}
\ No newline at end of file
......@@ -89,6 +89,10 @@
<oracle.version>11.2.0.3</oracle.version>
<postgresql.version>42.2.6</postgresql.version>
<alibaba-dingtalk.version>1.0.1</alibaba-dingtalk.version>
<aliyun-sdk-core.version>4.5.4</aliyun-sdk-core.version>
<aliyun-sdk-ecs.version>4.19.6</aliyun-sdk-ecs.version>
<aliyun-sdk-dm.version>3.3.1</aliyun-sdk-dm.version>
</properties>
<dependencyManagement>
......@@ -270,6 +274,28 @@
<version>${baomidou-jobs.version}</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>alibaba-dingtalk-service-sdk</artifactId>
<version>${alibaba-dingtalk.version}</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>${aliyun-sdk-core.version}</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-ecs</artifactId>
<version>${aliyun-sdk-ecs.version}</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-dm</artifactId>
<version>${aliyun-sdk-dm.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
......@@ -349,8 +375,6 @@
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
</project>
package cn.ibizlab.api.rest.extensions;
import cn.ibizlab.core.extensions.service.NotifyCoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class NotifyCoreResource {
@Autowired
NotifyCoreService notifyCoreService;
@RequestMapping(method = RequestMethod.GET,value = "/sendDingTalkMsg")
public ResponseEntity<Boolean> sendDingTalkMsg(@Validated @RequestParam String tid, @RequestParam String userId){
return ResponseEntity.status(HttpStatus.OK).body(notifyCoreService.sendDingTalkMsg(tid,userId));
// return ResponseEntity.status(HttpStatus.OK).body(notifyCoreService.sendDingTalkMsg("6c2e3779dd159ceba3e70e7502f4cf6f","760fd9aae5bb9475cb4e18b80d689ea7"));
}
@RequestMapping(method = RequestMethod.GET,value = "/sendWeChatMsg")
public ResponseEntity<Boolean> sendWeChatMsg(@Validated @RequestParam String tid,@RequestParam String userId){
return ResponseEntity.status(HttpStatus.OK).body(notifyCoreService.sendWeChatMsg(tid,userId));
// return ResponseEntity.status(HttpStatus.OK).body(notifyCoreService.sendWeChatMsg("8ddcea1f2a9743f159bd765133443684","760fd9aae5bb9475cb4e18b80d689ea7"));
}
@RequestMapping(method = RequestMethod.GET,value = "/sendAliEMail")
public ResponseEntity<Boolean> sendAliEMail(@Validated @RequestParam String tid,@RequestParam String userId){
return ResponseEntity.status(HttpStatus.OK).body(notifyCoreService.sendAliEMail(tid,userId));
// return ResponseEntity.status(HttpStatus.OK).body(notifyCoreService.sendAliEMail("5f4c72e0eb1eb3cf5b57c319a021d5b9","760fd9aae5bb9475cb4e18b80d689ea7"));
}
@RequestMapping(method = RequestMethod.GET,value = "/SendAliSms")
public ResponseEntity<Boolean> SendAliSms(@Validated @RequestParam String tid,@RequestParam String userId){
return ResponseEntity.status(HttpStatus.OK).body(notifyCoreService.SendAliSms(tid,userId));
// return ResponseEntity.status(HttpStatus.OK).body(notifyCoreService.SendAliSms("Vufzr1HEvhntkIOK8HkT_poUTLAmpwSbjzK0ncOkSuw","18677074230"));
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册