Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
仟微科技
Link Wechat
提交
03c67c4d
Link Wechat
项目概览
仟微科技
/
Link Wechat
通知
48
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Link Wechat
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
03c67c4d
编写于
7月 12, 2021
作者:
孙
孙喜旺
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
多企业token获取修改
上级
c2467c8c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
53 addition
and
70 deletion
+53
-70
linkwe-framework/src/main/java/com/linkwechat/framework/handler/WeMetaObjectHandler.java
...com/linkwechat/framework/handler/WeMetaObjectHandler.java
+4
-4
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWeCorpAccountService.java
...a/com/linkwechat/wecom/service/IWeCorpAccountService.java
+6
-2
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeAccessTokenServiceImpl.java
...nkwechat/wecom/service/impl/WeAccessTokenServiceImpl.java
+39
-64
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeCorpAccountServiceImpl.java
...nkwechat/wecom/service/impl/WeCorpAccountServiceImpl.java
+4
-0
未找到文件。
linkwe-framework/src/main/java/com/linkwechat/framework/handler/WeMetaObjectHandler.java
浏览文件 @
03c67c4d
...
...
@@ -17,10 +17,10 @@ import java.util.Date;
@Slf4j
@Component
public
class
WeMetaObjectHandler
implements
MetaObjectHandler
{
private
static
String
CREATE_TIME
=
"createTime"
;
private
static
String
CREATE_BY
=
"createBy"
;
private
static
String
UPDATE_TIME
=
"updateTime"
;
private
static
String
UPDATE_BY
=
"updateBY"
;
private
static
final
String
CREATE_TIME
=
"createTime"
;
private
static
final
String
CREATE_BY
=
"createBy"
;
private
static
final
String
UPDATE_TIME
=
"updateTime"
;
private
static
final
String
UPDATE_BY
=
"updateBY"
;
@Override
public
void
insertFill
(
MetaObject
metaObject
)
{
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWeCorpAccountService.java
浏览文件 @
03c67c4d
...
...
@@ -49,6 +49,10 @@ public interface IWeCorpAccountService extends IService<WeCorpAccount>
*/
String
getCustomerChurnNoticeSwitch
();
/**
* 根据corpId 获取企业配置信息
* @param corpId
* @return
*/
WeCorpAccount
getWeCorpAccount
(
String
corpId
);
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeAccessTokenServiceImpl.java
浏览文件 @
03c67c4d
...
...
@@ -2,6 +2,7 @@ package com.linkwechat.wecom.service.impl;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.linkwechat.common.config.RuoYiConfig
;
import
com.linkwechat.common.config.WeComeConfig
;
import
com.linkwechat.common.constant.Constants
;
import
com.linkwechat.common.constant.WeConstans
;
import
com.linkwechat.common.core.redis.RedisCache
;
...
...
@@ -14,6 +15,7 @@ import com.linkwechat.common.core.domain.entity.WeCorpAccount;
import
com.linkwechat.wecom.domain.dto.WeAccessTokenDtoDto
;
import
com.linkwechat.wecom.service.IWeAccessTokenService
;
import
com.linkwechat.wecom.service.IWeAppService
;
import
com.linkwechat.wecom.service.IWeComCorpTokenService
;
import
com.linkwechat.wecom.service.IWeCorpAccountService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -26,7 +28,7 @@ import java.util.concurrent.TimeUnit;
* @create: 2020-08-26 14:43
**/
@Service
public
class
WeAccessTokenServiceImpl
implements
IWeAccessTokenService
{
public
class
WeAccessTokenServiceImpl
extends
IWeComCorpTokenService
implements
IWeAccessTokenService
{
@Autowired
...
...
@@ -54,8 +56,6 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService {
*/
@Override
public
String
findCommonAccessToken
()
{
return
findAccessToken
(
WeConstans
.
WE_COMMON_ACCESS_TOKEN
);
}
...
...
@@ -66,8 +66,6 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService {
*/
@Override
public
String
findContactAccessToken
()
{
return
findAccessToken
(
WeConstans
.
WE_CONTACT_ACCESS_TOKEN
);
}
...
...
@@ -100,8 +98,6 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService {
*/
@Override
public
String
findThirdAppAccessToken
(
String
agentId
)
{
String
token
=
redisCache
.
getCacheObject
(
WeConstans
.
WE_THIRD_APP_TOKEN
+
"::"
+
agentId
);
if
(
StringUtils
.
isNotEmpty
(
token
)){
...
...
@@ -117,10 +113,7 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService {
}
private
String
findThirdAppAccessToken
(
WeApp
weApp
){
if
(
weApp
==
null
){
throw
new
WeComException
(
"当前agentId不可用或不存在"
);
}
...
...
@@ -138,15 +131,10 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService {
redisCache
.
setCacheObject
(
WeConstans
.
WE_THIRD_APP_TOKEN
+
"::"
+
weApp
.
getAgentId
(),
weAccessTokenDtoDto
.
getAccess_token
(),
weAccessTokenDtoDto
.
getExpires_in
().
intValue
(),
TimeUnit
.
SECONDS
);
}
return
weAccessTokenDtoDto
.
getAccess_token
();
}
private
String
findAccessToken
(
String
accessTokenKey
){
return
ruoYiConfig
.
isStartTenant
()?
findAccessTokenForTenant
(
accessTokenKey
):
findAccessTokenForNoTenant
(
accessTokenKey
);
...
...
@@ -157,55 +145,7 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService {
//多租户环境下获取token
private
String
findAccessTokenForTenant
(
String
accessTokenKey
){
WeCorpAccount
wxCorpAccount
=
SecurityUtils
.
getLoginUser
().
getUser
().
getWeCorpAccount
();
if
(
null
==
wxCorpAccount
){
//返回错误异常,让用户绑定企业id相关信息
throw
new
WeComException
(
"无可用的corpid和secret"
);
}
String
weAccessToken
=
redisCache
.
getCacheObject
(
accessTokenKey
+
"::"
+
wxCorpAccount
.
getCorpId
());
//为空,请求微信服务器同时缓存到redis中
if
(
StringUtils
.
isEmpty
(
weAccessToken
)){
String
token
=
""
;
Long
expires_in
=
null
;
if
(
WeConstans
.
WE_COMMON_ACCESS_TOKEN
.
equals
(
accessTokenKey
)
||
WeConstans
.
WE_CONTACT_ACCESS_TOKEN
.
equals
(
accessTokenKey
)){
WeAccessTokenDtoDto
weAccessTokenDtoDto
=
accessTokenClient
.
getToken
(
wxCorpAccount
.
getCorpId
(),
WeConstans
.
WE_COMMON_ACCESS_TOKEN
.
equals
(
accessTokenKey
)
?
wxCorpAccount
.
getCorpSecret
()
:
wxCorpAccount
.
getContactSecret
());
token
=
weAccessTokenDtoDto
.
getAccess_token
();
expires_in
=
weAccessTokenDtoDto
.
getExpires_in
();
}
else
if
(
WeConstans
.
WE_PROVIDER_ACCESS_TOKEN
.
equals
(
accessTokenKey
)){
WeAccessTokenDtoDto
providerToken
=
accessTokenClient
.
getProviderToken
(
wxCorpAccount
.
getCorpId
(),
wxCorpAccount
.
getProviderSecret
());
token
=
providerToken
.
getProvider_access_token
();
expires_in
=
providerToken
.
getExpires_in
();
}
else
if
(
WeConstans
.
WE_CHAT_ACCESS_TOKEN
.
equals
(
accessTokenKey
)){
WeAccessTokenDtoDto
weAccessTokenDtoDto
=
accessTokenClient
.
getToken
(
wxCorpAccount
.
getCorpId
(),
wxCorpAccount
.
getChatSecret
());
token
=
weAccessTokenDtoDto
.
getAccess_token
();
expires_in
=
weAccessTokenDtoDto
.
getExpires_in
();
}
else
if
(
WeConstans
.
WE_AGENT_ACCESS_TOKEN
.
equals
(
accessTokenKey
)){
WeAccessTokenDtoDto
weAccessTokenDtoDto
=
accessTokenClient
.
getToken
(
wxCorpAccount
.
getCorpId
(),
wxCorpAccount
.
getAgentSecret
());
token
=
weAccessTokenDtoDto
.
getAccess_token
();
expires_in
=
weAccessTokenDtoDto
.
getExpires_in
();
}
if
(
StringUtils
.
isNotEmpty
(
token
)){
redisCache
.
setCacheObject
(
accessTokenKey
+
"::"
+
wxCorpAccount
.
getCorpId
(),
token
,
expires_in
.
intValue
(),
TimeUnit
.
SECONDS
);
weAccessToken
=
token
;
}
}
return
weAccessToken
;
return
getWeComToken
(
accessTokenKey
);
}
...
...
@@ -272,4 +212,39 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService {
}
@Override
protected
String
getToken
(
String
accessTokenKey
,
WeCorpAccount
wxCorpAccount
)
{
String
weAccessToken
=
redisCache
.
getCacheObject
(
accessTokenKey
+
"::"
+
wxCorpAccount
.
getCorpId
());
//为空,请求微信服务器同时缓存到redis中
if
(
StringUtils
.
isEmpty
(
weAccessToken
)){
String
token
=
""
;
Long
expires_in
=
null
;
if
(
WeConstans
.
WE_COMMON_ACCESS_TOKEN
.
equals
(
accessTokenKey
)
||
WeConstans
.
WE_CONTACT_ACCESS_TOKEN
.
equals
(
accessTokenKey
)){
WeAccessTokenDtoDto
weAccessTokenDtoDto
=
accessTokenClient
.
getToken
(
wxCorpAccount
.
getCorpId
(),
WeConstans
.
WE_COMMON_ACCESS_TOKEN
.
equals
(
accessTokenKey
)
?
wxCorpAccount
.
getCorpSecret
()
:
wxCorpAccount
.
getContactSecret
());
token
=
weAccessTokenDtoDto
.
getAccess_token
();
expires_in
=
weAccessTokenDtoDto
.
getExpires_in
();
}
else
if
(
WeConstans
.
WE_PROVIDER_ACCESS_TOKEN
.
equals
(
accessTokenKey
)){
WeAccessTokenDtoDto
providerToken
=
accessTokenClient
.
getProviderToken
(
wxCorpAccount
.
getCorpId
(),
wxCorpAccount
.
getProviderSecret
());
token
=
providerToken
.
getProvider_access_token
();
expires_in
=
providerToken
.
getExpires_in
();
}
else
if
(
WeConstans
.
WE_CHAT_ACCESS_TOKEN
.
equals
(
accessTokenKey
)){
WeAccessTokenDtoDto
weAccessTokenDtoDto
=
accessTokenClient
.
getToken
(
wxCorpAccount
.
getCorpId
(),
wxCorpAccount
.
getChatSecret
());
token
=
weAccessTokenDtoDto
.
getAccess_token
();
expires_in
=
weAccessTokenDtoDto
.
getExpires_in
();
}
else
if
(
WeConstans
.
WE_AGENT_ACCESS_TOKEN
.
equals
(
accessTokenKey
)){
WeAccessTokenDtoDto
weAccessTokenDtoDto
=
accessTokenClient
.
getToken
(
wxCorpAccount
.
getCorpId
(),
wxCorpAccount
.
getAgentSecret
());
token
=
weAccessTokenDtoDto
.
getAccess_token
();
expires_in
=
weAccessTokenDtoDto
.
getExpires_in
();
}
if
(
StringUtils
.
isNotEmpty
(
token
)){
redisCache
.
setCacheObject
(
accessTokenKey
+
"::"
+
wxCorpAccount
.
getCorpId
(),
token
,
expires_in
.
intValue
(),
TimeUnit
.
SECONDS
);
weAccessToken
=
token
;
}
}
return
weAccessToken
;
}
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeCorpAccountServiceImpl.java
浏览文件 @
03c67c4d
...
...
@@ -102,6 +102,10 @@ public class WeCorpAccountServiceImpl extends ServiceImpl<WeCorpAccountMapper,We
return
noticeSwitch
;
}
@Override
public
WeCorpAccount
getWeCorpAccount
(
String
corpId
)
{
return
this
.
getOne
(
new
LambdaQueryWrapper
<
WeCorpAccount
>().
eq
(
WeCorpAccount:
:
getCorpId
,
corpId
));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录