diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java index bb7edb3e2a..1ec2b60a01 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java @@ -871,4 +871,14 @@ public class RedisKeys { public static String getDhToken() { return rootPrefix.concat("dh:token"); } + + /** + * Desc: 票据 + * @param suiteKey + * @author zxc + * @date 2022/9/14 10:46 + */ + public static String getSuiteTicketKey(String suiteKey) { + return rootPrefix.concat("ding:suiteTicket:" + suiteKey); + } } diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/DingMiniInfoDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/DingMiniInfoDTO.java new file mode 100644 index 0000000000..19ebfacdd9 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/DingMiniInfoDTO.java @@ -0,0 +1,89 @@ +package com.epmet.dto; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + + +/** + * 钉钉小程序信息 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-09-14 + */ +@Data +public class DingMiniInfoDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * ID + */ + private String id; + + /** + * + */ + private String suiteId; + + /** + * + */ + private String appId; + + /** + * + */ + private String miniAppId; + + /** + * + */ + private String suiteName; + + /** + * + */ + private String suiteKey; + + /** + * + */ + private String suiteSecret; + + private String token; + + private String aesKey; + + /** + * + */ + private Integer delFlag; + + /** + * 乐观锁 + */ + private Integer revision; + + /** + * 创建人 + */ + private String createdBy; + + /** + * 创建时间 + */ + private Date createdTime; + + /** + * 更新人 + */ + private String updatedBy; + + /** + * 更新时间 + */ + private Date updatedTime; + +} \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/dingtalk/CallbackController.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/dingtalk/CallbackController.java index 8edd48d46a..5940ce57f5 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/dingtalk/CallbackController.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/dingtalk/CallbackController.java @@ -3,8 +3,11 @@ package com.epmet.controller.dingtalk; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.aliyun.dingtalk.util.DingCallbackCrypto; -import com.epmet.commons.tools.utils.ConvertUtils; +import com.epmet.commons.tools.constant.NumConstant; +import com.epmet.dao.OpenSyncBizDataDao; +import com.epmet.dto.DingMiniInfoDTO; import com.epmet.entity.OpenSyncBizDataEntity; +import com.epmet.redis.DingDingCallbackRedis; import com.epmet.service.OpenSyncBizDataService; import org.apache.commons.collections4.CollectionUtils; import org.slf4j.Logger; @@ -49,21 +52,24 @@ public class CallbackController { @Autowired private OpenSyncBizDataService openSyncBizDataService; + @Autowired + private OpenSyncBizDataDao openSyncBizDataDao; + @Autowired + private DingDingCallbackRedis dingCallbackRedis; @PostMapping(value = "dingCallback") public Object dingCallback( @RequestParam(value = "signature") String signature, @RequestParam(value = "timestamp") Long timestamp, @RequestParam(value = "nonce") String nonce, - @RequestParam(value = "id") int id, + @RequestParam(value = "suiteKey") String suiteKey, @RequestBody(required = false) JSONObject body ) { - log.info("id is:"+id); - String params = "signature:" + signature + " timestamp:" + timestamp + " nonce:" + nonce + " body:" + body; + String params = "signature:" + signature + " timestamp:" + timestamp + " nonce:" + nonce + " body:" + body + "suiteKey::"+suiteKey; try { log.info("begin callback:" + params); - - DingCallbackCrypto dingTalkEncryptor = new DingCallbackCrypto("vTUvaf6QtOJZsa1h7Wkoteo", "csRpvVFGL7Cf1N9ubajix8tDWhCllROhaxCHKFnbuAz", "suite5yxliro6wawv514w"); + DingMiniInfoDTO dingMiniInfo = openSyncBizDataDao.getDingMiniInfo(suiteKey); + DingCallbackCrypto dingTalkEncryptor = new DingCallbackCrypto(dingMiniInfo.getToken(), dingMiniInfo.getAesKey(), suiteKey); // 从post请求的body中获取回调信息的加密数据进行解密处理 String encrypt = body.getString("encrypt"); @@ -88,12 +94,22 @@ public class CallbackController { // 即使本接口没有收到数据或者收到事件后处理初始化失败都可以后续再用户试用应用时从前端获取到corpId并拉取授权企业信息,进而初始化开通及企业。 log.info("企业授权开通应用事件: " + plainText); } else if (EVENT_SYNC_HTTP_PUSH_HIGH.equals(eventType)){ - log.info("ticket: " + plainText); List> bizData = (List>) callBackContent.get("bizData"); if (CollectionUtils.isNotEmpty(bizData)){ List list = new ArrayList<>(); bizData.forEach(b -> { - list.add(ConvertUtils.mapToEntity(b, OpenSyncBizDataEntity.class)); + OpenSyncBizDataEntity e = new OpenSyncBizDataEntity(); + e.setSubscribeId(b.get("subscribe_id").toString()); + e.setCorpId(b.get("corp_id").toString()); + e.setBizId(b.get("biz_id").toString()); + e.setBizData(b.get("biz_data").toString()); + e.setBizType(b.get("biz_type").toString()); + list.add(e); + openSyncBizDataService.delete(e); + if (e.getBizType().equals(NumConstant.TWO_STR)){ + Map ticketMap = JSON.parseObject(e.getBizData(), Map.class); + dingCallbackRedis.set(suiteKey,ticketMap.get("suiteTicket")); + } }); openSyncBizDataService.insertBatch(list); } diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/OpenSyncBizDataDao.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/OpenSyncBizDataDao.java index 800ff14a06..4d6ee1459e 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/OpenSyncBizDataDao.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/OpenSyncBizDataDao.java @@ -1,8 +1,10 @@ package com.epmet.dao; import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.dto.DingMiniInfoDTO; import com.epmet.entity.OpenSyncBizDataEntity; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; /** * @@ -12,5 +14,9 @@ import org.apache.ibatis.annotations.Mapper; */ @Mapper public interface OpenSyncBizDataDao extends BaseDao { - + + DingMiniInfoDTO getDingMiniInfo(@Param("suiteKey")String suiteKey); + + Integer delOpenSyncData(OpenSyncBizDataEntity e); + } \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/redis/DingDingCallbackRedis.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/redis/DingDingCallbackRedis.java new file mode 100644 index 0000000000..13d026d20b --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/redis/DingDingCallbackRedis.java @@ -0,0 +1,26 @@ +package com.epmet.redis; + +import com.epmet.commons.tools.redis.RedisKeys; +import com.epmet.commons.tools.redis.RedisUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * @Author zxc + * @DateTime 2022/9/14 10:32 + * @DESC + */ +@Component +public class DingDingCallbackRedis { + @Autowired + private RedisUtils redisUtils; + + public void set(String suiteKey,String suiteTicket){ + String key = RedisKeys.getSuiteTicketKey(suiteKey); + redisUtils.set(key,suiteTicket,-1); + } + + public String get(String suiteKey){ + return redisUtils.getString(RedisKeys.getSuiteTicketKey(suiteKey)); + } +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/OpenSyncBizDataService.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/OpenSyncBizDataService.java index 837eacceb7..64f3668e38 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/OpenSyncBizDataService.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/OpenSyncBizDataService.java @@ -75,4 +75,6 @@ public interface OpenSyncBizDataService extends BaseService + + DELETE + FROM open_sync_biz_data + WHERE biz_id = #{bizId} + AND biz_type = #{bizType} + AND subscribe_id = #{subscribeId} + AND corp_id = #{corpId} + AND DEL_FLAG = 0 + + \ No newline at end of file