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
dfe5e88c
Commit
dfe5e88c
authored
Aug 20, 2021
by
罗超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调整部分企业微信接口
parent
8e1c50c7
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
214 additions
and
30 deletions
+214
-30
WeChatReidsCache.cs
Edu.Cache/WeChat/WeChatReidsCache.cs
+48
-0
RB_WeChat_APP.cs
Edu.Model/Entity/WeChat/RB_WeChat_APP.cs
+37
-0
RB_WeChat_APP_ViewModel.cs
Edu.Model/ViewModel/WeChat/RB_WeChat_APP_ViewModel.cs
+15
-0
RB_WeChat_Config_ViewModel.cs
Edu.Model/ViewModel/WeChat/RB_WeChat_Config_ViewModel.cs
+1
-1
RB_AccountRepository.cs
Edu.Repository/User/RB_AccountRepository.cs
+4
-0
RB_WeChat_APPRepository.cs
Edu.Repository/WeChat/RB_WeChat_APPRepository.cs
+31
-0
QYWeiXinHelper.cs
Edu.ThirdCore/QYWinXin/QYWeiXinHelper.cs
+29
-10
QYWeChatController.cs
Edu.WebApi/Controllers/QYWeChat/QYWeChatController.cs
+28
-15
LoginController.cs
Edu.WebApi/Controllers/User/LoginController.cs
+21
-4
No files found.
Edu.Cache/WeChat/WeChatReidsCache.cs
View file @
dfe5e88c
using
Edu.CacheManager.Base
;
using
Edu.Model.CacheModel
;
using
Edu.Model.ViewModel.WeChat
;
using
Edu.Repository.WeChat
;
using
System
;
using
System.Linq
;
...
...
@@ -23,6 +24,8 @@ namespace Edu.Cache.WeChat
/// </summary>
static
readonly
RB_WeChat_ConfigRepository
configRepository
=
new
RB_WeChat_ConfigRepository
();
static
readonly
RB_WeChat_APPRepository
appRepository
=
new
RB_WeChat_APPRepository
();
/// <summary>
...
...
@@ -104,6 +107,19 @@ namespace Edu.Cache.WeChat
}
}
public
static
void
SetAppConfig
(
RB_WeChat_APP_ViewModel
model
,
string
cacheKey
,
int
JwtExpirTime
)
{
try
{
TimeSpan
ts
=
GetExpirTime
(
JwtExpirTime
);
redis
.
StringSet
<
RB_WeChat_APP_ViewModel
>(
cacheKey
,
model
,
ts
);
}
catch
(
Exception
ex
)
{
Common
.
Plugin
.
LogHelper
.
Write
(
ex
,
"SetAppConfig缓存设置失败"
);
}
}
/// <summary>
/// 更新全局配置
/// </summary>
...
...
@@ -136,6 +152,38 @@ namespace Edu.Cache.WeChat
}
}
/// <summary>
/// 获取应用配置信息
/// </summary>
/// <param name="groupId"></param>
/// <param name="code"></param>
/// <returns></returns>
public
static
RB_WeChat_APP_ViewModel
GetAppConfig
(
int
groupId
,
string
code
)
{
RB_WeChat_APP_ViewModel
model
=
null
;
var
cropConfig
=
GetWorkChatConfig
(
groupId
);
string
cacheKey
=
cropConfig
.
WX_CorpId
+
"_"
+
code
;
try
{
model
=
redis
.
StringGet
<
RB_WeChat_APP_ViewModel
>(
cacheKey
);
}
catch
(
Exception
ex
)
{
Common
.
Plugin
.
LogHelper
.
Write
(
ex
,
"GetAppConfig"
);
}
if
(
model
==
null
)
{
model
=
appRepository
.
GetAPPConfigByCodeAndParent
(
cropConfig
.
Id
,
code
);
if
(
model
!=
null
)
{
model
.
CropId
=
cropConfig
.
WX_CorpId
;
SetAppConfig
(
model
,
cacheKey
,
60
*
60
);
}
}
return
model
;
}
/// <summary>
/// 获取配置换成
/// </summary>
...
...
Edu.Model/Entity/WeChat/RB_WeChat_APP.cs
0 → 100644
View file @
dfe5e88c
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
using
VT.FW.DB
;
namespace
Edu.Model.Entity.WeChat
{
[
Serializable
]
[
DB
(
ConnectionName
=
"DefaultConnection"
)]
public
class
RB_WeChat_APP
{
/// <summary>
/// 编号
/// </summary>
public
int
Id
{
get
;
set
;
}
/// <summary>
/// 父级编号
/// </summary>
public
int
ParentId
{
get
;
set
;
}
/// <summary>
/// 应用编号
/// </summary>
public
string
AppId
{
get
;
set
;
}
/// <summary>
/// 密钥
/// </summary>
public
string
Secret
{
get
;
set
;
}
/// <summary>
/// 功能代码
/// </summary>
public
string
Code
{
get
;
set
;
}
}
}
Edu.Model/ViewModel/WeChat/RB_WeChat_APP_ViewModel.cs
0 → 100644
View file @
dfe5e88c
using
Edu.Model.Entity.WeChat
;
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
namespace
Edu.Model.ViewModel.WeChat
{
public
class
RB_WeChat_APP_ViewModel
:
RB_WeChat_APP
{
/// <summary>
/// 企业ID
/// </summary>
public
string
CropId
{
get
;
set
;
}
}
}
Edu.Model/ViewModel/WeChat/RB_WeChat_Config_ViewModel.cs
View file @
dfe5e88c
...
...
@@ -11,6 +11,6 @@ namespace Edu.Model.ViewModel.WeChat
/// </summary>
public
class
RB_WeChat_Config_ViewModel
:
RB_WeChat_Config
{
}
}
Edu.Repository/User/RB_AccountRepository.cs
View file @
dfe5e88c
...
...
@@ -136,6 +136,10 @@ WHERE 1=1
{
where
.
AppendFormat
(
" AND B.{0} <>4 "
,
nameof
(
Employee_ViewModel
.
LeaveStatus
));
}
if
(!
string
.
IsNullOrEmpty
(
query
.
WorkUserId
))
{
where
.
AppendFormat
(
" AND A.{0}='{1}' "
,
nameof
(
RB_Account_ViewModel
.
WorkUserId
),
query
.
WorkUserId
);
}
}
StringBuilder
builder
=
new
StringBuilder
();
...
...
Edu.Repository/WeChat/RB_WeChat_APPRepository.cs
0 → 100644
View file @
dfe5e88c
using
Edu.Model.Entity.WeChat
;
using
Edu.Model.ViewModel.WeChat
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
namespace
Edu.Repository.WeChat
{
/// <summary>
/// 企业微信APP
/// </summary>
public
class
RB_WeChat_APPRepository
:
BaseRepository
<
RB_WeChat_APP
>
{
private
const
string
TABLE_NAME
=
nameof
(
RB_WeChat_APP
);
/// <summary>
/// 获取指定代号的应用
/// </summary>
/// <param name="parentId"></param>
/// <param name="code"></param>
/// <returns></returns>
public
RB_WeChat_APP_ViewModel
GetAPPConfigByCodeAndParent
(
int
parentId
,
string
code
)
{
var
sql
=
$"select Id,ParentId,AppId,Secret,Code from
{
TABLE_NAME
}
where ParentId=
{
parentId
}
and Code='
{
code
}
'"
;
var
result
=
Get
<
RB_WeChat_APP_ViewModel
>(
sql
).
ToList
();
return
result
.
FirstOrDefault
();
}
}
}
Edu.ThirdCore/QYWinXin/QYWeiXinHelper.cs
View file @
dfe5e88c
...
...
@@ -4,6 +4,7 @@ using System.Text;
using
System.Web
;
using
Edu.Cache.User
;
using
Edu.Cache.WeChat
;
using
Edu.Common
;
using
Edu.Common.Plugin
;
using
Newtonsoft.Json
;
using
Newtonsoft.Json.Linq
;
...
...
@@ -40,6 +41,27 @@ namespace Edu.ThirdCore.QYWinXin
}
}
/// <summary>
/// 企业微信应用获取TOKEN
/// </summary>
/// <param name="groupId"></param>
/// <param name="appCode"></param>
/// <param name="newToken"></param>
/// <returns></returns>
public
static
string
GetToken
(
int
groupId
,
string
appCode
,
bool
newToken
=
false
)
{
var
config
=
WeChatReidsCache
.
GetAppConfig
(
groupId
,
appCode
);
if
(
config
!=
null
)
{
var
token
=
AccessTokenContainer
.
GetTokenAsync
(
config
.
CropId
,
config
.
Secret
,
newToken
);
return
token
.
Result
;
}
else
{
return
string
.
Empty
;
}
}
#
endregion
/// <summary>
...
...
@@ -48,9 +70,9 @@ namespace Edu.ThirdCore.QYWinXin
/// <param name="groupId"></param>
/// <param name="code"></param>
/// <returns></returns>
public
(
bool
status
,
GetUserInfoResult
result
)
GetLoginWorkUserInfo
(
int
groupId
,
string
code
)
public
(
bool
status
,
GetUserInfoResult
result
)
GetLoginWorkUserInfo
(
int
groupId
,
string
code
,
string
appCode
)
{
var
token
=
GetToken
(
groupId
);
var
token
=
GetToken
(
groupId
,
appCode
);
if
(!
string
.
IsNullOrEmpty
(
token
))
{
var
result
=
Senparc
.
Weixin
.
Work
.
AdvancedAPIs
.
OAuth2Api
.
GetUserId
(
token
,
code
);
...
...
@@ -70,16 +92,13 @@ namespace Edu.ThirdCore.QYWinXin
/// <returns></returns>
public
string
GetUserAuthorizationCodePath
(
int
groupId
,
string
mark
)
{
var
config
=
WeChatReidsCache
.
Get
WorkChatConfig
(
groupId
);
var
token
=
GetToken
(
groupId
);
if
(!
string
.
IsNullOrEmpty
(
token
))
var
config
=
WeChatReidsCache
.
Get
AppConfig
(
groupId
,
mark
);
var
token
=
GetToken
(
groupId
,
mark
);
if
(!
string
.
IsNullOrEmpty
(
token
)
&&
config
!=
null
)
{
string
redirect_uri
=
$"
http://mobileapis.kookaku.com/api/QYWeChat/UserCodeCallBack
"
;
string
redirect_uri
=
$"
{
Config
.
WorkAPPDomain
}
/login
"
;
string
state
=
mark
;
JObject
cacheContent
=
new
JObject
();
cacheContent
.
Add
(
"group_id"
,
groupId
);
UserReidsCache
.
Set
(
mark
,
cacheContent
,
60
);
return
Senparc
.
Weixin
.
Work
.
AdvancedAPIs
.
OAuth2Api
.
GetCode
(
config
.
WX_CorpId
,
redirect_uri
,
state
,
"1000004"
);
return
Senparc
.
Weixin
.
Work
.
AdvancedAPIs
.
OAuth2Api
.
GetCode
(
config
.
CropId
,
redirect_uri
,
state
,
config
.
AppId
);
}
else
{
...
...
Edu.WebApi/Controllers/QYWeChat/QYWeChatController.cs
View file @
dfe5e88c
...
...
@@ -195,27 +195,40 @@ namespace Edu.WebApi.Controllers.Finance
/// 获取用户Code
/// </summary>
/// <returns></returns>
[
Http
Ge
t
]
[
Http
Pos
t
]
[
AllowAnonymous
]
public
IActionResult
UserCodeCallBack
()
public
ApiResult
Set
UserCodeCallBack
()
{
var
mark
=
Request
.
Query
[
"state"
].
ToString
();
var
code
=
Request
.
Query
[
"code"
].
ToString
();
var
cacheObj
=
UserReidsCache
.
Get
(
mark
);
if
(
cacheObj
!=
null
&&
!
string
.
IsNullOrEmpty
(
code
))
var
referer
=
Request
.
Headers
[
"Origin"
].
ToString
().
Replace
(
"http://"
,
""
);
if
(!
string
.
IsNullOrEmpty
(
referer
))
{
var
cacheContent
=
JObject
.
FromObject
(
cacheObj
);
var
userInfo
=
new
QYWeiXinHelper
().
GetLoginWorkUserInfo
(
cacheContent
.
GetInt
(
"group_id"
),
code
);
if
(
userInfo
.
status
)
var
group
=
groupModule
.
GetGroupEntityModule
(
referer
);
if
(
group
.
GId
!=
0
)
{
var
parm
=
JObject
.
FromObject
(
RequestParm
.
Msg
);
var
appcode
=
parm
.
GetStringValue
(
"appcode"
);
var
code
=
parm
.
GetStringValue
(
"code"
);
var
userInfo
=
new
QYWeiXinHelper
().
GetLoginWorkUserInfo
(
group
.
GId
,
code
,
appcode
);
if
(
userInfo
.
status
)
{
return
ApiResult
.
Success
(
data
:
userInfo
.
result
);
}
else
{
return
ApiResult
.
Failed
(
message
:
"解析用户信息失败"
);
}
}
else
{
cacheContent
.
Add
(
"user"
,
JObject
.
FromObject
(
userInfo
.
result
));
UserReidsCache
.
Set
(
mark
+
"_Finish"
,
cacheContent
,
60
);
return
ApiResult
.
Failed
(
message
:
"未知的集团信息"
);
}
}
var
redirect_url
=
$"
{
Config
.
WorkAPPDomain
}
/login?mark=
{
mark
}
"
;
return
Redirect
(
redirect_url
);
}
else
{
return
ApiResult
.
Failed
(
message
:
"未找到域名来源"
);
}
}
#
endregion
...
...
Edu.WebApi/Controllers/User/LoginController.cs
View file @
dfe5e88c
...
...
@@ -85,9 +85,11 @@ namespace Edu.WebApi.Controllers.User
string
password
=
jobj
.
GetStringValue
(
"Password"
);
int
accountType
=
jobj
.
GetInt
(
"AccountType"
,
1
);
int
autoLoginId
=
jobj
.
GetInt
(
"AutoLoginId"
,
0
);
var
workId
=
jobj
.
GetStringValue
(
"AutoLoginWorkId"
);
var
openId
=
jobj
.
GetStringValue
(
"AutoLoginOpenId"
);
//新增自动登录功能,用于通过推送消息自动登录
RB_Account_ViewModel
model
=
null
;
if
(
autoLoginId
==
0
)
if
(
autoLoginId
==
0
&&
(
string
.
IsNullOrEmpty
(
workId
)
&&
string
.
IsNullOrEmpty
(
openId
))
)
{
model
=
accountModule
.
GetAccountListExtModule
(
new
RB_Account_ViewModel
()
{
...
...
@@ -95,7 +97,7 @@ namespace Edu.WebApi.Controllers.User
//AccountType = (AccountTypeEnum)accountType
})?.
FirstOrDefault
();
}
else
else
if
(
autoLoginId
>
0
&&
(
string
.
IsNullOrEmpty
(
workId
)
&&
string
.
IsNullOrEmpty
(
openId
)))
{
model
=
accountModule
.
GetAccountListExtModule
(
new
RB_Account_ViewModel
()
{
...
...
@@ -103,16 +105,31 @@ namespace Edu.WebApi.Controllers.User
//AccountType = (AccountTypeEnum)accountType
})?.
FirstOrDefault
();
}
else
{
model
=
accountModule
.
GetAccountListExtModule
(
new
RB_Account_ViewModel
()
{
WorkUserId
=
workId
,
OpenId
=
openId
})?.
FirstOrDefault
();
}
if
(
model
==
null
)
{
return
ApiResult
.
Failed
(
message
:
$"登录失败,账号或密码错误!"
);
if
(
string
.
IsNullOrEmpty
(
workId
)
&&
string
.
IsNullOrEmpty
(
openId
))
{
return
ApiResult
.
Failed
(
message
:
$"登录失败,账号或密码错误!"
);
}
else
{
return
ApiResult
.
Failed
(
message
:
$"改账号未绑定ERP账户,请通知行政人员同步你的资料"
);
}
}
else
{
if
(
password
!=
"Viitto!@#123"
)
{
password
=
Common
.
DES
.
Encrypt
(
password
);
if
(
model
.
Password
!=
password
&&
autoLoginId
==
0
)
if
(
model
.
Password
!=
password
&&
autoLoginId
==
0
&&
(
string
.
IsNullOrEmpty
(
workId
)&&
string
.
IsNullOrEmpty
(
openId
))
)
{
return
ApiResult
.
Failed
(
"密码错误"
);
}
...
...
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