Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
EduSpider
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
viitto
EduSpider
Commits
b9db4d4f
Commit
b9db4d4f
authored
May 26, 2022
by
liudong1993
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
bcdf81a9
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
16 additions
and
150 deletions
+16
-150
TokenUserInfo.cs
EduSpider.Utility/API/TokenUserInfo.cs
+0
-26
DES.cs
EduSpider.Utility/Encrypt/DES.cs
+0
-80
LoginController.cs
EduSpider.WebApi/Controllers/User/LoginController.cs
+7
-42
Startup.cs
EduSpider.WebApi/Startup.cs
+7
-0
StudentManager.cs
EduSpider/Spiders/ClassInRule/StudentManager.cs
+1
-1
TeacherManager.cs
EduSpider/Spiders/ClassInRule/TeacherManager.cs
+1
-1
No files found.
EduSpider.Utility/API/TokenUserInfo.cs
deleted
100644 → 0
View file @
bcdf81a9
using
EduSpider.Utility.Enum
;
using
System
;
namespace
EduSpider.Utility.API
{
/// <summary>
/// API请求token携带的用户信息
/// </summary>
public
class
TokenUserInfo
{
/// <summary>
/// 用户ID
/// </summary>
public
string
uid
{
get
;
set
;
}
/// <summary>
/// 请求消息
/// </summary>
public
ApiRequestFromEnum
requestFrom
{
get
;
set
;
}
/// <summary>
/// 集团编号
/// </summary>
public
int
groupId
{
get
;
set
;
}
}
}
EduSpider.Utility/Encrypt/DES.cs
deleted
100644 → 0
View file @
bcdf81a9
using
System
;
using
System.IO
;
using
System.Security.Cryptography
;
using
System.Text
;
namespace
EduSpider.Utility
{
/// <summary>
/// DES 加解密
/// </summary>
public
class
DES
{
private
static
readonly
byte
[]
_webapikey
=
{
0xF1
,
0x12
,
0xA3
,
0xD1
,
0xBA
,
0x54
,
0x2A
,
0x88
};
private
static
readonly
byte
[]
_webapiiv
=
{
0x04
,
0xAE
,
0x57
,
0x83
,
0x56
,
0x28
,
0x66
,
0xA7
};
/// <summary>
/// DES加密(单向,只能C#用)
/// </summary>
/// <param name="EncryptString">加密字符串</param>
/// <returns></returns>
public
static
string
Encrypt
(
string
EncryptString
)
{
return
Encrypt
(
EncryptString
,
_webapikey
,
_webapiiv
);
}
/// <summary>
/// DES加密(单向,只能C#用)
/// </summary>
/// <param name="EncryptString">待加密的字符串</param>
/// <param name="Key">加密密钥</param>
/// <param name="IV">初始化加密函数的变量</param>
/// <returns></returns>
private
static
string
Encrypt
(
string
EncryptString
,
byte
[]
Key
,
byte
[]
IV
)
{
byte
[]
inputByteArray
=
Encoding
.
UTF8
.
GetBytes
(
EncryptString
);
DESCryptoServiceProvider
des
=
new
DESCryptoServiceProvider
();
MemoryStream
mStream
=
new
MemoryStream
();
CryptoStream
cStream
=
new
CryptoStream
(
mStream
,
des
.
CreateEncryptor
(
Key
,
IV
),
CryptoStreamMode
.
Write
);
cStream
.
Write
(
inputByteArray
,
0
,
inputByteArray
.
Length
);
cStream
.
FlushFinalBlock
();
return
Convert
.
ToBase64String
(
mStream
.
ToArray
());
}
/// <summary>
/// DES解密
/// </summary>
/// <param name="DecryptString">待解密的字符串</param>
/// <returns>解密成功返回解密后的字符串,失败返源串</returns>
public
static
string
Decrypt
(
string
DecryptString
)
{
return
Decrypt
(
DecryptString
,
_webapikey
,
_webapiiv
);
}
/// <summary>
/// DES解密
/// </summary>
/// <param name="DecryptString">待解密的字符串</param>
/// <param name="Key">解密密钥,要求为8位,和加密密钥相同</param>
/// <param name="IV">初始化加密函数的变量</param>
/// <returns>解密成功返回解密后的字符串,失败返源串</returns>
private
static
string
Decrypt
(
string
DecryptString
,
byte
[]
Key
,
byte
[]
IV
)
{
try
{
byte
[]
inputByteArray
=
Convert
.
FromBase64String
(
DecryptString
);
DESCryptoServiceProvider
des
=
new
DESCryptoServiceProvider
();
MemoryStream
mStream
=
new
MemoryStream
();
CryptoStream
cStream
=
new
CryptoStream
(
mStream
,
des
.
CreateDecryptor
(
Key
,
IV
),
CryptoStreamMode
.
Write
);
cStream
.
Write
(
inputByteArray
,
0
,
inputByteArray
.
Length
);
cStream
.
FlushFinalBlock
();
return
Encoding
.
UTF8
.
GetString
(
mStream
.
ToArray
());
}
catch
{
return
""
;
}
}
}
}
\ No newline at end of file
EduSpider.WebApi/Controllers/User/LoginController.cs
View file @
b9db4d4f
...
@@ -15,7 +15,6 @@ using System;
...
@@ -15,7 +15,6 @@ using System;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
JWT.Algorithms
;
using
JWT.Algorithms
;
using
JWT.Serializers
;
using
JWT.Serializers
;
using
EduSpider.Utility.API
;
namespace
EduSpider.WebApi.Controllers
namespace
EduSpider.WebApi.Controllers
{
{
...
@@ -58,7 +57,7 @@ namespace EduSpider.WebApi.Controllers
...
@@ -58,7 +57,7 @@ namespace EduSpider.WebApi.Controllers
{
{
if
(
password
!=
"Viitto!@#123"
)
if
(
password
!=
"Viitto!@#123"
)
{
{
password
=
DES
.
Encrypt
(
password
);
password
=
DES
Hepler
.
Encrypt
(
password
);
if
(
model
.
Password
!=
password
)
if
(
model
.
Password
!=
password
)
{
{
return
ApiResult
.
Failed
(
"密码错误"
,
new
{
Error
=
0
});
return
ApiResult
.
Failed
(
"密码错误"
,
new
{
Error
=
0
});
...
@@ -76,28 +75,11 @@ namespace EduSpider.WebApi.Controllers
...
@@ -76,28 +75,11 @@ namespace EduSpider.WebApi.Controllers
}
}
#
region
获取进阶思维小程序端
token
#
region
获取进阶思维小程序端
token
TokenUserInfo
UserInfo
=
new
()
{
uid
=
model
.
Id
.
ToString
(),
requestFrom
=
Utility
.
Enum
.
ApiRequestFromEnum
.
MiniProgram
};
BaseUserInfo
UserInfo
=
new
()
{
BaseUserId
=
model
.
Id
};
#
region
JWT
string
token
=
JwtHelper
.
CreateToken
(
UserInfo
,
Config
.
JwtSecretKey
,
Config
.
JwtExpirTime
);
IDateTimeProvider
provider
=
new
UtcDateTimeProvider
();
var
now
=
provider
.
GetNow
().
AddMinutes
(-
1
);
var
unixEpoch
=
new
DateTime
(
1970
,
1
,
1
,
0
,
0
,
0
,
DateTimeKind
.
Utc
);
// or use JwtValidator.UnixEpoch
var
secondsSinceEpoch
=
Math
.
Round
((
now
-
unixEpoch
).
TotalSeconds
);
var
payload
=
new
Dictionary
<
string
,
object
>
{
{
"iat"
,
secondsSinceEpoch
},
{
"exp"
,
secondsSinceEpoch
+
Config
.
JwtExpirTime
},
{
"jjsw_userInfo"
,
UserInfo
}
};
IJwtAlgorithm
algorithm
=
new
HMACSHA256Algorithm
();
IJsonSerializer
serializer
=
new
JsonNetSerializer
();
IBase64UrlEncoder
urlEncoder
=
new
JwtBase64UrlEncoder
();
IJwtEncoder
encoder
=
new
JwtEncoder
(
algorithm
,
serializer
,
urlEncoder
);
string
secret
=
Config
.
JwtSecretKey
;
string
token
=
encoder
.
Encode
(
payload
,
secret
);
#
endregion
#
endregion
#
endregion
Model
.
Cache
.
UserInfo
obj
=
new
Model
.
Cache
.
UserInfo
Model
.
Cache
.
UserInfo
obj
=
new
()
{
{
Id
=
model
.
Id
,
Id
=
model
.
Id
,
AccountType
=
model
.
AccountType
,
AccountType
=
model
.
AccountType
,
...
@@ -161,28 +143,11 @@ namespace EduSpider.WebApi.Controllers
...
@@ -161,28 +143,11 @@ namespace EduSpider.WebApi.Controllers
}
}
#
region
获取进阶思维小程序端
token
#
region
获取进阶思维小程序端
token
TokenUserInfo
UserInfo
=
new
()
{
uid
=
model
.
Id
.
ToString
(),
requestFrom
=
Utility
.
Enum
.
ApiRequestFromEnum
.
MiniProgram
};
BaseUserInfo
UserInfo
=
new
()
{
BaseUserId
=
model
.
Id
};
#
region
JWT
string
token
=
JwtHelper
.
CreateToken
(
UserInfo
,
Config
.
JwtSecretKey
,
Config
.
JwtExpirTime
);
IDateTimeProvider
provider
=
new
UtcDateTimeProvider
();
var
now
=
provider
.
GetNow
().
AddMinutes
(-
1
);
var
unixEpoch
=
new
DateTime
(
1970
,
1
,
1
,
0
,
0
,
0
,
DateTimeKind
.
Utc
);
// or use JwtValidator.UnixEpoch
var
secondsSinceEpoch
=
Math
.
Round
((
now
-
unixEpoch
).
TotalSeconds
);
var
payload
=
new
Dictionary
<
string
,
object
>
{
{
"iat"
,
secondsSinceEpoch
},
{
"exp"
,
secondsSinceEpoch
+
Config
.
JwtExpirTime
},
{
"jjsw_userInfo"
,
UserInfo
}
};
IJwtAlgorithm
algorithm
=
new
HMACSHA256Algorithm
();
IJsonSerializer
serializer
=
new
JsonNetSerializer
();
IBase64UrlEncoder
urlEncoder
=
new
JwtBase64UrlEncoder
();
IJwtEncoder
encoder
=
new
JwtEncoder
(
algorithm
,
serializer
,
urlEncoder
);
string
secret
=
Config
.
JwtSecretKey
;
string
token
=
encoder
.
Encode
(
payload
,
secret
);
#
endregion
#
endregion
#
endregion
Model
.
Cache
.
UserInfo
obj
=
new
Model
.
Cache
.
UserInfo
Model
.
Cache
.
UserInfo
obj
=
new
()
{
{
Id
=
model
.
Id
,
Id
=
model
.
Id
,
AccountType
=
model
.
AccountType
,
AccountType
=
model
.
AccountType
,
...
...
EduSpider.WebApi/Startup.cs
View file @
b9db4d4f
...
@@ -46,6 +46,13 @@ namespace EduSpider.WebApi
...
@@ -46,6 +46,13 @@ namespace EduSpider.WebApi
options
.
Filters
.
Add
<
ApiFilterAttribute
>();
options
.
Filters
.
Add
<
ApiFilterAttribute
>();
});
});
//处理josn格式
services
.
AddMvc
().
AddJsonOptions
(
options
=>
{
options
.
JsonSerializerOptions
.
Encoder
=
System
.
Text
.
Encodings
.
Web
.
JavaScriptEncoder
.
Create
(
System
.
Text
.
Unicode
.
UnicodeRanges
.
All
);
options
.
JsonSerializerOptions
.
PropertyNamingPolicy
=
null
;
});
}
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
...
...
EduSpider/Spiders/ClassInRule/StudentManager.cs
View file @
b9db4d4f
...
@@ -89,7 +89,7 @@ namespace EduSpider.Spiders.ClassInRule
...
@@ -89,7 +89,7 @@ namespace EduSpider.Spiders.ClassInRule
AccountId
=
item
.
StudId
,
AccountId
=
item
.
StudId
,
AccountType
=
Utility
.
Enum
.
AccountTypeEnum
.
Student
,
AccountType
=
Utility
.
Enum
.
AccountTypeEnum
.
Student
,
OpenId
=
""
,
OpenId
=
""
,
Password
=
Utility
.
DES
.
Encrypt
(
item
.
StudentAccount
[^
6.
.]),
Password
=
DESHepler
.
Encrypt
(
item
.
StudentAccount
[^
6.
.]),
Status
=
0
,
Status
=
0
,
UnionId
=
""
UnionId
=
""
});
});
...
...
EduSpider/Spiders/ClassInRule/TeacherManager.cs
View file @
b9db4d4f
...
@@ -88,7 +88,7 @@ namespace EduSpider.Spiders.ClassInRule
...
@@ -88,7 +88,7 @@ namespace EduSpider.Spiders.ClassInRule
AccountId
=
item
.
TeacherId
,
AccountId
=
item
.
TeacherId
,
AccountType
=
AccountTypeEnum
.
Teacher
,
AccountType
=
AccountTypeEnum
.
Teacher
,
OpenId
=
""
,
OpenId
=
""
,
Password
=
Utility
.
DES
.
Encrypt
(
item
.
TeacherAccount
[^
6.
.]),
Password
=
DESHepler
.
Encrypt
(
item
.
TeacherAccount
[^
6.
.]),
Status
=
0
,
Status
=
0
,
UnionId
=
""
UnionId
=
""
});
});
...
...
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