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
4676ab69
Commit
4676ab69
authored
May 26, 2022
by
黄奎
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://gitlab.oytour.com/viitto/eduspider
parents
169ace6c
8a5750d4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
152 additions
and
0 deletions
+152
-0
LoginController.cs
EduSpider.WebApi/Controllers/User/LoginController.cs
+152
-0
No files found.
EduSpider.WebApi/Controllers/User/LoginController.cs
View file @
4676ab69
...
...
@@ -30,6 +30,7 @@ namespace EduSpider.WebApi.Controllers
[
Autowired
]
public
IAccountService
accountService
{
get
;
set
;
}
#
region
账号密码登录
/// <summary>
/// 账号密码登录
/// </summary>
...
...
@@ -94,7 +95,9 @@ namespace EduSpider.WebApi.Controllers
return
ApiResult
.
Success
(
data
:
obj
);
}
}
#
endregion
#
region
手机号码登录
/// <summary>
/// 根据手机号码一键登录
/// </summary>
...
...
@@ -260,5 +263,154 @@ namespace EduSpider.WebApi.Controllers
return
ApiResult
.
Success
(
data
:
userinfo
);
}
#
endregion
#
endregion
#
region
授权一键登录
/// <summary>
/// 微信授权 获取手机号码 一键登录
/// </summary>
/// <returns></returns>
[
HttpGet
]
[
HttpPost
]
[
AllowAnonymous
]
public
ApiResult
LoginByAuthorize
()
{
JObject
parms
=
JObject
.
Parse
(
RequestParm
.
Msg
.
ToString
());
string
code
=
parms
.
GetString
(
"code"
);
string
encryptedData
=
parms
.
GetString
(
"encryptedData"
);
string
iv
=
parms
.
GetString
(
"iv"
);
//string WeChatName = jobj.GetString("WeChatName");
//string WeChatPhoto = jobj.GetString("WeChatPhoto");
//获取手机号码等信息
var
rmodel
=
GetWeiXinMobileInfo
(
code
,
encryptedData
,
iv
);
string
account
=
rmodel
.
phoneNumber
;
//手机号码
string
OpenId
=
rmodel
.
openid
;
string
UnionId
=
rmodel
.
unionid
;
if
(
string
.
IsNullOrEmpty
(
account
))
{
return
ApiResult
.
Failed
(
message
:
"手机号码登录失败、跳转至账号登录"
,
new
{
Error
=
-
1
});
}
var
model
=
accountService
.
GetAccountList
(
new
RB_Account_Extend
()
{
Account
=
account
.
Trim
()
})?.
FirstOrDefault
();
if
(
model
==
null
)
{
return
ApiResult
.
Failed
(
message
:
"手机号码登录失败、跳转至账号登录"
,
new
{
Error
=
-
1
});
}
else
{
if
(!
string
.
IsNullOrEmpty
(
model
.
OpenId
))
//UnionId是否为空,为空则绑定手机号与UnionId
{
if
(
OpenId
!=
model
.
OpenId
)
{
//return ApiResult.Failed("手机号与绑定的微信账户不一致", new { Error = 0 });
}
}
else
{
model
.
UnionId
=
UnionId
;
model
.
OpenId
=
OpenId
;
accountService
.
UpdateAccountUnionId
(
model
);
}
if
(
model
.
Status
==
Utility
.
Enum
.
DateStateEnum
.
Delete
)
{
return
ApiResult
.
Failed
(
message
:
$"此账号【
{
account
}
】已禁用"
,
new
{
Error
=
2
});
}
#
region
获取进阶思维小程序端
token
BaseUserInfo
UserInfo
=
new
()
{
BaseUserId
=
model
.
Id
};
string
token
=
JwtHelper
.
CreateToken
(
UserInfo
,
Config
.
JwtSecretKey
,
Config
.
JwtExpirTime
);
#
endregion
Model
.
Cache
.
UserInfo
obj
=
new
()
{
Id
=
model
.
Id
,
AccountType
=
model
.
AccountType
,
AccountName
=
model
.
AccountName
,
Token
=
token
,
ApiRequestFromEnum
=
Utility
.
Enum
.
ApiRequestFromEnum
.
MiniProgram
,
AccountId
=
model
.
AccountId
,
UserMobile
=
model
.
Account
,
UserIcon
=
model
.
UserIcon
,
};
Cache
.
User
.
UserReidsCache
.
UserInfoSet
(
Cache
.
CacheKey
.
User_Login_Key
+
model
.
Id
,
obj
,
Config
.
JwtExpirTime
);
return
ApiResult
.
Success
(
data
:
obj
);
}
}
/// <summary>
/// 获取手机号码等信息
/// </summary>
/// <returns></returns>
private
static
result
GetWeiXinMobileInfo
(
string
code
,
string
encryptedData
,
string
iv
)
{
result
res
=
new
()
{
phoneNumber
=
""
,
openid
=
""
};
try
{
res
=
WeChatHelper
.
GetWechatMobile
(
encryptedData
,
code
,
iv
);
}
catch
{
LogHelper
.
WriteError
(
"GetGuestWeiXinMobile:1"
+
JsonHelper
.
Serialize
(
res
));
try
{
res
=
WeChatHelper
.
GetWechatMobile
(
encryptedData
,
code
,
iv
);
}
catch
{
LogHelper
.
WriteError
(
"GetGuestWeiXinMobile:2"
+
JsonHelper
.
Serialize
(
res
));
}
}
if
(
res
.
phoneNumber
==
null
||
string
.
IsNullOrEmpty
(
res
.
phoneNumber
))
{
Thread
.
Sleep
(
10
);
try
{
res
=
WeChatHelper
.
GetWechatMobile
(
encryptedData
,
code
,
iv
);
}
catch
{
LogHelper
.
WriteError
(
"GetGuestWeiXinMobile:3"
+
JsonHelper
.
Serialize
(
res
));
try
{
res
=
WeChatHelper
.
GetWechatMobile
(
encryptedData
,
code
,
iv
);
}
catch
{
LogHelper
.
WriteError
(
"GetGuestWeiXinMobile:4"
+
JsonHelper
.
Serialize
(
res
));
}
}
}
if
(
res
.
phoneNumber
==
null
||
string
.
IsNullOrEmpty
(
res
.
phoneNumber
))
{
Thread
.
Sleep
(
10
);
try
{
res
=
WeChatHelper
.
GetWechatMobile
(
encryptedData
,
code
,
iv
);
}
catch
{
LogHelper
.
WriteError
(
"GetGuestWeiXinMobile:5"
+
JsonHelper
.
Serialize
(
res
));
try
{
res
=
WeChatHelper
.
GetWechatMobile
(
encryptedData
,
code
,
iv
);
}
catch
{
LogHelper
.
WriteError
(
"GetGuestWeiXinMobile:6"
+
JsonHelper
.
Serialize
(
res
));
}
}
}
return
res
;
}
#
endregion
}
}
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