From cdb040ae40c91ce53bfcdd4e075da67f0176fed0 Mon Sep 17 00:00:00 2001 From: zxc <954985706@qq.com> Date: Thu, 9 Jul 2020 18:26:31 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E7=AC=AC=E4=B8=89?= =?UTF-8?q?=E6=96=B9=E5=B9=B3=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/epmet/dto/AuthCodeDTO.java | 86 ++++++++ .../com/epmet/dto/AuthorizationInfoDTO.java | 91 +++++++++ .../epmet/dto/AuthorizerRefreshTokenDTO.java | 76 +++++++ .../epmet/dto/ComponentAccessTokenDTO.java | 76 +++++++ .../main/java/com/epmet/dto/FuncInfoDTO.java | 86 ++++++++ .../java/com/epmet/dto/PreAuthTokenDTO.java | 76 +++++++ .../dto/RefreshAuthorizerAccessTokenDTO.java | 91 +++++++++ .../com/epmet/dto/form/AuthCodeFormDTO.java | 50 +++++ .../dto/form/AuthorizationInfoFormDTO.java | 49 +++++ .../form/AuthorizerAccessTokenFormDTO.java | 47 +++++ .../dto/form/ComponentAccessTokenFormDTO.java | 40 ++++ .../com/epmet/dto/form/FuncInfoFormDTO.java | 41 ++++ .../epmet/dto/form/PreAuthTokenFormDTO.java | 41 ++++ .../dto/result/WillOverDueResultDTO.java | 37 ++++ .../com/epmet/constant/ModuleConstant.java | 14 +- .../com/epmet/constant/ThirdApiConstant.java | 26 +++ .../epmet/constant/ThirdPlatformConstant.java | 20 -- .../epmet/constant/ThirdRedisKeyConstant.java | 45 +++++ .../controller/WeChatNotifyController.java | 41 ++-- .../main/java/com/epmet/dao/AuthCodeDao.java | 36 ++++ .../com/epmet/dao/AuthorizationInfoDao.java | 41 ++++ .../epmet/dao/AuthorizerRefreshTokenDao.java | 33 +++ .../epmet/dao/ComponentAccessTokenDao.java | 41 ++++ .../main/java/com/epmet/dao/FuncInfoDao.java | 39 ++++ .../com/epmet/dao/PaCustomerAgencyDao.java | 12 +- .../java/com/epmet/dao/PreAuthTokenDao.java | 41 ++++ .../dao/RefreshAuthorizerAccessTokenDao.java | 47 +++++ .../java/com/epmet/entity/AuthCodeEntity.java | 61 ++++++ .../epmet/entity/AuthorizationInfoEntity.java | 66 ++++++ .../entity/AuthorizerRefreshTokenEntity.java | 51 +++++ .../entity/ComponentAccessTokenEntity.java | 51 +++++ .../java/com/epmet/entity/FuncInfoEntity.java | 61 ++++++ .../com/epmet/entity/PreAuthTokenEntity.java | 51 +++++ .../RefreshAuthorizerAccessTokenEntity.java | 66 ++++++ .../main/java/com/epmet/redis/RedisThird.java | 68 ++++--- .../service/ComponentVerifyTicketService.java | 16 +- .../ComponentVerifyTicketServiceImpl.java | 190 ++++++++++++++---- .../src/main/resources/mapper/AuthCodeDao.xml | 36 ++++ .../resources/mapper/AuthorizationInfoDao.xml | 39 ++++ .../mapper/AuthorizerRefreshTokenDao.xml | 18 ++ .../mapper/ComponentAccessTokenDao.xml | 33 +++ .../src/main/resources/mapper/FuncInfoDao.xml | 38 ++++ .../resources/mapper/PaCustomerAgencyDao.xml | 11 + .../main/resources/mapper/PreAuthTokenDao.xml | 32 +++ .../RefreshAuthorizerAccessTokenDao.xml | 52 +++++ 45 files changed, 2143 insertions(+), 120 deletions(-) create mode 100644 epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/AuthCodeDTO.java create mode 100644 epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/AuthorizationInfoDTO.java create mode 100644 epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/AuthorizerRefreshTokenDTO.java create mode 100644 epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/ComponentAccessTokenDTO.java create mode 100644 epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/FuncInfoDTO.java create mode 100644 epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/PreAuthTokenDTO.java create mode 100644 epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/RefreshAuthorizerAccessTokenDTO.java create mode 100644 epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/AuthCodeFormDTO.java create mode 100644 epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/AuthorizationInfoFormDTO.java create mode 100644 epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/AuthorizerAccessTokenFormDTO.java create mode 100644 epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/ComponentAccessTokenFormDTO.java create mode 100644 epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/FuncInfoFormDTO.java create mode 100644 epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/PreAuthTokenFormDTO.java create mode 100644 epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/result/WillOverDueResultDTO.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ThirdApiConstant.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ThirdRedisKeyConstant.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/AuthCodeDao.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/AuthorizationInfoDao.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/AuthorizerRefreshTokenDao.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/ComponentAccessTokenDao.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/FuncInfoDao.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PreAuthTokenDao.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/RefreshAuthorizerAccessTokenDao.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/AuthCodeEntity.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/AuthorizationInfoEntity.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/AuthorizerRefreshTokenEntity.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/ComponentAccessTokenEntity.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/FuncInfoEntity.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/PreAuthTokenEntity.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/RefreshAuthorizerAccessTokenEntity.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/AuthCodeDao.xml create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/AuthorizationInfoDao.xml create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/AuthorizerRefreshTokenDao.xml create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/ComponentAccessTokenDao.xml create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/FuncInfoDao.xml create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PreAuthTokenDao.xml create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/RefreshAuthorizerAccessTokenDao.xml diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/AuthCodeDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/AuthCodeDTO.java new file mode 100644 index 0000000000..59dce8901d --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/AuthCodeDTO.java @@ -0,0 +1,86 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dto; + +import java.io.Serializable; +import java.util.Date; +import lombok.Data; + + +/** + * 授权回调url反参表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-07-09 + */ +@Data +public class AuthCodeDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * + */ + private String id; + + /** + * 客户ID + */ + private String customerId; + + /** + * 授权方APPID + */ + private String authAppid; + + /** + * 授权码 + */ + private String authCode; + + /** + * 有效期 10min + */ + private Integer expiresIn; + + /** + * + */ + private Integer delFlag; + + /** + * + */ + 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-client/src/main/java/com/epmet/dto/AuthorizationInfoDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/AuthorizationInfoDTO.java new file mode 100644 index 0000000000..ebdc051c24 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/AuthorizationInfoDTO.java @@ -0,0 +1,91 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dto; + +import java.io.Serializable; +import java.util.Date; +import lombok.Data; + + +/** + * 授权信息表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-07-09 + */ +@Data +public class AuthorizationInfoDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * + */ + private String id; + + /** + * 客户ID + */ + private String customerId; + + /** + * 授权方 appid + */ + private String authorizerAppid; + + /** + * 接口调用令牌(在授权的公众号/小程序具备 API 权限时,才有此返回值) + */ + private String authorizerAccessToken; + + /** + * authorizer_access_token 的有效期(在授权的公众号/小程序具备API权限时,才有此返回值),单位:秒 + */ + private Integer expiresIn; + + /** + * 刷新令牌(在授权的公众号具备API权限时,才有此返回值),刷新令牌主要用于第三方平台获取和刷新已授权用户的 authorizer_access_token。一旦丢失,只能让用户重新授权,才能再次拿到新的刷新令牌。用户重新授权后,之前的刷新令牌会失效 + */ + private String authorizerRefreshToken; + + /** + * + */ + private Integer delFlag; + + /** + * + */ + 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-client/src/main/java/com/epmet/dto/AuthorizerRefreshTokenDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/AuthorizerRefreshTokenDTO.java new file mode 100644 index 0000000000..32b509fe6f --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/AuthorizerRefreshTokenDTO.java @@ -0,0 +1,76 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dto; + +import java.io.Serializable; +import java.util.Date; +import lombok.Data; + + +/** + * 授权方的刷新令牌表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-07-09 + */ +@Data +public class AuthorizerRefreshTokenDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + private String id; + + /** + * 授权方的刷新令牌 + */ + private String authorizerRefreshToken; + + /** + * 授权方appid + */ + private String authorizerAppid; + + /** + * 删除标识 0-否,1-是 + */ + private String delFlag; + + /** + * 创建人 + */ + 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-client/src/main/java/com/epmet/dto/ComponentAccessTokenDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/ComponentAccessTokenDTO.java new file mode 100644 index 0000000000..630898d5db --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/ComponentAccessTokenDTO.java @@ -0,0 +1,76 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dto; + +import java.io.Serializable; +import java.util.Date; +import lombok.Data; + + +/** + * 第三方平台调用凭证 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-07-09 + */ +@Data +public class ComponentAccessTokenDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * id + */ + private String id; + + /** + * 令牌 【第三方平台接口的调用凭据】 + */ + private String componentAccessToken; + + /** + * 令牌有效期 单位:s 最长 60*60*2 + */ + private Integer expiresIn; + + /** + * 删除状态 0:正常 1:删除 + */ + private Integer delFlag; + + /** + * 创建人 + */ + 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-client/src/main/java/com/epmet/dto/FuncInfoDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/FuncInfoDTO.java new file mode 100644 index 0000000000..482e71f206 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/FuncInfoDTO.java @@ -0,0 +1,86 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dto; + +import java.io.Serializable; +import java.util.Date; +import lombok.Data; + + +/** + * 授权给开发者的权限集列表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-07-09 + */ +@Data +public class FuncInfoDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * id + */ + private String id; + + /** + * 权限类别 + */ + private String funcscopeCategory; + + /** + * 权限ID + */ + private String funcscopeId; + + /** + * 客户ID + */ + private String customerId; + + /** + * 授权方APPID + */ + private String authorizationInfoAppid; + + /** + * + */ + private Integer delFlag; + + /** + * + */ + 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-client/src/main/java/com/epmet/dto/PreAuthTokenDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/PreAuthTokenDTO.java new file mode 100644 index 0000000000..e0caf8be1c --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/PreAuthTokenDTO.java @@ -0,0 +1,76 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dto; + +import java.io.Serializable; +import java.util.Date; +import lombok.Data; + + +/** + * 预授权码历史记录表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-07-09 + */ +@Data +public class PreAuthTokenDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * id + */ + private String id; + + /** + * 预授权码 【第三方平台方实现授权托管的必备信息,每个预授权码有效期为 10 分钟。需要先获取令牌才能调用】 + */ + private String preAuthToken; + + /** + * 预授权码有效期 单位:s 最长 60*60*2 + */ + private Integer expiresIn; + + /** + * 删除状态 0:正常 1:删除 + */ + private Integer delFlag; + + /** + * 创建人 + */ + 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-client/src/main/java/com/epmet/dto/RefreshAuthorizerAccessTokenDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/RefreshAuthorizerAccessTokenDTO.java new file mode 100644 index 0000000000..aed9b812f7 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/RefreshAuthorizerAccessTokenDTO.java @@ -0,0 +1,91 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dto; + +import java.io.Serializable; +import java.util.Date; +import lombok.Data; + + +/** + * 获取/刷新接口调用令牌记录表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-07-09 + */ +@Data +public class RefreshAuthorizerAccessTokenDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * + */ + private String id; + + /** + * 授权方令牌 + */ + private String authorizerAccessToken; + + /** + * 有效期,单位:秒 + */ + private Integer expiresIn; + + /** + * 刷新令牌 + */ + private String authorizerRefreshToken; + + /** + * 授权方APPID + */ + private String authAppid; + + /** + * 客户ID + */ + private String customerId; + + /** + * + */ + private Integer delFlag; + + /** + * + */ + 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-client/src/main/java/com/epmet/dto/form/AuthCodeFormDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/AuthCodeFormDTO.java new file mode 100644 index 0000000000..71e5d419fd --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/AuthCodeFormDTO.java @@ -0,0 +1,50 @@ +package com.epmet.dto.form; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author zxc + * @CreateTime 2020/7/8 17:53 + */ +@Data +public class AuthCodeFormDTO implements Serializable { + + private static final long serialVersionUID = -6163303184086480522L; + + /** + * 客户ID + */ + private String customerId; + + /** + * 授权方AppId + */ + private String authAppId; + + /** + * 授权码 + */ + private String authCode; + + /** + * 有效期 10min + */ + private Integer expiresIn; + + /** + * 删除状态 0:正常 1:已删除 + */ + private Integer delFlag = 0; + + /** + * 创建者 + */ + private String createdBy = "APP_USER"; + + /** + * 更新者 + */ + private String updatedBy = "APP_USER"; +} diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/AuthorizationInfoFormDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/AuthorizationInfoFormDTO.java new file mode 100644 index 0000000000..f1001e0b4b --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/AuthorizationInfoFormDTO.java @@ -0,0 +1,49 @@ +package com.epmet.dto.form; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author zxc + * @CreateTime 2020/7/9 10:30 + */ +@Data +public class AuthorizationInfoFormDTO implements Serializable { + + private static final long serialVersionUID = -1117036477221128930L; + + /** + * 客户Id + */ + private String customerId; + + /** + * 授权方 appid + */ + private String authorizerAppid; + + /** + * 接口调用令牌(在授权的公众号/小程序具备 API 权限时,才有此返回值) + */ + private String authorizerAccessToken; + + /** + * authorizer_access_token 的有效期(在授权的公众号/小程序具备API权限时,才有此返回值),单位:秒 + */ + private Integer expiresIn; + + /** + * 刷新令牌(在授权的公众号具备API权限时,才有此返回值),刷新令牌主要用于第三方平台获取和刷新已授权用户的 authorizer_access_token。一旦丢失,只能让用户重新授权,才能再次拿到新的刷新令牌。用户重新授权后,之前的刷新令牌会失效 + */ + private String authorizerRefreshToken; + + /** + * + */ + private Integer delFlag = 0; + + private String createdBy = "APP_USER"; + + private String updatedBy = "APP_USER"; +} diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/AuthorizerAccessTokenFormDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/AuthorizerAccessTokenFormDTO.java new file mode 100644 index 0000000000..7d0fa419cf --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/AuthorizerAccessTokenFormDTO.java @@ -0,0 +1,47 @@ +package com.epmet.dto.form; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @Author zxc + * @CreateTime 2020/7/9 17:29 + */ +@Data +public class AuthorizerAccessTokenFormDTO implements Serializable { + + private static final long serialVersionUID = 268927093061495006L; + + /** + * 授权方令牌 + */ + private String authorizerAccessToken; + + /** + * 有效期,单位:秒 + */ + private Integer expiresIn; + + /** + * 刷新令牌 + */ + private String authorizerRefreshToken; + + /** + * 授权方APPID + */ + private String authAppid; + + /** + * 客户ID + */ + private String customerId; + + private Integer delFlag = 0; + + private String createdBy = "APP_USER"; + + private String updatedBy = "APP_USER"; +} diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/ComponentAccessTokenFormDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/ComponentAccessTokenFormDTO.java new file mode 100644 index 0000000000..61e2f5063e --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/ComponentAccessTokenFormDTO.java @@ -0,0 +1,40 @@ +package com.epmet.dto.form; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author zxc + * @CreateTime 2020/7/9 8:54 + */ +@Data +public class ComponentAccessTokenFormDTO implements Serializable { + + private static final long serialVersionUID = -2860559047843944065L; + + /** + * 令牌 【第三方平台接口的调用凭据】 + */ + private String componentAccessToken; + + /** + * 令牌有效期 单位:s 最长 60*60*2 + */ + private Integer expiresIn; + + /** + * 删除状态 0:正常 1:删除 + */ + private Integer delFlag = 0; + + /** + * 创建人 + */ + private String createdBy = "APP_USER"; + + /** + * 更新人 + */ + private String updatedBy = "APP_USER"; +} diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/FuncInfoFormDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/FuncInfoFormDTO.java new file mode 100644 index 0000000000..e8b0c182bb --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/FuncInfoFormDTO.java @@ -0,0 +1,41 @@ +package com.epmet.dto.form; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author zxc + * @CreateTime 2020/7/9 10:43 + */ +@Data +public class FuncInfoFormDTO implements Serializable { + + private static final long serialVersionUID = 5468844633023377254L; + + /** + * 权限类别 + */ + private String funcscopeCategory; + + /** + * 权限ID + */ + private String funcscopeId; + + /** + * 客户ID + */ + private String customerId; + + /** + * 授权方APPID + */ + private String authorizationInfoAppid; + + private Integer delFlag = 0; + + private String createdBy = "APP_USER"; + + private String updatedBy = "APP_USER"; +} diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/PreAuthTokenFormDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/PreAuthTokenFormDTO.java new file mode 100644 index 0000000000..0f07ee3528 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/PreAuthTokenFormDTO.java @@ -0,0 +1,41 @@ +package com.epmet.dto.form; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author zxc + * @CreateTime 2020/7/9 9:15 + */ +@Data +public class PreAuthTokenFormDTO implements Serializable { + + private static final long serialVersionUID = 2970040842154724385L; + + /** + * 预授权码 【第三方平台方实现授权托管的必备信息,每个预授权码有效期为 10 分钟。需要先获取令牌才能调用】 + */ + private String preAuthToken; + + /** + * 预授权码有效期 单位:s 最长 60*60*2 + */ + private Integer expiresIn; + + /** + * 删除状态 0:正常 1:删除 + */ + private Integer delFlag = 0; + + /** + * 创建人 + */ + private String createdBy = "APP_USER"; + + /** + * 更新人 + */ + private String updatedBy = "APP_USER"; + +} diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/result/WillOverDueResultDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/result/WillOverDueResultDTO.java new file mode 100644 index 0000000000..b89826abda --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/result/WillOverDueResultDTO.java @@ -0,0 +1,37 @@ +package com.epmet.dto.result; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author zxc + * @CreateTime 2020/7/9 17:01 + */ +@Data +public class WillOverDueResultDTO implements Serializable { + + private static final long serialVersionUID = -9073227815312384742L; + + /** + * 授权方令牌 + */ + private String authorizerAccessToken; + + /** + * 刷新令牌 + */ + private String authorizerRefreshToken; + + /** + * 授权方AppId + */ + private String authAppId; + + /** + * 客户Id + */ + private String customerId; + + +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ModuleConstant.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ModuleConstant.java index 6b8df00640..bbda7a670b 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ModuleConstant.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ModuleConstant.java @@ -24,6 +24,8 @@ public interface ModuleConstant { */ String COMPONENT_ACCESS_TOKEN = "component_access_token"; + String FUNC_INFO = "func_info"; + /** * 有效期 */ @@ -39,6 +41,8 @@ public interface ModuleConstant { String AUTHORIZER_REFRESH_TOKEN = "authorizer_refresh_token"; + String AUTHORIZER_ACCESS_TOKEN = "authorizer_access_token"; + String AUTH_TICKET = "====================授权票据【ComponentVerifyTicket】:【%s】===================="; String ERROR_TICKET = "微信开放平台,第三方平台获取【验证票据】失败"; @@ -57,17 +61,7 @@ public interface ModuleConstant { String FAILURE_ACCESS_TOKEN = "微信开放平台,第三方平台获取【令牌】失败"; - String TICKET_REDIS_KEY = "epmet:wechartthird:componentverifyticket"; - - String PRE_AUTH_CODE_REDIS_KEY = "epmet:wechartthird:preauthcode"; - - String ACCESS_TOKEN_REDIS_KEY = "epmet:wechartthird:preauthcode"; - - String AUTHORIZER_REFRESH_TOKEN_REDIS_KEY = "epmet:wechartthird:authorizerrefreshtoken"; - - String AUTHORIZATION_CODE_REDIS_KEY = "epmet:wechartthird:authorizationcode"; - String AUTH_INFO_REDIS_KEY = "epmet:wechartthird:authinfo"; diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ThirdApiConstant.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ThirdApiConstant.java new file mode 100644 index 0000000000..96c69002f3 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ThirdApiConstant.java @@ -0,0 +1,26 @@ +package com.epmet.constant; + +/** + * @Author zxc + * @CreateTime 2020/7/8 17:59 + */ +public interface ThirdApiConstant { + + /** + * + */ + String API_CREATE_PREAUTHCODE_URL = "https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode"; + + /** + * 使用授权码获取授权信息请求地址 + */ + String API_QUERY_AUTH_URL = "https://api.weixin.qq.com/cgi-bin/component/api_query_auth"; + + /** + * 获取令牌请求地址 + */ + String API_COMPONENT_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/component/api_component_token"; + + String API_AUTHORIZER_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token"; + +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ThirdPlatformConstant.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ThirdPlatformConstant.java index 618d62010f..09f8af7681 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ThirdPlatformConstant.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ThirdPlatformConstant.java @@ -26,24 +26,4 @@ public interface ThirdPlatformConstant { */ String PLATFORM_COMPONENT_TOKEN = "****************"; - /** - * - */ - String API_CREATE_PREAUTHCODE_URl = "https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token=COMPONENT_ACCESS_TOKEN"; - - /** - * - */ - String API_CREATE_PREAUTHCODE_URL = "https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token=COMPONENT_ACCESS_TOKEN"; - - /** - * 使用授权码获取授权信息请求地址 - */ - String API_QUERY_AUTH_URL = "https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=COMPONENT_ACCESS_TOKEN"; - - /** - * 获取令牌请求地址 - */ - String API_COMPONENT_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/component/api_component_token"; - } diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ThirdRedisKeyConstant.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ThirdRedisKeyConstant.java new file mode 100644 index 0000000000..c4aab903d5 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ThirdRedisKeyConstant.java @@ -0,0 +1,45 @@ +package com.epmet.constant; + +/** + * @Author zxc + * @CreateTime 2020/7/8 18:16 + */ +public interface ThirdRedisKeyConstant { + + /** + * : + */ + String COLON = ":"; + + /** + * component_verify_ticket 【令牌】目录 + */ + String TICKET_REDIS_KEY = "epmet:wechartthird:componentverifyticket"; + + /** + * pre_auth_code 预授权码 + */ + String PRE_AUTH_CODE_REDIS_KEY = "epmet:wechartthird:preauthcode"; + + /** + * component_access_token + */ + String ACCESS_TOKEN_REDIS_KEY = "epmet:wechartthird:componentaccesstoken"; + + /** + * authorizer_refresh_token 刷新令牌,获取授权信息时得到 + */ + String AUTHORIZER_REFRESH_TOKEN_REDIS_KEY = "epmet:wechartthird:authorizerrefreshtoken"; + + /** + * auth_code 授权码 + */ + String AUTH_CODE_REDIS_KEY = "epmet:wechartthird:authcode"; + + /** + * authorization_info 授权信息 + */ + String AUTH_INFO_REDIS_KEY = "epmet:wechartthird:authinfo"; + + +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/WeChatNotifyController.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/WeChatNotifyController.java index 721794c247..f9e98d5114 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/WeChatNotifyController.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/WeChatNotifyController.java @@ -1,13 +1,13 @@ package com.epmet.controller; +import com.epmet.commons.tools.annotation.LoginUser; +import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.Result; import com.epmet.service.ComponentVerifyTicketService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** @@ -46,33 +46,38 @@ public class WeChatNotifyController { /** * @Description 使用授权码获取授权信息 - * @param response - * @param authCode - * @param expiresIn * @author zxc */ - @PostMapping(value = "/authinfobyauthcode") - public Result authInfoByAuthCode(HttpServletResponse response, - @RequestParam("auth_code") String authCode, - @RequestParam("expires_in") String expiresIn) { - componentVerifyTicketService.authInfoByAuthCode(response,authCode,expiresIn); + /*@PostMapping(value = "/authinfobyauthcode") + public Result authInfoByAuthCode() { + componentVerifyTicketService.authInfoByAuthCode(); return new Result(); - } + }*/ /** * @Description 获取/刷新接口调用令牌 - * @param authorizerAppId 授权方AppId * @author zxc */ @PostMapping("refreshtoken") - public Result refreshToken(@RequestParam("authorizer_appid") String authorizerAppId){ - componentVerifyTicketService.refreshToken(authorizerAppId); + public Result refreshToken(){ + componentVerifyTicketService.refreshToken(); return new Result(); } + /** + * @Description 授权回调URL + * @param + * @author zxc + */ @PostMapping("redirecturi") - public Result redirectUri(){ - componentVerifyTicketService.redirectUri(); + public Result redirectUri(HttpServletRequest request, HttpServletResponse response, @LoginUser TokenDto tokenDto, @PathVariable String authAppId){ + componentVerifyTicketService.redirectUri(request,response,tokenDto,authAppId); + return new Result(); + } + + @PostMapping("merge") + public Result merge(){ + return new Result(); } } diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/AuthCodeDao.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/AuthCodeDao.java new file mode 100644 index 0000000000..9ff232bbb4 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/AuthCodeDao.java @@ -0,0 +1,36 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dao; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.dto.form.AuthCodeFormDTO; +import com.epmet.entity.AuthCodeEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * 授权回调url反参表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-07-08 + */ +@Mapper +public interface AuthCodeDao extends BaseDao { + + void insertRedirectAuthCode(AuthCodeFormDTO formDTO); + +} \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/AuthorizationInfoDao.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/AuthorizationInfoDao.java new file mode 100644 index 0000000000..908d924afb --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/AuthorizationInfoDao.java @@ -0,0 +1,41 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dao; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.dto.form.AuthorizationInfoFormDTO; +import com.epmet.entity.AuthorizationInfoEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * 授权信息表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-07-08 + */ +@Mapper +public interface AuthorizationInfoDao extends BaseDao { + + /** + * @Description 插入 授权信息 + * @param formDTO + * @author zxc + */ + void insertAuthorizationInfo(AuthorizationInfoFormDTO formDTO); + +} \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/AuthorizerRefreshTokenDao.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/AuthorizerRefreshTokenDao.java new file mode 100644 index 0000000000..087e781c1a --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/AuthorizerRefreshTokenDao.java @@ -0,0 +1,33 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dao; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.entity.AuthorizerRefreshTokenEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * 授权方的刷新令牌表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-07-08 + */ +@Mapper +public interface AuthorizerRefreshTokenDao extends BaseDao { + +} \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/ComponentAccessTokenDao.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/ComponentAccessTokenDao.java new file mode 100644 index 0000000000..12666b9f01 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/ComponentAccessTokenDao.java @@ -0,0 +1,41 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dao; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.dto.form.ComponentAccessTokenFormDTO; +import com.epmet.entity.ComponentAccessTokenEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * 第三方平台调用凭证 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-07-08 + */ +@Mapper +public interface ComponentAccessTokenDao extends BaseDao { + + /** + * @Description 插入component_access_token信息 + * @param formDTO + * @author zxc + */ + void insertComponentAccessToken(ComponentAccessTokenFormDTO formDTO); + +} \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/FuncInfoDao.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/FuncInfoDao.java new file mode 100644 index 0000000000..fb54341e90 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/FuncInfoDao.java @@ -0,0 +1,39 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dao; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.dto.form.FuncInfoFormDTO; +import com.epmet.entity.FuncInfoEntity; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 授权给开发者的权限集列表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-07-08 + */ +@Mapper +public interface FuncInfoDao extends BaseDao { + + void insertFuncInfo(@Param("funcInfoList") List funcInfoList); + +} \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PaCustomerAgencyDao.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PaCustomerAgencyDao.java index cec7dcc514..179a27459d 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PaCustomerAgencyDao.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PaCustomerAgencyDao.java @@ -20,14 +20,22 @@ package com.epmet.dao; import com.epmet.commons.mybatis.dao.BaseDao; import com.epmet.entity.PaCustomerAgencyEntity; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; /** * 客户根组织信息 * * @author generator generator@elink-cn.com - * @since v1.0.0 2020-07-09 + * @since v1.0.0 2020-07-08 */ @Mapper public interface PaCustomerAgencyDao extends BaseDao { - + + /** + * @Description 根据userId查询客户Id + * @param userId + * @author zxc + */ + String getCustomerIdByUserId(@Param("userId")String userId); + } \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PreAuthTokenDao.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PreAuthTokenDao.java new file mode 100644 index 0000000000..36e0dce88b --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PreAuthTokenDao.java @@ -0,0 +1,41 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dao; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.dto.form.PreAuthTokenFormDTO; +import com.epmet.entity.PreAuthTokenEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * 预授权码历史记录表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-07-08 + */ +@Mapper +public interface PreAuthTokenDao extends BaseDao { + + /** + * @Description 插入 预授权码 + * @param formDTO + * @author zxc + */ + void insertPreAuthToken(PreAuthTokenFormDTO formDTO); + +} \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/RefreshAuthorizerAccessTokenDao.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/RefreshAuthorizerAccessTokenDao.java new file mode 100644 index 0000000000..c6293fbd37 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/RefreshAuthorizerAccessTokenDao.java @@ -0,0 +1,47 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dao; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.dto.form.AuthorizerAccessTokenFormDTO; +import com.epmet.dto.result.WillOverDueResultDTO; +import com.epmet.entity.RefreshAuthorizerAccessTokenEntity; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +/** + * 获取/刷新接口调用令牌记录表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-07-08 + */ +@Mapper +public interface RefreshAuthorizerAccessTokenDao extends BaseDao { + + /** + * @Description 查询即将过期的 authorizer_access_token + * @param + * @author zxc + */ + List checkWillOverDue(); + + void insertAuthorizerAccessToken(AuthorizerAccessTokenFormDTO refreshAccessToken); + + +} \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/AuthCodeEntity.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/AuthCodeEntity.java new file mode 100644 index 0000000000..fd9d829d2c --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/AuthCodeEntity.java @@ -0,0 +1,61 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.entity; + +import com.baomidou.mybatisplus.annotation.TableName; + +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 授权回调url反参表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-07-09 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("auth_code") +public class AuthCodeEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 客户ID + */ + private String customerId; + + /** + * 授权方APPID + */ + private String authAppid; + + /** + * 授权码 + */ + private String authCode; + + /** + * 有效期 10min + */ + private Integer expiresIn; + +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/AuthorizationInfoEntity.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/AuthorizationInfoEntity.java new file mode 100644 index 0000000000..f774abb2cf --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/AuthorizationInfoEntity.java @@ -0,0 +1,66 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.entity; + +import com.baomidou.mybatisplus.annotation.TableName; + +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 授权信息表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-07-09 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("authorization_info") +public class AuthorizationInfoEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 客户ID + */ + private String customerId; + + /** + * 授权方 appid + */ + private String authorizerAppid; + + /** + * 接口调用令牌(在授权的公众号/小程序具备 API 权限时,才有此返回值) + */ + private String authorizerAccessToken; + + /** + * authorizer_access_token 的有效期(在授权的公众号/小程序具备API权限时,才有此返回值),单位:秒 + */ + private Integer expiresIn; + + /** + * 刷新令牌(在授权的公众号具备API权限时,才有此返回值),刷新令牌主要用于第三方平台获取和刷新已授权用户的 authorizer_access_token。一旦丢失,只能让用户重新授权,才能再次拿到新的刷新令牌。用户重新授权后,之前的刷新令牌会失效 + */ + private String authorizerRefreshToken; + +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/AuthorizerRefreshTokenEntity.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/AuthorizerRefreshTokenEntity.java new file mode 100644 index 0000000000..1f6d7127d4 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/AuthorizerRefreshTokenEntity.java @@ -0,0 +1,51 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.entity; + +import com.baomidou.mybatisplus.annotation.TableName; + +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 授权方的刷新令牌表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-07-09 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("authorizer_refresh_token") +public class AuthorizerRefreshTokenEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 授权方的刷新令牌 + */ + private String authorizerRefreshToken; + + /** + * 授权方appid + */ + private String authorizerAppid; + +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/ComponentAccessTokenEntity.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/ComponentAccessTokenEntity.java new file mode 100644 index 0000000000..47ed337383 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/ComponentAccessTokenEntity.java @@ -0,0 +1,51 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.entity; + +import com.baomidou.mybatisplus.annotation.TableName; + +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 第三方平台调用凭证 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-07-09 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("component_access_token") +public class ComponentAccessTokenEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 令牌 【第三方平台接口的调用凭据】 + */ + private String componentAccessToken; + + /** + * 令牌有效期 单位:s 最长 60*60*2 + */ + private Integer expiresIn; + +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/FuncInfoEntity.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/FuncInfoEntity.java new file mode 100644 index 0000000000..fd32f8067f --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/FuncInfoEntity.java @@ -0,0 +1,61 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.entity; + +import com.baomidou.mybatisplus.annotation.TableName; + +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 授权给开发者的权限集列表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-07-09 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("func_info") +public class FuncInfoEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 权限类别 + */ + private String funcscopeCategory; + + /** + * 权限ID + */ + private String funcscopeId; + + /** + * 客户ID + */ + private String customerId; + + /** + * 授权方APPID + */ + private String authorizationInfoAppid; + +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/PreAuthTokenEntity.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/PreAuthTokenEntity.java new file mode 100644 index 0000000000..9ccb82efe1 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/PreAuthTokenEntity.java @@ -0,0 +1,51 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.entity; + +import com.baomidou.mybatisplus.annotation.TableName; + +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 预授权码历史记录表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-07-09 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("pre_auth_token") +public class PreAuthTokenEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 预授权码 【第三方平台方实现授权托管的必备信息,每个预授权码有效期为 10 分钟。需要先获取令牌才能调用】 + */ + private String preAuthToken; + + /** + * 预授权码有效期 单位:s 最长 60*60*2 + */ + private Integer expiresIn; + +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/RefreshAuthorizerAccessTokenEntity.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/RefreshAuthorizerAccessTokenEntity.java new file mode 100644 index 0000000000..0a5c9ddfe2 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/RefreshAuthorizerAccessTokenEntity.java @@ -0,0 +1,66 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.entity; + +import com.baomidou.mybatisplus.annotation.TableName; + +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 获取/刷新接口调用令牌记录表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-07-09 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("refresh_authorizer_access_token") +public class RefreshAuthorizerAccessTokenEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 授权方令牌 + */ + private String authorizerAccessToken; + + /** + * 有效期,单位:秒 + */ + private Integer expiresIn; + + /** + * 刷新令牌 + */ + private String authorizerRefreshToken; + + /** + * 授权方APPID + */ + private String authAppid; + + /** + * 客户ID + */ + private String customerId; + +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/redis/RedisThird.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/redis/RedisThird.java index 3deac90425..07324228de 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/redis/RedisThird.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/redis/RedisThird.java @@ -2,6 +2,9 @@ package com.epmet.redis; import com.epmet.commons.tools.redis.RedisUtils; import com.epmet.constant.ModuleConstant; +import com.epmet.constant.ThirdRedisKeyConstant; +import com.epmet.dto.form.AuthCodeFormDTO; +import com.epmet.dto.form.AuthorizerAccessTokenFormDTO; import com.epmet.dto.result.AuthorizationInfoResultDTO; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -24,60 +27,62 @@ public class RedisThird { private RedisUtils redisUtils; /** - * @Description 缓存 component_access_token 有效期:1小时59分钟 (官网有效期:2H) - * @param accessToken + * @Description 缓存 component_verify_ticket 有效期:9min (官方有效期 10分钟) + * @param verifyTicket * @author zxc */ - public void setComponentAccessToken (String accessToken){ - redisTemplate.opsForValue().set(ModuleConstant.ACCESS_TOKEN_REDIS_KEY+ModuleConstant.COMPONENT_ACCESS_TOKEN, accessToken, 60 * 60 * 2 - 60, TimeUnit.SECONDS); + public void setComponentVerifyTicket(String verifyTicket){ + redisUtils.set(ThirdRedisKeyConstant.TICKET_REDIS_KEY,verifyTicket,-1); } /** - * @Description 获取 component_access_token + * @Description 获取 component_verify_ticket * @param key * @author zxc */ - public String getComponentAccessToken(String key){ - return redisTemplate.opsForValue().get(ModuleConstant.ACCESS_TOKEN_REDIS_KEY+key).toString(); + public String getComponentVerifyTicket(String key){ + return redisTemplate.opsForValue().get(ThirdRedisKeyConstant.TICKET_REDIS_KEY).toString(); } /** - * @Description 获取 component_verify_ticket - * @param key + * @Description 缓存 component_access_token 有效期:1小时59分钟 (官网有效期:2H) + * @param accessToken * @author zxc */ - public String getComponentVerifyTicket(String key){ - return redisTemplate.opsForValue().get(ModuleConstant.TICKET_REDIS_KEY+ModuleConstant.TICKET_REDIS_KEY+key).toString(); + public void setComponentAccessToken (String accessToken){ + String key = ThirdRedisKeyConstant.ACCESS_TOKEN_REDIS_KEY; + redisUtils.set(key,accessToken,-1); } /** - * @Description 缓存 component_verify_ticket 有效期:9min (官方有效期 10分钟) - * @param verifyTicket + * @Description 获取 component_access_token + * @param key * @author zxc */ - public void setComponentVerifyTicket(String verifyTicket){ - redisTemplate.opsForValue().set(ModuleConstant.TICKET_REDIS_KEY+ModuleConstant.TICKET_UNDERLINE_KEY, verifyTicket, 60 * 9, TimeUnit.SECONDS); + public String getComponentAccessToken(String key){ + return redisTemplate.opsForValue().get(ThirdRedisKeyConstant.ACCESS_TOKEN_REDIS_KEY+key).toString(); } /** - * @Description 缓存 pre_auth_code 有效期:9min (官方有效期 10分钟) + * @Description 缓存 pre_auth_code 有效期: (官方有效期 10分钟) * @param authCode pre_auth_code 预授权码 * @param expiresIn expires_in 有效期 * @author zxc */ public void setPreAuthCode(String authCode,Integer expiresIn){ - redisTemplate.opsForValue().set(ModuleConstant.PRE_AUTH_CODE_REDIS_KEY+ModuleConstant.PRE_AUTH_CODE, authCode,expiresIn, TimeUnit.SECONDS); + redisUtils.set(ThirdRedisKeyConstant.PRE_AUTH_CODE_REDIS_KEY+ModuleConstant.PRE_AUTH_CODE,authCode,-1); } /** * @Description 缓存 刷新令牌 * (在授权的公众号具备API权限时,才有此返回值),刷新令牌主要用于第三方平台获取和刷新已授权用户的 authorizer_access_token。 * 一旦丢失,只能让用户重新授权,才能再次拿到新的刷新令牌。用户重新授权后,之前的刷新令牌会失效 - * @param authorizerRefreshToken + * @param refreshAccessToken * @author zxc */ - public void setAuthorizerRefreshToken(String authorizerRefreshToken){ - redisTemplate.opsForValue().set(ModuleConstant.AUTHORIZER_REFRESH_TOKEN_REDIS_KEY+authorizerRefreshToken,authorizerRefreshToken); + public void setAuthorizerRefreshToken(AuthorizerAccessTokenFormDTO refreshAccessToken){ + String key = ThirdRedisKeyConstant.AUTHORIZER_REFRESH_TOKEN_REDIS_KEY + ThirdRedisKeyConstant.COLON + refreshAccessToken.getCustomerId()+ThirdRedisKeyConstant.COLON+refreshAccessToken.getAuthAppid(); + redisUtils.set(key,refreshAccessToken,-1); } /** @@ -86,7 +91,17 @@ public class RedisThird { * @author zxc */ public String getAuthorizerRefreshToken(String key){ - return redisTemplate.opsForValue().get(ModuleConstant.AUTHORIZER_REFRESH_TOKEN_REDIS_KEY+key).toString(); + return redisTemplate.opsForValue().get(ThirdRedisKeyConstant.AUTHORIZER_REFRESH_TOKEN_REDIS_KEY+key).toString(); + } + + /** + * @Description 缓存授权码 auth_Code + * @param + * @author zxc + */ + public void setAuthCode(AuthCodeFormDTO formDTO){ + String key = ThirdRedisKeyConstant.AUTH_CODE_REDIS_KEY+ThirdRedisKeyConstant.COLON+formDTO.getCustomerId(); + redisUtils.set(key,formDTO,-1); } /** @@ -95,12 +110,17 @@ public class RedisThird { * @param key * @author zxc */ - public String getAuthorizationCode(String key){ - return redisTemplate.opsForValue().get(ModuleConstant.AUTHORIZATION_CODE_REDIS_KEY+key).toString(); + public String getAuthCode(String key){ + return redisTemplate.opsForValue().get(ThirdRedisKeyConstant.AUTH_CODE_REDIS_KEY+key).toString(); } + /** + * @Description 缓存授权信息 + * @param authInfo + * @author zxc + */ public void setAuthInfo(AuthorizationInfoResultDTO authInfo){ - redisUtils.set(ModuleConstant.AUTH_INFO_REDIS_KEY,authInfo,-1); + redisUtils.set(ThirdRedisKeyConstant.AUTH_INFO_REDIS_KEY,authInfo,-1); } } diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/ComponentVerifyTicketService.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/ComponentVerifyTicketService.java index 6178dd929d..d12d7cce9a 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/ComponentVerifyTicketService.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/ComponentVerifyTicketService.java @@ -1,5 +1,7 @@ package com.epmet.service; +import com.epmet.commons.tools.security.dto.TokenDto; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -31,20 +33,22 @@ public interface ComponentVerifyTicketService { /** * @Description 使用授权码获取授权信息 - * @param response - * @param authCode - * @param expiresIn * @author zxc */ - void authInfoByAuthCode(HttpServletResponse response,String authCode,String expiresIn); +// void authInfoByAuthCode(); /** * @Description 获取/刷新接口调用令牌 * @param * @author zxc */ - void refreshToken(String authorizerAppId); + void refreshToken(); - void redirectUri(); + /** + * @Description 授权回调URL + * @param + * @author zxc + */ + void redirectUri(HttpServletRequest request, HttpServletResponse response, TokenDto tokenDto,String authAppId); } diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java index 604ccd06f5..c223823929 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java @@ -4,19 +4,25 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.alibaba.nacos.client.config.utils.IOUtils; import com.epmet.commons.tools.constant.NumConstant; +import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.HttpClientManager; import com.epmet.constant.ModuleConstant; -import com.epmet.dao.ComponentVerifyTicketDao; -import com.epmet.dto.form.ComponentVerifyTicketFormDTO; +import com.epmet.constant.ThirdApiConstant; +import com.epmet.dao.*; +import com.epmet.dto.form.*; import com.epmet.dto.result.AuthorizationInfoResultDTO; +import com.epmet.dto.result.WillOverDueResultDTO; import com.epmet.redis.RedisThird; import com.epmet.service.ComponentVerifyTicketService; import com.epmet.util.WXBizMsgCrypt; import com.epmet.util.WXXmlToMapUtil; import com.epmet.util.XmlUtil; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.github.pagehelper.util.StringUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -24,9 +30,9 @@ import org.springframework.transaction.annotation.Transactional; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.InputStream; +import java.io.UnsupportedEncodingException; import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Map; +import java.util.*; import static com.epmet.constant.ThirdPlatformConstant.*; @@ -42,6 +48,20 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe private RedisThird redisThird; @Autowired private ComponentVerifyTicketDao ticketDao; + @Autowired + private AuthCodeDao authCodeDao; + @Autowired + private ComponentAccessTokenDao componentAccessTokenDao; + @Autowired + private PreAuthTokenDao preAuthTokenDao; + @Autowired + private AuthorizationInfoDao authorizationInfoDao; + @Autowired + private FuncInfoDao funcInfoDao; + @Autowired + private PaCustomerAgencyDao paCustomerAgencyDao; + @Autowired + private RefreshAuthorizerAccessTokenDao refreshAuthorizerAccessTokenDao; /** * @Description 获得授权事件的票据 @@ -115,6 +135,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe * @param * @author zxc */ + @Transactional(rollbackFor = Exception.class) @Override public void getComponentAccessToken() { log.info("====================开始执行定时任务获取令牌【component_access_token】===================="); @@ -126,13 +147,20 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe jsonObject.put(ModuleConstant.COMPONENT_APPID, PLATFORM_APP_ID); jsonObject.put(ModuleConstant.COMPONENT_APPSECRET, PLATFORM_APP_SECRET); jsonObject.put(ModuleConstant.TICKET_UNDERLINE_KEY, componentVerifyTicket); - String post = HttpClientManager.getInstance().sendPostByJSON(API_CREATE_PREAUTHCODE_URL, JSON.toJSONString(jsonObject)).getData(); + String post = HttpClientManager.getInstance().sendPostByJSON(ThirdApiConstant.API_COMPONENT_TOKEN_URL, JSON.toJSONString(jsonObject)).getData(); HashMap hashMap = JSON.parseObject(post, HashMap.class); String componentAccessToken = hashMap.get(ModuleConstant.COMPONENT_ACCESS_TOKEN); + String expiresIn = hashMap.get(ModuleConstant.EXPIRES_IN); if (StringUtils.isNotEmpty(componentAccessToken)) { + //令牌信息存DB + ComponentAccessTokenFormDTO formDTO = new ComponentAccessTokenFormDTO(); + formDTO.setComponentAccessToken(componentAccessToken); + formDTO.setExpiresIn(Integer.valueOf(expiresIn)); + componentAccessTokenDao.insertComponentAccessToken(formDTO); + //存缓存 redisThird.setComponentAccessToken(componentAccessToken); } else { - throw new RuntimeException(ModuleConstant.FAILURE_ACCESS_TOKEN); + throw new RenException(ModuleConstant.FAILURE_ACCESS_TOKEN); } } catch (Exception e) { e.printStackTrace(); @@ -141,10 +169,11 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe } /** - * @Description 定时获取预授权码 + * @Description 获取预授权码 * @param * @author zxc */ + @Transactional(rollbackFor = Exception.class) @Override public void preAuthCode() { log.info("====================开始执行定时任务获取预授权码【pre_auth_code】===================="); @@ -152,14 +181,20 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe String accessToken = redisThird.getComponentAccessToken(ModuleConstant.COMPONENT_ACCESS_TOKEN); JSONObject jsonObject = new JSONObject(); jsonObject.put(ModuleConstant.COMPONENT_APPID, PLATFORM_APP_ID); - String post = HttpClientManager.getInstance().sendPostByJSON(API_CREATE_PREAUTHCODE_URL + accessToken, JSON.toJSONString(jsonObject)).getData(); + String post = HttpClientManager.getInstance().sendPostByJSON(ThirdApiConstant.API_CREATE_PREAUTHCODE_URL + accessToken, JSON.toJSONString(jsonObject)).getData(); log.info("====================返回post结果:" + post); HashMap hashMap = JSON.parseObject(post, HashMap.class); - String authCode = hashMap.get(ModuleConstant.PRE_AUTH_CODE); + String preAuthCode = hashMap.get(ModuleConstant.PRE_AUTH_CODE); String expiresIn = hashMap.get(ModuleConstant.EXPIRES_IN); int ex = Integer.valueOf(expiresIn) - NumConstant.SIXTY; - if (StringUtils.isNotEmpty(authCode)) { - redisThird.setPreAuthCode(authCode,ex); + if (StringUtils.isNotEmpty(preAuthCode)) { + //预授权码 存DB + PreAuthTokenFormDTO formDTO = new PreAuthTokenFormDTO(); + formDTO.setPreAuthToken(preAuthCode); + formDTO.setExpiresIn(ex); + preAuthTokenDao.insertPreAuthToken(formDTO); + //预授权码 放入缓存 + redisThird.setPreAuthCode(preAuthCode,ex); } else { throw new RuntimeException("微信开放平台,第三方平台获取【预授权码】失败"); } @@ -170,35 +205,60 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe } /** - * @Description 使用授权码获取授权信息 - * @param response - * @param authCode - * @param expiresIn + * @Description 使用授权码获取授权信息 请求参数:【component_access_token、component_appid、authorization_code】 * @author zxc */ - @Override - public void authInfoByAuthCode(HttpServletResponse response, String authCode, String expiresIn) { + @Transactional(rollbackFor = Exception.class) + public AuthorizationInfoResultDTO authInfoByAuthCode(String authCode,String authAppId,String customerId) { + AuthorizationInfoResultDTO authorizationInfoResultDTO = new AuthorizationInfoResultDTO(); // 获取令牌【component_access_token】 String accessToken = redisThird.getComponentAccessToken(ModuleConstant.COMPONENT_ACCESS_TOKEN); // 使用授权码获取授权信息 JSONObject jsonObject = new JSONObject(); jsonObject.put(ModuleConstant.COMPONENT_APPID, PLATFORM_APP_ID); jsonObject.put(ModuleConstant.AUTHORIZATION_CODE, authCode); - String authInfo; - try { - authInfo = HttpClientManager.getInstance().sendPostByJSON(API_QUERY_AUTH_URL + accessToken, JSON.toJSONString(jsonObject)).getData(); - HashMap hashMap = JSON.parseObject(authInfo, HashMap.class); - Map map = hashMap.get(ModuleConstant.AUTHORIZATION_INFO); - AuthorizationInfoResultDTO authorizationInfoResultDTO = mapToEntity(map, AuthorizationInfoResultDTO.class); - redisThird.setAuthInfo(authorizationInfoResultDTO); - String authorizerRefreshToken = map.get(ModuleConstant.AUTHORIZER_REFRESH_TOKEN).toString(); - redisThird.setAuthorizerRefreshToken(authorizerRefreshToken); - } catch (Exception e) { - e.printStackTrace(); + String authInfo = HttpClientManager.getInstance().sendPostByJSON(ThirdApiConstant.API_QUERY_AUTH_URL + accessToken, JSON.toJSONString(jsonObject)).getData(); + HashMap hashMap = JSON.parseObject(authInfo, HashMap.class); + Map map = hashMap.get(ModuleConstant.AUTHORIZATION_INFO); + authorizationInfoResultDTO = mapToEntity(map, AuthorizationInfoResultDTO.class); + //授权信息分为两张表,基础信息authorization_info,授权列表func_info + // 1. 基础信息 + AuthorizationInfoFormDTO authInfoDTO = new AuthorizationInfoFormDTO(); + authInfoDTO.setAuthorizerAppid(authorizationInfoResultDTO.getAuthorizer_appid()); + authInfoDTO.setAuthorizerAccessToken(authorizationInfoResultDTO.getAuthorizer_access_token()); + authInfoDTO.setAuthorizerRefreshToken(authorizationInfoResultDTO.getAuthorizer_refresh_token()); + authInfoDTO.setExpiresIn(Integer.valueOf(authorizationInfoResultDTO.getExpires_in())); + authInfoDTO.setCustomerId(customerId); + authorizationInfoDao.insertAuthorizationInfo(authInfoDTO); + // 获取/刷新接口调用令牌记录表 插入 + AuthorizerAccessTokenFormDTO refreshAccessToken = new AuthorizerAccessTokenFormDTO(); + refreshAccessToken.setAuthAppid(authAppId); + refreshAccessToken.setCustomerId(customerId); + refreshAccessToken.setAuthorizerAccessToken(authorizationInfoResultDTO.getAuthorizer_access_token()); + refreshAccessToken.setAuthorizerRefreshToken(authorizationInfoResultDTO.getAuthorizer_refresh_token()); + refreshAccessToken.setExpiresIn(Integer.valueOf(authorizationInfoResultDTO.getExpires_in())); + refreshAuthorizerAccessTokenDao.insertAuthorizerAccessToken(refreshAccessToken); + // 2. 权限列表 + List funcInfos = new ArrayList<>(); + List func_info = authorizationInfoResultDTO.getFunc_info(); + for (Map map1 : func_info) { + List key = (List)map1.keySet(); + FuncInfoFormDTO fu = new FuncInfoFormDTO(); + String funcscopeCategory = key.get(NumConstant.ZERO).toString(); + fu.setFuncscopeCategory(funcscopeCategory); + Map funcscope = (Map) map1.get(funcscopeCategory); + String funcscopeId = funcscope.get("id").toString(); + fu.setFuncscopeId(funcscopeId); + fu.setAuthorizationInfoAppid(authorizationInfoResultDTO.getAuthorizer_appid()); + fu.setCustomerId(customerId); + funcInfos.add(fu); } - - // 重定向地址 -// response.sendRedirect("/wechat/authcode"); + funcInfoDao.insertFuncInfo(funcInfos); + // 授权信息放入缓存 + redisThird.setAuthInfo(authorizationInfoResultDTO); + //authorizer_refresh_token 放入缓存 + redisThird.setAuthorizerRefreshToken(refreshAccessToken); + return authorizationInfoResultDTO; } /** @@ -206,19 +266,69 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe * @param * @author zxc */ + @Transactional(rollbackFor = Exception.class) @Override - public void refreshToken(String authorizerAppId) { - JSONObject jsonObject = new JSONObject(); - //todo 授权方appid从哪来,每个用户的刷新token - //授权方AppId -// jsonObject.put(ModuleConstant.AUTHORIZER_APPID,authorizerAppId); - //第三方平台AppId - jsonObject.put(ModuleConstant.COMPONENT_APPID,PLATFORM_APP_ID); - jsonObject.put("",redisThird.getAuthorizerRefreshToken("")); + public void refreshToken() { + List willOverDueResultDTOS = refreshAuthorizerAccessTokenDao.checkWillOverDue(); + if (willOverDueResultDTOS.size() != NumConstant.ZERO && null != willOverDueResultDTOS){ + willOverDueResultDTOS.forEach(willOverDueDTO -> { + JSONObject jsonObject = new JSONObject(); + //授权方AppId + jsonObject.put(ModuleConstant.AUTHORIZER_APPID,willOverDueDTO.getAuthAppId()); + //第三方平台AppId + jsonObject.put(ModuleConstant.COMPONENT_APPID,PLATFORM_APP_ID); + jsonObject.put(ModuleConstant.AUTHORIZER_REFRESH_TOKEN,willOverDueDTO.getAuthorizerRefreshToken()); + String data = HttpClientManager.getInstance().sendPostByJSON(ThirdApiConstant.API_AUTHORIZER_TOKEN_URL, JSON.toJSONString(jsonObject)).getData(); + Map map = JSON.parseObject(data, HashMap.class); + //authorizer_access_token + String authorizerAccessToken = map.get(ModuleConstant.AUTHORIZER_ACCESS_TOKEN).toString(); + String expiresIn = map.get(ModuleConstant.EXPIRES_IN).toString(); + String authorizerRefreshToken = map.get(ModuleConstant.AUTHORIZER_REFRESH_TOKEN).toString(); + //更新DB + AuthorizerAccessTokenFormDTO formDTO = new AuthorizerAccessTokenFormDTO(); + formDTO.setAuthorizerAccessToken(authorizerAccessToken); + formDTO.setAuthorizerRefreshToken(authorizerRefreshToken); + formDTO.setExpiresIn(Integer.valueOf(expiresIn)); + formDTO.setCustomerId(willOverDueDTO.getCustomerId()); + formDTO.setAuthAppid(willOverDueDTO.getAuthAppId()); + refreshAuthorizerAccessTokenDao.insertAuthorizerAccessToken(formDTO); + + //缓存 refreshAuthorizerAccessToken + redisThird.setAuthorizerRefreshToken(formDTO); + }); + } + } + /** + * @Description 授权回调URL + * @param + * @author zxc + */ + @Transactional(rollbackFor = Exception.class) @Override - public void redirectUri() { + public void redirectUri(HttpServletRequest request, HttpServletResponse response, TokenDto tokenDto,String authAppId) { + String userId = tokenDto.getUserId(); + String customerId = paCustomerAgencyDao.getCustomerIdByUserId(userId); + try { + request.setCharacterEncoding("UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + response.setCharacterEncoding("UTF-8"); + String authCode = request.getParameter("auth_code"); + String expiresIn = request.getParameter("expires_in"); + //authCode存数据库 + AuthCodeFormDTO formDTO = new AuthCodeFormDTO(); + formDTO.setAuthCode(authCode); + formDTO.setExpiresIn(Integer.valueOf(expiresIn)); + formDTO.setAuthAppId(authAppId); + formDTO.setCustomerId(customerId); + authCodeDao.insertRedirectAuthCode(formDTO); + //authCode存缓存 + redisThird.setAuthCode(formDTO); + // 获取授权信息 + AuthorizationInfoResultDTO authorizationInfoResultDTO = this.authInfoByAuthCode(authCode, authAppId, customerId); } diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/AuthCodeDao.xml b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/AuthCodeDao.xml new file mode 100644 index 0000000000..5fcd3c0db1 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/AuthCodeDao.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + INSERT INTO auth_code ( ID, CUSTOMER_ID, AUTH_APPID, AUTH_CODE, EXPIRES_IN, DEL_FLAG, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME ) + VALUES + ( + REPLACE ( UUID(), '-', '' ), + #{customerId}, + #{authAppId}, + #{authCode}, + #{expiresIn}, + #{delFlag}, + #{createdBy}, + NOW(), + #{updatedBy}, + NOW() + ) + + + \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/AuthorizationInfoDao.xml b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/AuthorizationInfoDao.xml new file mode 100644 index 0000000000..88c9cb5b5a --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/AuthorizationInfoDao.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + INSERT INTO authorization_info ( ID, CUSTOMER_ID, AUTHORIZER_APPID, AUTHORIZER_ACCESS_TOKEN, EXPIRES_IN, AUTHORIZER_REFRESH_TOKEN, DEL_FLAG, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME ) + VALUES + ( + REPLACE ( UUID(), '-', '' ), + #{customerId}, + #{authorizerAppid}, + #{authorizerAccessToken}, + #{expiresIn}, + #{authorizerRefreshToken}, + #{delFlag}, + #{createdBy}, + NOW(), + #{updatedBy}, + NOW() + ) + + + \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/AuthorizerRefreshTokenDao.xml b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/AuthorizerRefreshTokenDao.xml new file mode 100644 index 0000000000..6cfa1d6b86 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/AuthorizerRefreshTokenDao.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/ComponentAccessTokenDao.xml b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/ComponentAccessTokenDao.xml new file mode 100644 index 0000000000..bf76c092c8 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/ComponentAccessTokenDao.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + INSERT INTO component_access_token ( ID, COMPONENT_ACCESS_TOKEN, EXPIRES_IN, DEL_FLAG, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME ) + VALUES + ( + REPLACE ( UUID(), '-', '' ), + #{componentAccessToken}, + #{expiresIn}, + #{delFlag}, + #{createdBy}, + NOW(), + #{updatedBy}, + NOW() + ) + + + \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/FuncInfoDao.xml b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/FuncInfoDao.xml new file mode 100644 index 0000000000..332b2e672f --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/FuncInfoDao.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + INSERT INTO func_info ( ID, FUNCSCOPE_CATEGORY, FUNCSCOPE_ID, CUSTOMER_ID, AUTHORIZATION_INFO_APPID, DEL_FLAG, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME ) + VALUES + ( + REPLACE ( UUID(), '-', '' ), + #{func.funcscopeCategory}, + #{func.funcscopeId}, + #{func.customerId} + #{func.authorizationInfoAppid}, + #{func.delFlag}, + #{func.createdBy}, + NOW(), + #{func.updatedBy}, + NOW() + ) + + + + \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PaCustomerAgencyDao.xml b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PaCustomerAgencyDao.xml index 5867f5a86c..420dfac6ad 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PaCustomerAgencyDao.xml +++ b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PaCustomerAgencyDao.xml @@ -3,5 +3,16 @@ + + \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PreAuthTokenDao.xml b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PreAuthTokenDao.xml new file mode 100644 index 0000000000..e0eeb08e23 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PreAuthTokenDao.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + INSERT INTO pre_auth_token ( ID, PRE_AUTH_TOKEN, EXPIRES_IN, DEL_FLAG, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME ) + VALUES + ( + REPLACE ( UUID(), '-', '' ), + #{preAuthToken}, + #{expiresIn}, + #{delFlag}, + #{createdBy}, + NOW(), + #{updatedBy}, + NOW() + ) + + + \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/RefreshAuthorizerAccessTokenDao.xml b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/RefreshAuthorizerAccessTokenDao.xml new file mode 100644 index 0000000000..9670ff2e90 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/RefreshAuthorizerAccessTokenDao.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + INSERT INTO refresh_authorizer_access_token ( ID, AUTHORIZER_ACCESS_TOKEN, EXPIRES_IN, AUTHORIZER_REFRESH_TOKEN, AUTH_APPID, CUSTOMER_ID, DEL_FLAG, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME ) + VALUES + ( + REPLACE ( UUID(), '-', '' ), + #{authorizerAccessToken}, + #{expiresIn}, + #{authorizerRefreshToken}, + #{authAppid}, + #{customerId}, + #{delFlag}, + #{createdBy}, + NOW(), + #{updatedBy}, + NOW() + ) + + + \ No newline at end of file From e2a8e343243dc10db83fbafaa336b8360b544b71 Mon Sep 17 00:00:00 2001 From: zxc <954985706@qq.com> Date: Fri, 10 Jul 2020 09:22:01 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E7=AC=AC=E4=B8=89?= =?UTF-8?q?=E6=96=B9=E5=B9=B3=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AuthRedirectController.java | 37 +++++++++++++++++++ .../controller/WeChatNotifyController.java | 31 ---------------- .../com/epmet/dao/AuthorizationInfoDao.java | 8 ++++ .../epmet/dao/ComponentAccessTokenDao.java | 2 + .../main/java/com/epmet/dao/FuncInfoDao.java | 12 ++++++ .../java/com/epmet/dao/PreAuthTokenDao.java | 7 ++++ .../dao/RefreshAuthorizerAccessTokenDao.java | 12 ++++++ .../service/ComponentVerifyTicketService.java | 6 --- .../ComponentVerifyTicketServiceImpl.java | 12 ++++++ .../resources/mapper/AuthorizationInfoDao.xml | 5 +++ .../mapper/ComponentAccessTokenDao.xml | 4 ++ .../src/main/resources/mapper/FuncInfoDao.xml | 6 +++ .../main/resources/mapper/PreAuthTokenDao.xml | 6 +++ .../RefreshAuthorizerAccessTokenDao.xml | 5 +++ 14 files changed, 116 insertions(+), 37 deletions(-) create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/AuthRedirectController.java diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/AuthRedirectController.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/AuthRedirectController.java new file mode 100644 index 0000000000..cb38cf1014 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/AuthRedirectController.java @@ -0,0 +1,37 @@ +package com.epmet.controller; + +import com.epmet.commons.tools.annotation.LoginUser; +import com.epmet.commons.tools.security.dto.TokenDto; +import com.epmet.commons.tools.utils.Result; +import com.epmet.service.ComponentVerifyTicketService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * @Author zxc + * @CreateTime 2020/7/10 9:04 + */ +@RestController +@RequestMapping("mpweb") +public class AuthRedirectController { + + @Autowired + private ComponentVerifyTicketService componentVerifyTicketService; + + /** + * @Description 授权回调URL + * @param + * @author zxc + */ + public Result redirectUri(HttpServletRequest request, HttpServletResponse response, @LoginUser TokenDto tokenDto, @RequestParam("authAppId")String authAppId){ + componentVerifyTicketService.redirectUri(request,response,tokenDto,authAppId); + return new Result(); + } + +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/WeChatNotifyController.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/WeChatNotifyController.java index f9e98d5114..a63583e38c 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/WeChatNotifyController.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/WeChatNotifyController.java @@ -1,15 +1,10 @@ package com.epmet.controller; -import com.epmet.commons.tools.annotation.LoginUser; -import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.Result; import com.epmet.service.ComponentVerifyTicketService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - /** * @Author zxc * @CreateTime 2020/7/8 15:06 @@ -44,16 +39,6 @@ public class WeChatNotifyController { return new Result(); } - /** - * @Description 使用授权码获取授权信息 - * @author zxc - */ - /*@PostMapping(value = "/authinfobyauthcode") - public Result authInfoByAuthCode() { - componentVerifyTicketService.authInfoByAuthCode(); - return new Result(); - }*/ - /** * @Description 获取/刷新接口调用令牌 * @author zxc @@ -64,20 +49,4 @@ public class WeChatNotifyController { return new Result(); } - /** - * @Description 授权回调URL - * @param - * @author zxc - */ - @PostMapping("redirecturi") - public Result redirectUri(HttpServletRequest request, HttpServletResponse response, @LoginUser TokenDto tokenDto, @PathVariable String authAppId){ - componentVerifyTicketService.redirectUri(request,response,tokenDto,authAppId); - return new Result(); - } - - @PostMapping("merge") - public Result merge(){ - - return new Result(); - } } diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/AuthorizationInfoDao.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/AuthorizationInfoDao.java index 908d924afb..02539669af 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/AuthorizationInfoDao.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/AuthorizationInfoDao.java @@ -21,6 +21,7 @@ import com.epmet.commons.mybatis.dao.BaseDao; import com.epmet.dto.form.AuthorizationInfoFormDTO; import com.epmet.entity.AuthorizationInfoEntity; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; /** * 授权信息表 @@ -37,5 +38,12 @@ public interface AuthorizationInfoDao extends BaseDao { * @author zxc */ void insertAuthorizationInfo(AuthorizationInfoFormDTO formDTO); + + /** + * @Description 逻辑删除授权信息 + * @param customerId + * @author zxc + */ + void updateOldAuthorizationInfo(@Param("customerId")String customerId); } \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/ComponentAccessTokenDao.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/ComponentAccessTokenDao.java index 12666b9f01..4615c22728 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/ComponentAccessTokenDao.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/ComponentAccessTokenDao.java @@ -37,5 +37,7 @@ public interface ComponentAccessTokenDao extends BaseDao { + /** + * @Description 插入授权列表信息 + * @param funcInfoList + * @author zxc + */ void insertFuncInfo(@Param("funcInfoList") List funcInfoList); + + /** + * @Description 逻辑删除 权限列表 + * @param customerId + * @author zxc + */ + void updateOldFuncInfo(@Param("customerId")String customerId); } \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PreAuthTokenDao.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PreAuthTokenDao.java index 36e0dce88b..defe7f5bb0 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PreAuthTokenDao.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PreAuthTokenDao.java @@ -37,5 +37,12 @@ public interface PreAuthTokenDao extends BaseDao { * @author zxc */ void insertPreAuthToken(PreAuthTokenFormDTO formDTO); + + /** + * @Description 逻辑删 pre_auth_code + * @param + * @author zxc + */ + void updateOldPreAuthCode(); } \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/RefreshAuthorizerAccessTokenDao.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/RefreshAuthorizerAccessTokenDao.java index c6293fbd37..ecd62336d5 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/RefreshAuthorizerAccessTokenDao.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/RefreshAuthorizerAccessTokenDao.java @@ -22,6 +22,7 @@ import com.epmet.dto.form.AuthorizerAccessTokenFormDTO; import com.epmet.dto.result.WillOverDueResultDTO; import com.epmet.entity.RefreshAuthorizerAccessTokenEntity; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; import java.util.List; @@ -41,7 +42,18 @@ public interface RefreshAuthorizerAccessTokenDao extends BaseDao checkWillOverDue(); + /** + * @Description 插入 authorizer_access_token + * @param refreshAccessToken + * @author zxc + */ void insertAuthorizerAccessToken(AuthorizerAccessTokenFormDTO refreshAccessToken); + /** + * @Description 逻辑删除 授权方的authorizer_access_token + * @param customerId + * @author zxc + */ + void updateOldAuthorizerAccessToken(@Param("customerId")String customerId); } \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/ComponentVerifyTicketService.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/ComponentVerifyTicketService.java index d12d7cce9a..a20ff2d1f4 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/ComponentVerifyTicketService.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/ComponentVerifyTicketService.java @@ -31,12 +31,6 @@ public interface ComponentVerifyTicketService { */ void preAuthCode(); - /** - * @Description 使用授权码获取授权信息 - * @author zxc - */ -// void authInfoByAuthCode(); - /** * @Description 获取/刷新接口调用令牌 * @param diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java index c223823929..f66db43c0e 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java @@ -156,6 +156,8 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe ComponentAccessTokenFormDTO formDTO = new ComponentAccessTokenFormDTO(); formDTO.setComponentAccessToken(componentAccessToken); formDTO.setExpiresIn(Integer.valueOf(expiresIn)); + //先逻辑删,在插入 + componentAccessTokenDao.updateOldComponentAccessToken(); componentAccessTokenDao.insertComponentAccessToken(formDTO); //存缓存 redisThird.setComponentAccessToken(componentAccessToken); @@ -192,6 +194,8 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe PreAuthTokenFormDTO formDTO = new PreAuthTokenFormDTO(); formDTO.setPreAuthToken(preAuthCode); formDTO.setExpiresIn(ex); + //先逻辑删除,在插入DB + preAuthTokenDao.updateOldPreAuthCode(); preAuthTokenDao.insertPreAuthToken(formDTO); //预授权码 放入缓存 redisThird.setPreAuthCode(preAuthCode,ex); @@ -229,6 +233,8 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe authInfoDTO.setAuthorizerRefreshToken(authorizationInfoResultDTO.getAuthorizer_refresh_token()); authInfoDTO.setExpiresIn(Integer.valueOf(authorizationInfoResultDTO.getExpires_in())); authInfoDTO.setCustomerId(customerId); + //先逻辑删除,在插入 + authorizationInfoDao.updateOldAuthorizationInfo(customerId); authorizationInfoDao.insertAuthorizationInfo(authInfoDTO); // 获取/刷新接口调用令牌记录表 插入 AuthorizerAccessTokenFormDTO refreshAccessToken = new AuthorizerAccessTokenFormDTO(); @@ -237,6 +243,8 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe refreshAccessToken.setAuthorizerAccessToken(authorizationInfoResultDTO.getAuthorizer_access_token()); refreshAccessToken.setAuthorizerRefreshToken(authorizationInfoResultDTO.getAuthorizer_refresh_token()); refreshAccessToken.setExpiresIn(Integer.valueOf(authorizationInfoResultDTO.getExpires_in())); + //先逻辑删除,再插入 + refreshAuthorizerAccessTokenDao.updateOldAuthorizerAccessToken(customerId); refreshAuthorizerAccessTokenDao.insertAuthorizerAccessToken(refreshAccessToken); // 2. 权限列表 List funcInfos = new ArrayList<>(); @@ -253,6 +261,8 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe fu.setCustomerId(customerId); funcInfos.add(fu); } + //先逻辑删除,在插入 + funcInfoDao.updateOldFuncInfo(customerId); funcInfoDao.insertFuncInfo(funcInfos); // 授权信息放入缓存 redisThird.setAuthInfo(authorizationInfoResultDTO); @@ -291,6 +301,8 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe formDTO.setExpiresIn(Integer.valueOf(expiresIn)); formDTO.setCustomerId(willOverDueDTO.getCustomerId()); formDTO.setAuthAppid(willOverDueDTO.getAuthAppId()); + //先逻辑删除,在插入 + refreshAuthorizerAccessTokenDao.updateOldAuthorizerAccessToken(willOverDueDTO.getCustomerId()); refreshAuthorizerAccessTokenDao.insertAuthorizerAccessToken(formDTO); //缓存 refreshAuthorizerAccessToken diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/AuthorizationInfoDao.xml b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/AuthorizationInfoDao.xml index 88c9cb5b5a..97929fa2d6 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/AuthorizationInfoDao.xml +++ b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/AuthorizationInfoDao.xml @@ -36,4 +36,9 @@ ) + + + update authorization_info set del_flag = 0 where customer_id = #{customerId} + + \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/ComponentAccessTokenDao.xml b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/ComponentAccessTokenDao.xml index bf76c092c8..7e294a150a 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/ComponentAccessTokenDao.xml +++ b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/ComponentAccessTokenDao.xml @@ -30,4 +30,8 @@ ) + + update component_access_token set del_flag = 1 + + \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/FuncInfoDao.xml b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/FuncInfoDao.xml index 332b2e672f..0982fcefd6 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/FuncInfoDao.xml +++ b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/FuncInfoDao.xml @@ -16,6 +16,7 @@ + INSERT INTO func_info ( ID, FUNCSCOPE_CATEGORY, FUNCSCOPE_ID, CUSTOMER_ID, AUTHORIZATION_INFO_APPID, DEL_FLAG, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME ) @@ -35,4 +36,9 @@ + + + update func_info set del_flag = 0 where customer_id = #{customerId} + + \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PreAuthTokenDao.xml b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PreAuthTokenDao.xml index e0eeb08e23..bac47ff2f3 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PreAuthTokenDao.xml +++ b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PreAuthTokenDao.xml @@ -14,6 +14,7 @@ + INSERT INTO pre_auth_token ( ID, PRE_AUTH_TOKEN, EXPIRES_IN, DEL_FLAG, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME ) VALUES @@ -29,4 +30,9 @@ ) + + + update pre_auth_token set del_flag = 0 + + \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/RefreshAuthorizerAccessTokenDao.xml b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/RefreshAuthorizerAccessTokenDao.xml index 9670ff2e90..fbc94fa431 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/RefreshAuthorizerAccessTokenDao.xml +++ b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/RefreshAuthorizerAccessTokenDao.xml @@ -49,4 +49,9 @@ ) + + + update refresh_authorizer_access_token set del_flag = 0 where customer_id = #{customerId} + + \ No newline at end of file From 713d3e408eed4e491d488cabbd188fc7a528cc1d Mon Sep 17 00:00:00 2001 From: zxc <954985706@qq.com> Date: Fri, 10 Jul 2020 09:58:53 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E7=AC=AC=E4=B8=89?= =?UTF-8?q?=E6=96=B9=E5=B9=B3=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/epmet/constant/ModuleConstant.java | 57 +++++----------- .../constant/ThirdRunTimeInfoConstant.java | 49 ++++++++++++++ .../controller/AuthRedirectController.java | 1 - .../ComponentVerifyTicketServiceImpl.java | 66 ++++++++++--------- 4 files changed, 101 insertions(+), 72 deletions(-) create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ThirdRunTimeInfoConstant.java diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ModuleConstant.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ModuleConstant.java index bbda7a670b..77bfbe8263 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ModuleConstant.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ModuleConstant.java @@ -6,63 +6,40 @@ package com.epmet.constant; */ public interface ModuleConstant { - String TICKET_KEY = "ComponentVerifyTicket"; + String FUNC_INFO = "func_info"; + //获得授权事件的票据 如下 + String UTF8 = "UTF-8"; + String MSG_SIGNATURE = "msg_signature"; + String TIMESTAMP = "timestamp"; + String NONCE = "nonce"; + String INFO_TYPE = "InfoType"; String TICKET_UNDERLINE_KEY = "component_verify_ticket"; - + String TICKET_KEY = "ComponentVerifyTicket"; + String UNAUTHORIZED = "unauthorized"; + String NULL_CHAR = ""; String SUCCESS = "success"; - /** - * 第三方平台 AppId - */ + // 获取 component_access_token 如下 String COMPONENT_APPID = "component_appid"; - String COMPONENT_APPSECRET = "component_appsecret"; - - /** - * 第三方平台 access_token - */ String COMPONENT_ACCESS_TOKEN = "component_access_token"; - - String FUNC_INFO = "func_info"; - - /** - * 有效期 - */ String EXPIRES_IN = "expires_in"; + //获取预授权码 如下 String PRE_AUTH_CODE = "pre_auth_code"; + //使用授权码获取授权信息 如下 String AUTHORIZATION_CODE = "authorization_code"; - - String AUTHORIZER_APPID = "authorizer_appid"; - String AUTHORIZATION_INFO = "authorization_info"; + //获取/刷新接口调用令牌 如下 + String AUTHORIZER_APPID = "authorizer_appid"; String AUTHORIZER_REFRESH_TOKEN = "authorizer_refresh_token"; - String AUTHORIZER_ACCESS_TOKEN = "authorizer_access_token"; - String AUTH_TICKET = "====================授权票据【ComponentVerifyTicket】:【%s】===================="; - - String ERROR_TICKET = "微信开放平台,第三方平台获取【验证票据】失败"; - - String END_TICKET = "==============================结束授权事件接收URL================================="; - - String START_RECEIVE = "==============================开始授权事件接收URL================================="; - - String URL_TICKET = "授权事件接收URL,验证票据"; - - String SUCCESS_TICKET = "第三方平台授权事件接收URL,验证票据成功"; - - String ERROR_URL_TICKET = "第三方平台授权事件接收URL,验证票据异常"; - - String SUCCESS_ACCESS_TOKEN = "====================结束执行定时任务获取令牌【component_access_token】===================="; - - String FAILURE_ACCESS_TOKEN = "微信开放平台,第三方平台获取【令牌】失败"; - - - + //授权回调URL 如下 + String AUTH_CODE = "auth_code"; } diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ThirdRunTimeInfoConstant.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ThirdRunTimeInfoConstant.java new file mode 100644 index 0000000000..6ff00a3e80 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ThirdRunTimeInfoConstant.java @@ -0,0 +1,49 @@ +package com.epmet.constant; + +/** + * @Author zxc + * @CreateTime 2020/7/10 9:27 + */ +public interface ThirdRunTimeInfoConstant { + + String AUTH_TICKET = "====================授权票据【ComponentVerifyTicket】:【%s】===================="; + + String ERROR_TICKET = "微信开放平台,第三方平台获取【验证票据】失败"; + + String END_TICKET = "==============================结束授权事件接收URL================================="; + + String START_RECEIVE = "==============================开始授权事件接收URL================================="; + + String URL_TICKET = "授权事件接收URL,验证票据"; + + String SUCCESS_TICKET = "第三方平台授权事件接收URL,验证票据成功"; + + String ERROR_URL_TICKET = "第三方平台授权事件接收URL,验证票据异常"; + + String SUCCESS_ACCESS_TOKEN = "====================结束执行定时任务获取令牌【component_access_token】===================="; + + String FAILURE_ACCESS_TOKEN = "微信开放平台,第三方平台获取【令牌】失败"; + + String ENCRYPT = "Encrypt:%s"; + + String MSG = "msg:%s"; + + String START_GET_COMPONENT_ACCESS_TOKEN = "====================开始执行定时任务获取令牌【component_access_token】===================="; + + String START_DELETE_COMPONENT_ACCESS_TOKEN = "====================开始逻辑删除【component_access_token】===================="; + + String START_GET_PRE_AUTH_CODE = "====================开始执行定时任务获取预授权码【pre_auth_code】===================="; + + String POST_RESULT = "====================返回post结果:%s"; + + String FAILURE_GET_PRE_AUTH_CODE = "微信开放平台,第三方平台获取【预授权码】失败"; + + String END_GET_PRE_AUTH_CODE = "====================结束获取预授权码【pre_auth_code】===================="; + + String START_GET_AUTH_INFO = "=====================开始获取【authorization_info】====================="; + + String START_INSERT_FUNC_INFO = "================================开始插入【func_info】===================================="; + + String END_GET_AUTH_INFO = "=====================结束获取【authorization_info】====================="; + +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/AuthRedirectController.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/AuthRedirectController.java index cb38cf1014..4e4166f0b0 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/AuthRedirectController.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/AuthRedirectController.java @@ -5,7 +5,6 @@ import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.Result; import com.epmet.service.ComponentVerifyTicketService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java index f66db43c0e..cb13287289 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java @@ -9,6 +9,7 @@ import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.HttpClientManager; import com.epmet.constant.ModuleConstant; import com.epmet.constant.ThirdApiConstant; +import com.epmet.constant.ThirdRunTimeInfoConstant; import com.epmet.dao.*; import com.epmet.dto.form.*; import com.epmet.dto.result.AuthorizationInfoResultDTO; @@ -18,11 +19,9 @@ import com.epmet.service.ComponentVerifyTicketService; import com.epmet.util.WXBizMsgCrypt; import com.epmet.util.WXXmlToMapUtil; import com.epmet.util.XmlUtil; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.github.pagehelper.util.StringUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -35,6 +34,7 @@ import java.lang.reflect.Field; import java.util.*; import static com.epmet.constant.ThirdPlatformConstant.*; +import static com.epmet.constant.ThirdRunTimeInfoConstant.*; /** * @Author zxc @@ -71,24 +71,24 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe @Transactional(rollbackFor = Exception.class) @Override public String componentVerifyTicket(HttpServletRequest request, HttpServletResponse response) { - log.info(ModuleConstant.START_RECEIVE); + log.info(ThirdRunTimeInfoConstant.START_RECEIVE); try { - request.setCharacterEncoding("UTF-8"); - response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding(ModuleConstant.UTF8); + response.setCharacterEncoding(ModuleConstant.UTF8); // 微信加密签名 - String msgSignature = request.getParameter("msg_signature"); + String msgSignature = request.getParameter(ModuleConstant.MSG_SIGNATURE); // 时间戳 - String timeStamp = request.getParameter("timestamp"); + String timeStamp = request.getParameter(ModuleConstant.TIMESTAMP); // 随机数 - String nonce = request.getParameter("nonce"); + String nonce = request.getParameter(ModuleConstant.NONCE); // 从请求中读取整个post数据 InputStream inputStream; String postData = null; inputStream = request.getInputStream(); - postData= IOUtils.toString(inputStream, "UTF-8"); + postData= IOUtils.toString(inputStream,ModuleConstant.UTF8); //从XML中获取标签内的密文文本 String encrypt = XmlUtil.toXml(postData); - log.info("Encrypt:"+encrypt); + log.info(String.format(ThirdRunTimeInfoConstant.ENCRYPT,encrypt)); //格式化密文文本,否则没有标签,会解密失败,参考官方的加解密代码JAVA版本 String format = ""; String fromXML = String.format(format, encrypt); @@ -102,14 +102,14 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe // 解密消息 msg = wxcpt.decryptMsg(msgSignature, timeStamp, nonce, fromXML); } - log.info("msg:"+msg); + log.info(String.format(ThirdRunTimeInfoConstant.MSG,msg)); // 将xml转为map Map result = WXXmlToMapUtil.xmlToMap(msg); - String infotype = result.get("InfoType"); //获取infotype,注:微信开放平台文档中标明固定为:"component_verify_ticket",但参考其他代码,还包含authorized??? + String infotype = result.get(ModuleConstant.INFO_TYPE); //获取infotype,注:微信开放平台文档中标明固定为:"component_verify_ticket",但参考其他代码,还包含authorized??? log.info(infotype); switch (infotype){ - case "component_verify_ticket": //验证票据 - String ComponentVerifyTicket = result.get("ComponentVerifyTicket"); + case ModuleConstant.TICKET_UNDERLINE_KEY: //验证票据 + String ComponentVerifyTicket = result.get(ModuleConstant.TICKET_KEY); // 缓存 ticket redisThird.setComponentVerifyTicket(ComponentVerifyTicket); // 存数据库 @@ -117,17 +117,17 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe ticketFormDTO.setAppid(PLATFORM_APP_ID); ticketFormDTO.setComponentVerifyTicket(ComponentVerifyTicket); ticketDao.insertComponentVerifyTicket(ticketFormDTO); - log.info("component_verify_ticket:"+ComponentVerifyTicket); + log.info(ModuleConstant.TICKET_UNDERLINE_KEY+":"+ComponentVerifyTicket); break; - case "unauthorized"://用户取消授权 - return ""; + case ModuleConstant.UNAUTHORIZED://用户取消授权 + return ModuleConstant.NULL_CHAR; } } catch (Exception e) { log.error(e.getMessage()); - return ""; + return ModuleConstant.NULL_CHAR; } - log.info(ModuleConstant.END_TICKET); - return "success"; + log.info(ThirdRunTimeInfoConstant.END_TICKET); + return ModuleConstant.SUCCESS; } /** @@ -138,7 +138,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe @Transactional(rollbackFor = Exception.class) @Override public void getComponentAccessToken() { - log.info("====================开始执行定时任务获取令牌【component_access_token】===================="); + log.info(ThirdRunTimeInfoConstant.START_GET_COMPONENT_ACCESS_TOKEN); Map reMap; try { // 核心定时器 @@ -157,17 +157,18 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe formDTO.setComponentAccessToken(componentAccessToken); formDTO.setExpiresIn(Integer.valueOf(expiresIn)); //先逻辑删,在插入 + log.info(ThirdRunTimeInfoConstant.START_DELETE_COMPONENT_ACCESS_TOKEN); componentAccessTokenDao.updateOldComponentAccessToken(); componentAccessTokenDao.insertComponentAccessToken(formDTO); //存缓存 redisThird.setComponentAccessToken(componentAccessToken); } else { - throw new RenException(ModuleConstant.FAILURE_ACCESS_TOKEN); + throw new RenException(ThirdRunTimeInfoConstant.FAILURE_ACCESS_TOKEN); } } catch (Exception e) { e.printStackTrace(); } - log.info(ModuleConstant.SUCCESS_ACCESS_TOKEN); + log.info(ThirdRunTimeInfoConstant.SUCCESS_ACCESS_TOKEN); } /** @@ -178,13 +179,13 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe @Transactional(rollbackFor = Exception.class) @Override public void preAuthCode() { - log.info("====================开始执行定时任务获取预授权码【pre_auth_code】===================="); + log.info(START_GET_PRE_AUTH_CODE); try { String accessToken = redisThird.getComponentAccessToken(ModuleConstant.COMPONENT_ACCESS_TOKEN); JSONObject jsonObject = new JSONObject(); jsonObject.put(ModuleConstant.COMPONENT_APPID, PLATFORM_APP_ID); String post = HttpClientManager.getInstance().sendPostByJSON(ThirdApiConstant.API_CREATE_PREAUTHCODE_URL + accessToken, JSON.toJSONString(jsonObject)).getData(); - log.info("====================返回post结果:" + post); + log.info(String.format(POST_RESULT,post)); HashMap hashMap = JSON.parseObject(post, HashMap.class); String preAuthCode = hashMap.get(ModuleConstant.PRE_AUTH_CODE); String expiresIn = hashMap.get(ModuleConstant.EXPIRES_IN); @@ -200,12 +201,12 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe //预授权码 放入缓存 redisThird.setPreAuthCode(preAuthCode,ex); } else { - throw new RuntimeException("微信开放平台,第三方平台获取【预授权码】失败"); + throw new RuntimeException(FAILURE_GET_PRE_AUTH_CODE); } } catch (Exception e) { e.printStackTrace(); } - log.info("====================结束执行定时任务获取预授权码【pre_auth_code】===================="); + log.info(END_GET_PRE_AUTH_CODE); } /** @@ -214,6 +215,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe */ @Transactional(rollbackFor = Exception.class) public AuthorizationInfoResultDTO authInfoByAuthCode(String authCode,String authAppId,String customerId) { + log.info(START_GET_AUTH_INFO); AuthorizationInfoResultDTO authorizationInfoResultDTO = new AuthorizationInfoResultDTO(); // 获取令牌【component_access_token】 String accessToken = redisThird.getComponentAccessToken(ModuleConstant.COMPONENT_ACCESS_TOKEN); @@ -247,6 +249,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe refreshAuthorizerAccessTokenDao.updateOldAuthorizerAccessToken(customerId); refreshAuthorizerAccessTokenDao.insertAuthorizerAccessToken(refreshAccessToken); // 2. 权限列表 + log.info(START_INSERT_FUNC_INFO); List funcInfos = new ArrayList<>(); List func_info = authorizationInfoResultDTO.getFunc_info(); for (Map map1 : func_info) { @@ -268,6 +271,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe redisThird.setAuthInfo(authorizationInfoResultDTO); //authorizer_refresh_token 放入缓存 redisThird.setAuthorizerRefreshToken(refreshAccessToken); + log.info(END_GET_AUTH_INFO); return authorizationInfoResultDTO; } @@ -323,13 +327,13 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe String userId = tokenDto.getUserId(); String customerId = paCustomerAgencyDao.getCustomerIdByUserId(userId); try { - request.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding(ModuleConstant.UTF8); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } - response.setCharacterEncoding("UTF-8"); - String authCode = request.getParameter("auth_code"); - String expiresIn = request.getParameter("expires_in"); + response.setCharacterEncoding(ModuleConstant.UTF8); + String authCode = request.getParameter(ModuleConstant.AUTH_CODE); + String expiresIn = request.getParameter(ModuleConstant.EXPIRES_IN); //authCode存数据库 AuthCodeFormDTO formDTO = new AuthCodeFormDTO(); formDTO.setAuthCode(authCode); From b3a5bff1e95bd6e75d9654ac1134df8bf27b6716 Mon Sep 17 00:00:00 2001 From: zxc <954985706@qq.com> Date: Fri, 10 Jul 2020 10:21:22 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E7=AC=AC=E4=B8=89?= =?UTF-8?q?=E6=96=B9=E5=B9=B3=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/epmet/controller/AuthRedirectController.java | 2 +- .../com/epmet/controller/ComponentVerifyTicketController.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/AuthRedirectController.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/AuthRedirectController.java index 4e4166f0b0..dd462b2245 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/AuthRedirectController.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/AuthRedirectController.java @@ -17,7 +17,7 @@ import javax.servlet.http.HttpServletResponse; * @CreateTime 2020/7/10 9:04 */ @RestController -@RequestMapping("mpweb") +@RequestMapping("redirectauthcode") public class AuthRedirectController { @Autowired diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/ComponentVerifyTicketController.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/ComponentVerifyTicketController.java index 7a19d3a8e6..4a2a6791f5 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/ComponentVerifyTicketController.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/ComponentVerifyTicketController.java @@ -15,7 +15,7 @@ import javax.servlet.http.HttpServletResponse; */ @Slf4j @RestController -@RequestMapping("thirdplatform") +@RequestMapping("verifyticket") public class ComponentVerifyTicketController { @Autowired From d68f6f0c977c82ad480d278087bf430e05144bda Mon Sep 17 00:00:00 2001 From: zxc <954985706@qq.com> Date: Fri, 10 Jul 2020 11:12:52 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E7=AC=AC=E4=B8=89?= =?UTF-8?q?=E6=96=B9=E5=B9=B3=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/controller/WarrantController.java | 39 ++++++++++++++ .../com/epmet/service/WarrantService.java | 19 +++++++ .../service/impl/WarrantServiceImpl.java | 51 +++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/WarrantController.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/WarrantService.java create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/WarrantServiceImpl.java diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/WarrantController.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/WarrantController.java new file mode 100644 index 0000000000..b28c047c8e --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/WarrantController.java @@ -0,0 +1,39 @@ +package com.epmet.controller; + +import com.epmet.exception.AesException; +import com.epmet.service.WarrantService; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.DocumentHelper; +import org.dom4j.Element; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.BufferedReader; +import java.io.IOException; + +/** + * @Author zxc + * @CreateTime 2020/7/10 10:41 + */ +@Slf4j +@RestController +@RequestMapping("warrant") +public class WarrantController { + + @Autowired + private WarrantService warrantService; + + @RequestMapping(value ="/{AppId}/callback") + public void acceptMessageAndEvent(HttpServletRequest request, @PathVariable("APPID") String appid, + HttpServletResponse response)throws IOException, DocumentException, AesException { + warrantService.acceptMessageAndEvent(request, appid, response); + } + +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/WarrantService.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/WarrantService.java new file mode 100644 index 0000000000..8475322c5b --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/WarrantService.java @@ -0,0 +1,19 @@ +package com.epmet.service; + +import com.epmet.exception.AesException; +import org.dom4j.DocumentException; +import org.springframework.web.bind.annotation.PathVariable; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * @Author zxc + * @CreateTime 2020/7/10 11:03 + */ +public interface WarrantService { + + void acceptMessageAndEvent(HttpServletRequest request,String appid,HttpServletResponse response)throws IOException, DocumentException, AesException; + +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/WarrantServiceImpl.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/WarrantServiceImpl.java new file mode 100644 index 0000000000..1f9306de89 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/WarrantServiceImpl.java @@ -0,0 +1,51 @@ +package com.epmet.service.impl; + +import com.epmet.exception.AesException; +import com.epmet.service.WarrantService; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.DocumentHelper; +import org.dom4j.Element; +import org.springframework.stereotype.Service; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.BufferedReader; +import java.io.IOException; + +/** + * @Author zxc + * @CreateTime 2020/7/10 11:03 + */ +@Slf4j +@Service +public class WarrantServiceImpl implements WarrantService { + @Override + public void acceptMessageAndEvent(HttpServletRequest request, String appid, HttpServletResponse response)throws IOException, DocumentException, AesException { + String msgSignature = request.getParameter("msg_signature"); + log.info("第三方平台全网发布-------------{appid}/callback-----------验证开始。。。。msg_signature=" + msgSignature); + if (!StringUtils.isNotBlank(msgSignature)) { + return;// 微信推送给第三方开放平台的消息一定是加过密的,无消息加密无法解密消息 + } + StringBuilder sb =new StringBuilder(); + BufferedReader in = request.getReader(); + String line; + while ((line = in.readLine()) !=null) { + sb.append(line); + } + in.close(); + + String xml = sb.toString(); + Document doc = DocumentHelper.parseText(xml); + Element rootElt = doc.getRootElement(); + String toUserName = rootElt.elementText("ToUserName"); + + //微信全网测试账号 +// if (StringUtils.equalsIgnoreCase(toUserName, APPID)) { + log.info("全网发布接入检测消息反馈开始---------------APPID=" + appid +"------------------------toUserName=" + toUserName); +// checkWeixinAllNetworkCheck(request, response, xml); +// } + } +}