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
616c8e1e
Commit
616c8e1e
authored
Oct 09, 2021
by
吴春
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
也没修过
parent
4d88c49a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
66 deletions
+46
-66
WeChatHelper.cs
Edu.Common/Plugin/WeChatHelper.cs
+22
-22
AppletLoginController.cs
Edu.WebApi/Controllers/Applet/AppletLoginController.cs
+24
-44
No files found.
Edu.Common/Plugin/WeChatHelper.cs
View file @
616c8e1e
...
@@ -122,34 +122,34 @@ namespace Edu.Common.Plugin
...
@@ -122,34 +122,34 @@ namespace Edu.Common.Plugin
/// 获取微信授权手机号码
/// 获取微信授权手机号码
/// </summary>
/// </summary>
/// <param name="encryptedData"></param>
/// <param name="encryptedData"></param>
/// <param name="
sessionKey
"></param>
/// <param name="
code
"></param>
/// <param name="ivStr"></param>
/// <param name="ivStr"></param>
/// <returns></returns>
/// <returns></returns>
public
static
string
GetWechatMobile
(
string
encryptedData
,
string
sessionKey
,
string
ivStr
)
public
static
result
GetWechatMobile
(
string
encryptedData
,
string
code
,
string
iv
)
{
{
try
string
Appid
=
Common
.
Config
.
JiaXiaoHeAppId
;
var
Secret
=
Common
.
Config
.
JiaXiaoHeAppSecret
;
string
grant_type
=
"authorization_code"
;
//向微信服务端 使用登录凭证 code 获取 session_key 和 openid
string
url
=
"https://api.weixin.qq.com/sns/jscode2session?appid="
+
Appid
+
"&secret="
+
Secret
+
"&js_code="
+
code
+
"&grant_type="
+
grant_type
;
string
type
=
"utf-8"
;
GetUsersHelper
GetUsersHelper
=
new
GetUsersHelper
();
result
res
=
new
Common
.
Plugin
.
result
();
string
j
=
GetUsersHelper
.
GetUrltoHtml
(
url
,
type
);
//获取微信服务器返回字符串
//将字符串转换为json格式
JObject
jo
=
JObject
.
Parse
(
j
);
//微信服务器验证成功
res
.
openid
=
jo
.
GetStringValue
(
"openid"
);
res
.
session_key
=
jo
.
GetStringValue
(
"session_key"
);
if
(!
string
.
IsNullOrWhiteSpace
(
res
.
openid
))
{
{
//16进制数据转换成byte
if
(!
string
.
IsNullOrEmpty
(
encryptedData
)
&&
!
string
.
IsNullOrEmpty
(
iv
))
var
encryptedDataByte
=
Convert
.
FromBase64String
(
encryptedData
);
// strToToHexByte(text);
var
rijndaelCipher
=
new
RijndaelManaged
{
{
Key
=
Convert
.
FromBase64String
(
sessionKey
),
//解析手机号码
IV
=
Convert
.
FromBase64String
(
ivStr
),
res
.
phoneNumber
=
Common
.
EncryptionHelper
.
AES_decrypt
(
encryptedData
,
res
.
session_key
,
iv
);
Mode
=
CipherMode
.
CBC
,
}
Padding
=
PaddingMode
.
PKCS7
};
var
transform
=
rijndaelCipher
.
CreateDecryptor
();
var
plainText
=
transform
.
TransformFinalBlock
(
encryptedDataByte
,
0
,
encryptedDataByte
.
Length
);
var
result
=
Encoding
.
Default
.
GetString
(
plainText
);
return
result
;
}
catch
(
Exception
ex
)
{
return
null
;
}
}
return
res
;
}
}
}
}
...
...
Edu.WebApi/Controllers/Applet/AppletLoginController.cs
View file @
616c8e1e
...
@@ -240,19 +240,19 @@ namespace Edu.WebApi.Controllers.APP
...
@@ -240,19 +240,19 @@ namespace Edu.WebApi.Controllers.APP
}
}
else
else
{
{
//if (!string.IsNullOrEmpty(model.Unio
nId))//UnionId是否为空,为空则绑定手机号与UnionId
if
(!
string
.
IsNullOrEmpty
(
model
.
Ope
nId
))
//UnionId是否为空,为空则绑定手机号与UnionId
//
{
{
// if (UnionId != model.Unio
nId)
if
(
OpenId
!=
model
.
Ope
nId
)
//
{
{
//
return ApiResult.Failed("手机号与绑定的微信账户不一致", new { Error = 0 });
return
ApiResult
.
Failed
(
"手机号与绑定的微信账户不一致"
,
new
{
Error
=
0
});
//
}
}
//
}
}
//
else
else
//
{
{
//
model.UnionId = UnionId;
model
.
UnionId
=
UnionId
;
//
model.OpenId = OpenId;
model
.
OpenId
=
OpenId
;
//
var flag = accountModule.UpdateAccountUnionId(model);
var
flag
=
accountModule
.
UpdateAccountUnionId
(
model
);
//
}
}
if
(
model
.
Status
==
Common
.
Enum
.
DateStateEnum
.
Delete
)
if
(
model
.
Status
==
Common
.
Enum
.
DateStateEnum
.
Delete
)
{
{
return
ApiResult
.
Failed
(
message
:
$"此账号【
{
account
}
】已禁用"
,
new
{
Error
=
2
});
return
ApiResult
.
Failed
(
message
:
$"此账号【
{
account
}
】已禁用"
,
new
{
Error
=
2
});
...
@@ -337,41 +337,21 @@ namespace Edu.WebApi.Controllers.APP
...
@@ -337,41 +337,21 @@ namespace Edu.WebApi.Controllers.APP
string
code
=
parms
.
GetStringValue
(
"code"
);
string
code
=
parms
.
GetStringValue
(
"code"
);
string
encryptedData
=
parms
.
GetStringValue
(
"encryptedData"
);
string
encryptedData
=
parms
.
GetStringValue
(
"encryptedData"
);
string
iv
=
parms
.
GetStringValue
(
"iv"
);
string
iv
=
parms
.
GetStringValue
(
"iv"
);
result
res
=
new
result
();
Common
.
Plugin
.
result
res
=
new
Common
.
Plugin
.
result
();
try
try
{
{
string
Appid
=
Common
.
Config
.
JiaXiaoHeAppId
;
res
=
Common
.
Plugin
.
WeChatHelper
.
GetWechatMobile
(
encryptedData
,
code
,
iv
);
var
Secret
=
Common
.
Config
.
JiaXiaoHeAppSecret
;
string
grant_type
=
"authorization_code"
;
//向微信服务端 使用登录凭证 code 获取 session_key 和 openid
string
url
=
"https://api.weixin.qq.com/sns/jscode2session?appid="
+
Appid
+
"&secret="
+
Secret
+
"&js_code="
+
code
+
"&grant_type="
+
grant_type
;
string
type
=
"utf-8"
;
GetUsersHelper
GetUsersHelper
=
new
GetUsersHelper
();
JObject
jo
=
null
;
string
_telPhone
=
""
;
string
j
=
GetUsersHelper
.
GetUrltoHtml
(
url
,
type
);
//获取微信服务器返回字符串
//将字符串转换为json格式
jo
=
JObject
.
Parse
(
j
);
//微信服务器验证成功
res
.
openid
=
jo
.
GetStringValue
(
"openid"
);
res
.
session_key
=
jo
.
GetStringValue
(
"session_key"
);
if
(!
string
.
IsNullOrWhiteSpace
(
res
.
openid
))
{
if
(!
String
.
IsNullOrEmpty
(
encryptedData
)
&&
!
string
.
IsNullOrEmpty
(
iv
))
{
//解析手机号码
_telPhone
=
Common
.
EncryptionHelper
.
AES_decrypt
(
encryptedData
,
res
.
session_key
,
iv
);
res
.
phoneNumber
=
_telPhone
;
}
}
}
}
catch
(
Exception
ex
)
catch
{
{
Common
.
Plugin
.
LogHelper
.
Write
(
ex
,
string
.
Format
(
"GetGuestWeiXinMobile:msg:{0},request:{1},URL:{2}"
,
Common
.
Plugin
.
JsonHelper
.
Serialize
(
jo
),
RequestParm
.
Msg
.
ToString
(),
url
));
try
return
ApiResult
.
Failed
(
"获取失败"
);
{
res
=
Common
.
Plugin
.
WeChatHelper
.
GetWechatMobile
(
encryptedData
,
code
,
iv
);
}
catch
(
Exception
ex
)
{
Common
.
Plugin
.
LogHelper
.
Write
(
ex
,
"GetGuestWeiXinMobile"
);
}
}
}
return
ApiResult
.
Success
(
""
,
res
);
return
ApiResult
.
Success
(
""
,
res
);
}
}
...
...
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