Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Education
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄奎
Education
Commits
6e181ba5
Commit
6e181ba5
authored
Aug 16, 2021
by
黄奎
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://gitlab.oytour.com/Kui2/education
parents
ad866076
fb4030f0
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
396 additions
and
8 deletions
+396
-8
CacheKey.cs
Edu.Cache/CacheKey.cs
+5
-0
WeChatReidsCache.cs
Edu.Cache/WeChat/WeChatReidsCache.cs
+111
-0
WorkChatConfig.cs
Edu.Model/CacheModel/WorkChatConfig.cs
+86
-0
RB_Group.cs
Edu.Model/Entity/User/RB_Group.cs
+5
-0
QYWeChatModule.cs
Edu.Module.QYWeChat/QYWeChatModule.cs
+19
-6
GroupModule.cs
Edu.Module.User/GroupModule.cs
+10
-0
RB_GroupRepository.cs
Edu.Repository/User/RB_GroupRepository.cs
+4
-0
Edu.ThirdCore.csproj
Edu.ThirdCore/Edu.ThirdCore.csproj
+1
-0
QYWeiXinConfig.cs
Edu.ThirdCore/QYWinXin/QYWeiXinConfig.cs
+13
-0
QYWeiXinHelper.cs
Edu.ThirdCore/QYWinXin/QYWeiXinHelper.cs
+45
-0
QYWeChatController.cs
Edu.WebApi/Controllers/QYWeChat/QYWeChatController.cs
+81
-0
Startup.cs
Edu.WebApi/Startup.cs
+16
-2
No files found.
Edu.Cache/CacheKey.cs
View file @
6e181ba5
...
...
@@ -58,5 +58,10 @@ namespace Edu.Cache
/// </summary>
public
static
string
QYWeChat_EmpToken_Key
=
"EWeChat_Token_Key_"
;
/// <summary>
/// 企业微信配置文件
/// </summary>
public
static
string
QYWECHAT_GLOBAL_CONFIG_KEY
=
"QYWECHAT_GLOBAL_CONFIG"
;
}
}
Edu.Cache/WeChat/WeChatReidsCache.cs
View file @
6e181ba5
using
Edu.CacheManager.Base
;
using
Edu.Model.CacheModel
;
using
Edu.Repository.WeChat
;
using
System
;
using
System.Linq
;
namespace
Edu.Cache.WeChat
{
...
...
@@ -15,6 +18,13 @@ namespace Edu.Cache.WeChat
static
readonly
RedisHelper
redis
=
new
RedisHelper
(
REDIS_DB3
);
/// <summary>
/// 账号仓储层对象
/// </summary>
static
readonly
RB_WeChat_ConfigRepository
configRepository
=
new
RB_WeChat_ConfigRepository
();
/// <summary>
/// 设置缓存
/// </summary>
...
...
@@ -75,6 +85,107 @@ namespace Edu.Cache.WeChat
}
}
#
region
企业微信全局配置
/// <summary>
/// 设置配置缓存
/// </summary>
/// <param name="model"></param>
public
static
void
SetConfig
(
WorkChatConfig
model
,
int
JwtExpirTime
)
{
try
{
TimeSpan
ts
=
GetExpirTime
(
JwtExpirTime
);
redis
.
StringSet
<
WorkChatConfig
>(
CacheKey
.
QYWECHAT_GLOBAL_CONFIG_KEY
+
"_"
+
model
.
Group_Id
,
model
,
ts
);
}
catch
(
Exception
ex
)
{
Common
.
Plugin
.
LogHelper
.
Write
(
ex
,
"WorkChatConfig缓存设置失败"
);
}
}
/// <summary>
/// 更新全局配置
/// </summary>
/// <param name="id"></param>
public
static
void
UpdateConfig
(
int
id
)
{
var
model
=
configRepository
.
GetEntity
(
id
);
if
(
model
!=
null
)
{
var
chatConfig
=
new
WorkChatConfig
{
Id
=
model
.
Id
,
Group_Id
=
model
.
Group_Id
,
Name
=
model
.
Name
,
WX_CorpId
=
model
.
WX_CorpId
,
Social_Code
=
model
.
Social_Code
,
Employee_Secret
=
model
.
Employee_Secret
,
Contact_Secret
=
model
.
Contact_Secret
,
TelEvent_CallBack
=
model
.
TelEvent_CallBack
,
Token
=
model
.
Token
,
Encoding_Aes_Key
=
model
.
Encoding_Aes_Key
,
EmpEvent_CallBack
=
model
.
EmpEvent_CallBack
,
CreateBy
=
model
.
CreateBy
,
CreateTime
=
model
.
CreateTime
,
UpdateBy
=
model
.
UpdateBy
,
UpdateTime
=
model
.
UpdateTime
};
SetConfig
(
chatConfig
,
Common
.
Config
.
JwtExpirTime
);
}
}
/// <summary>
/// 获取配置换成
/// </summary>
/// <returns></returns>
public
static
WorkChatConfig
GetWorkChatConfig
(
int
groupId
)
{
WorkChatConfig
chatConfig
=
null
;
string
cacheKey
=
CacheKey
.
QYWECHAT_GLOBAL_CONFIG_KEY
+
"_"
+
groupId
;
try
{
chatConfig
=
redis
.
StringGet
<
WorkChatConfig
>(
cacheKey
);
}
catch
(
Exception
ex
)
{
Common
.
Plugin
.
LogHelper
.
Write
(
ex
,
"GeWorkChatConfig"
);
}
if
(
chatConfig
==
null
)
{
var
model
=
configRepository
.
GetList
(
new
Model
.
ViewModel
.
WeChat
.
RB_WeChat_Config_ViewModel
()
{
Group_Id
=
groupId
}).
FirstOrDefault
();
if
(
model
!=
null
)
{
chatConfig
=
new
WorkChatConfig
{
Id
=
model
.
Id
,
Group_Id
=
model
.
Group_Id
,
Name
=
model
.
Name
,
WX_CorpId
=
model
.
WX_CorpId
,
Social_Code
=
model
.
Social_Code
,
Employee_Secret
=
model
.
Employee_Secret
,
Contact_Secret
=
model
.
Contact_Secret
,
TelEvent_CallBack
=
model
.
TelEvent_CallBack
,
Token
=
model
.
Token
,
Encoding_Aes_Key
=
model
.
Encoding_Aes_Key
,
EmpEvent_CallBack
=
model
.
EmpEvent_CallBack
,
CreateBy
=
model
.
CreateBy
,
CreateTime
=
model
.
CreateTime
,
UpdateBy
=
model
.
UpdateBy
,
UpdateTime
=
model
.
UpdateTime
};
SetConfig
(
chatConfig
,
Common
.
Config
.
JwtExpirTime
);
}
}
return
chatConfig
;
}
#
endregion
}
/// <summary>
...
...
Edu.Model/CacheModel/WorkChatConfig.cs
0 → 100644
View file @
6e181ba5
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
namespace
Edu.Model.CacheModel
{
/// <summary>
/// 企业微信配置
/// </summary>
public
class
WorkChatConfig
{
/// <summary>
/// Id
/// </summary>
public
int
Id
{
get
;
set
;
}
/// <summary>
/// 企业名称
/// </summary>
public
string
Name
{
get
;
set
;
}
/// <summary>
/// 企业微信ID
/// </summary>
public
string
WX_CorpId
{
get
;
set
;
}
/// <summary>
/// 企业代码(企业统一社会信用代码)
/// </summary>
public
string
Social_Code
{
get
;
set
;
}
/// <summary>
/// 企业通讯录secret
/// </summary>
public
string
Employee_Secret
{
get
;
set
;
}
/// <summary>
/// 企业外部联系人secret
/// </summary>
public
string
Contact_Secret
{
get
;
set
;
}
/// <summary>
/// 事件回调地址(通讯录)
/// </summary>
public
string
TelEvent_CallBack
{
get
;
set
;
}
/// <summary>
/// 回调token
/// </summary>
public
string
Token
{
get
;
set
;
}
/// <summary>
/// 回调消息加密串
/// </summary>
public
string
Encoding_Aes_Key
{
get
;
set
;
}
/// <summary>
/// 事件回调地址(外部人员)
/// </summary>
public
string
EmpEvent_CallBack
{
get
;
set
;
}
/// <summary>
/// 集团编号
/// </summary>
public
int
Group_Id
{
get
;
set
;
}
/// <summary>
/// 创建人
/// </summary>
public
int
CreateBy
{
get
;
set
;
}
/// <summary>
/// 创建日期
/// </summary>
public
DateTime
CreateTime
{
get
;
set
;
}
/// <summary>
/// 修改人
/// </summary>
public
int
UpdateBy
{
get
;
set
;
}
/// <summary>
/// 更新时间
/// </summary>
public
DateTime
UpdateTime
{
get
;
set
;
}
}
}
Edu.Model/Entity/User/RB_Group.cs
View file @
6e181ba5
...
...
@@ -100,5 +100,10 @@ namespace Edu.Model.Entity.User
/// 官网地址
/// </summary>
public
string
WebSiteDomain
{
get
;
set
;
}
/// <summary>
/// 企业微信应用域名
/// </summary>
public
string
WorkAppDomain
{
get
;
set
;
}
}
}
\ No newline at end of file
Edu.Module.QYWeChat/QYWeChatModule.cs
View file @
6e181ba5
...
...
@@ -32,11 +32,11 @@ namespace Edu.Module.QYWeChat
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public
RB_WeChat_Config_ViewModel
GetWeChatConfigModel
(
RB_WeChat_Config_ViewModel
model
)
public
WorkChatConfig
GetWeChatConfigModel
(
RB_WeChat_Config_ViewModel
model
)
{
var
dmodel
=
weChat_ConfigRepository
.
GetList
(
model
).
FirstOrDefault
();
if
(
dmodel
==
null
)
{
dmodel
=
new
RB_WeChat_Config_ViewModel
();
}
return
dmodel
;
//
var dmodel = weChat_ConfigRepository.GetList(model).FirstOrDefault();
//
if (dmodel == null) { dmodel = new RB_WeChat_Config_ViewModel(); }
return
WeChatReidsCache
.
GetWorkChatConfig
(
model
.
Group_Id
)
;
}
/// <summary>
...
...
@@ -79,11 +79,24 @@ namespace Edu.Module.QYWeChat
OperatorEnum
=
OperatorEnum
.
Equal
}
};
bool
flag
=
weChat_ConfigRepository
.
Update
(
keyValues
,
wheres
);
bool
flag
=
false
;
if
(
weChat_ConfigRepository
.
Update
(
keyValues
,
wheres
))
{
flag
=
true
;
//更新缓存
WeChatReidsCache
.
UpdateConfig
(
demdoel
.
Id
);
}
return
flag
?
""
:
"出错了,请联系管理员"
;
}
else
{
bool
flag
=
weChat_ConfigRepository
.
Insert
(
demdoel
)
>
0
;
var
id
=
weChat_ConfigRepository
.
Insert
(
demdoel
);
bool
flag
=
false
;
if
(
id
>
0
)
{
flag
=
true
;
//更新缓存
WeChatReidsCache
.
UpdateConfig
(
id
);
}
return
flag
?
""
:
"出错了,请联系管理员"
;
}
}
...
...
Edu.Module.User/GroupModule.cs
View file @
6e181ba5
...
...
@@ -66,6 +66,16 @@ namespace Edu.Module.User
return
GetGroupListModule
(
new
RB_Group_ViewModel
()
{
GId
=
GId
})?.
FirstOrDefault
()
??
new
RB_Group_ViewModel
();
}
/// <summary>
/// 获取集团实体类
/// </summary>
/// <param name="GId"></param>
/// <returns></returns>
public
RB_Group_ViewModel
GetGroupEntityModule
(
string
workDomainUrl
)
{
return
GetGroupListModule
(
new
RB_Group_ViewModel
()
{
WorkAppDomain
=
workDomainUrl
})?.
FirstOrDefault
()
??
new
RB_Group_ViewModel
();
}
/// <summary>
/// 新增修改集团
/// </summary>
...
...
Edu.Repository/User/RB_GroupRepository.cs
View file @
6e181ba5
...
...
@@ -58,6 +58,10 @@ WHERE 1=1
{
builder
.
AppendFormat
(
" AND {0}={1} "
,
nameof
(
RB_Group_ViewModel
.
GId
),
query
.
GId
);
}
if
(!
string
.
IsNullOrEmpty
(
query
.
WorkAppDomain
))
{
builder
.
AppendFormat
(
" AND {0}='{1}' "
,
nameof
(
RB_Group_ViewModel
.
WorkAppDomain
),
query
.
WorkAppDomain
);
}
if
(!
string
.
IsNullOrEmpty
(
query
.
WebSiteDomain
))
{
builder
.
AppendFormat
(
" AND {0}='{1}' "
,
nameof
(
RB_Group_ViewModel
.
WebSiteDomain
),
query
.
WebSiteDomain
);
...
...
Edu.ThirdCore/Edu.ThirdCore.csproj
View file @
6e181ba5
...
...
@@ -19,6 +19,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Edu.Cache\Edu.Cache.csproj" />
<ProjectReference Include="..\Edu.Common\Edu.Common.csproj" />
</ItemGroup>
...
...
Edu.ThirdCore/QYWinXin/QYWeiXinConfig.cs
0 → 100644
View file @
6e181ba5
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
namespace
Edu.ThirdCore.QYWinXin
{
/// <summary>
///
/// </summary>
public
class
QYWeiXinConfig
{
}
}
Edu.ThirdCore/QYWinXin/QYWeiXinHelper.cs
View file @
6e181ba5
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
using
Edu.Cache.WeChat
;
using
Newtonsoft.Json
;
using
Newtonsoft.Json.Linq
;
using
Senparc.Weixin.Work
;
using
Senparc.Weixin.Work.AdvancedAPIs
;
using
Senparc.Weixin.Work.AdvancedAPIs.OAuth2
;
using
Senparc.Weixin.Work.Containers
;
namespace
Edu.ThirdCore.QYWinXin
...
...
@@ -14,6 +16,49 @@ namespace Edu.ThirdCore.QYWinXin
/// </summary>
public
class
QYWeiXinHelper
{
#
region
全局静态
private
static
string
WORK_KEY
=
string
.
Empty
;
#
endregion
#
region
令牌
public
static
string
GetToken
(
int
groupId
,
bool
newToken
=
false
)
{
var
config
=
WeChatReidsCache
.
GetWorkChatConfig
(
groupId
);
if
(
config
!=
null
)
{
var
token
=
AccessTokenContainer
.
GetTokenAsync
(
config
.
WX_CorpId
,
config
.
Employee_Secret
,
newToken
);
return
token
.
Result
;
}
else
{
return
string
.
Empty
;
}
}
#
endregion
/// <summary>
/// 解析用户信息
/// </summary>
/// <param name="groupId"></param>
/// <param name="code"></param>
/// <returns></returns>
public
(
bool
status
,
GetUserInfoResult
result
)
GetLoginWorkUserInfo
(
int
groupId
,
string
code
)
{
var
token
=
GetToken
(
groupId
);
if
(!
string
.
IsNullOrEmpty
(
token
))
{
var
result
=
Senparc
.
Weixin
.
Work
.
AdvancedAPIs
.
OAuth2Api
.
GetUserIdAsync
(
token
,
code
);
return
(
true
,
result
.
Result
);
}
else
{
return
(
false
,
null
);
}
}
/// <summary>
/// 获取token
/// </summary>
...
...
Edu.WebApi/Controllers/QYWeChat/QYWeChatController.cs
View file @
6e181ba5
...
...
@@ -8,7 +8,10 @@ using Edu.Common.Enum.Finance;
using
Edu.Common.Plugin
;
using
Edu.Model.ViewModel.WeChat
;
using
Edu.Module.QYWeChat
;
using
Edu.Module.User
;
using
Edu.ThirdCore.QYWinXin
;
using
Edu.WebApi.Filter
;
using
Microsoft.AspNetCore.Authorization
;
using
Microsoft.AspNetCore.Cors
;
using
Microsoft.AspNetCore.Mvc
;
using
Newtonsoft.Json.Linq
;
...
...
@@ -29,6 +32,8 @@ namespace Edu.WebApi.Controllers.Finance
/// </summary>
private
readonly
QYWeChatModule
weChatModule
=
new
QYWeChatModule
();
private
readonly
GroupModule
groupModule
=
new
GroupModule
();
#
region
微信配置
/// <summary>
/// 获取活动配置
...
...
@@ -83,5 +88,81 @@ namespace Edu.WebApi.Controllers.Finance
}
#
endregion
#
region
企业微信客户端
API
/// <summary>
/// 获取企业微信TOKEN
/// </summary>
/// <returns></returns>
[
HttpPost
]
[
AllowAnonymous
]
public
ApiResult
GetWorkToken
()
{
var
referer
=
Request
.
Headers
[
"Origin"
].
ToString
().
Replace
(
"http://"
,
""
);
if
(!
string
.
IsNullOrEmpty
(
referer
))
{
var
group
=
groupModule
.
GetGroupEntityModule
(
referer
);
if
(
group
.
GId
!=
0
)
{
var
query
=
QYWeiXinHelper
.
GetToken
(
group
.
GId
);
if
(!
string
.
IsNullOrEmpty
(
query
))
{
return
ApiResult
.
Success
(
data
:
query
);
}
else
{
return
ApiResult
.
Failed
(
message
:
"解析用户信息失败"
);
}
}
else
{
return
ApiResult
.
Failed
(
message
:
"未知的集团信息"
);
}
}
else
{
return
ApiResult
.
Failed
(
message
:
"未找到域名来源"
);
}
}
[
HttpPost
]
[
AllowAnonymous
]
public
ApiResult
SetUserLogin
()
{
var
referer
=
Request
.
Headers
[
"Origin"
].
ToString
().
Replace
(
"http://"
,
""
);
if
(!
string
.
IsNullOrEmpty
(
referer
))
{
var
group
=
groupModule
.
GetGroupEntityModule
(
referer
);
if
(
group
.
GId
!=
0
)
{
var
query
=
JObject
.
Parse
(
RequestParm
.
Msg
.
ToString
());
var
code
=
query
.
GetStringValue
(
"code"
);
var
userInfo
=
new
QYWeiXinHelper
().
GetLoginWorkUserInfo
(
group
.
GId
,
code
);
if
(
userInfo
.
status
)
{
return
ApiResult
.
Success
(
data
:
userInfo
.
result
);
}
else
{
return
ApiResult
.
Failed
(
message
:
"解析用户信息失败"
);
}
}
else
{
return
ApiResult
.
Failed
(
message
:
"未知的集团信息"
);
}
}
else
{
return
ApiResult
.
Failed
(
message
:
"未找到域名来源"
);
}
}
#
endregion
}
}
Edu.WebApi/Startup.cs
View file @
6e181ba5
...
...
@@ -12,6 +12,8 @@ using Microsoft.Extensions.DependencyInjection;
using
Microsoft.Extensions.Hosting
;
using
Microsoft.Extensions.Options
;
using
Senparc.CO2NET
;
using
Senparc.CO2NET.RegisterServices
;
using
Senparc.Weixin
;
using
Senparc.Weixin.Entities
;
using
Senparc.Weixin.RegisterServices
;
using
Senparc.Weixin.Work
;
...
...
@@ -42,6 +44,7 @@ namespace Edu.WebApi
List
<
string
>
corsArray
=
new
List
<
string
>()
{
"http://192.168.20.214:8400"
,
"http://localhost"
,
"http://localhost:8400"
,
"http://localhost:8081"
,
"http://localhost:8080"
,
...
...
@@ -68,15 +71,23 @@ namespace Edu.WebApi
"https://edu.kookaku.com"
,
"https://eduapi.oytour.com"
,
"http://eduapi.oytour.com"
,
"http://mobile.kookaku.com"
};
services
.
AddCors
(
options
=>
options
.
AddPolicy
(
"AllowCors"
,
policy
=>
policy
.
AllowAnyHeader
().
AllowAnyMethod
().
AllowCredentials
().
WithOrigins
(
corsArray
.
ToArray
())));
services
.
Configure
<
IISServerOptions
>(
options
=>
options
.
AllowSynchronousIO
=
true
);
services
.
AddSingleton
<
IHttpContextAccessor
,
HttpContextAccessor
>();
services
.
AddMemoryCache
();
//使用本地缓存必须添加
services
.
AddSenparcGlobalServices
(
Configuration
)
//Senparc.CO2NET 全局注册
.
AddSenparcWeixinServices
(
Configuration
);
services
.
AddSenparcWeixinServices
(
Configuration
);
//注册全局微信服务
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public
void
Configure
(
IApplicationBuilder
app
,
IWebHostEnvironment
env
,
IHostApplicationLifetime
appLifetime
)
public
void
Configure
(
IApplicationBuilder
app
,
IWebHostEnvironment
env
,
IHostApplicationLifetime
appLifetime
,
IOptions
<
SenparcSetting
>
senparcSetting
,
IOptions
<
SenparcWeixinSetting
>
senparcWeixinSetting
)
{
if
(
env
.
IsDevelopment
())
{
...
...
@@ -120,6 +131,9 @@ namespace Edu.WebApi
Path
.
Combine
(
Directory
.
GetCurrentDirectory
(),
"upfile"
)),
RequestPath
=
"/upfile"
});
IRegisterService
register
=
RegisterService
.
Start
(
senparcSetting
.
Value
).
UseSenparcGlobal
();
register
.
UseSenparcWeixin
(
senparcWeixinSetting
.
Value
,
senparcSetting
.
Value
);
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment