Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mall.oytour.com
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
黄奎
mall.oytour.com
Commits
73d671c3
Commit
73d671c3
authored
Nov 07, 2022
by
黄奎
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
页面修改
parent
844518af
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
38 deletions
+60
-38
MessageController.cs
Mall.WebApi/Controllers/Adapay/MessageController.cs
+60
-38
No files found.
Mall.WebApi/Controllers/Adapay/MessageController.cs
View file @
73d671c3
...
...
@@ -34,63 +34,85 @@ namespace Mall.WebApi.Controllers.Adapay
[
HttpGet
]
public
string
CheckSignature
(
string
echostr
,
string
signature
,
string
timestamp
,
string
nonce
)
{
Tencent
.
WXBizMsgCrypt
wxcpt
=
new
Tencent
.
WXBizMsgCrypt
(
token
,
aes
,
appId
);
string
sVerifyMsgSig
=
signature
;
string
sVerifyTimeStamp
=
timestamp
;
string
sVerifyNonce
=
nonce
;
string
sVerifyEchoStr
=
echostr
;
string
sEchoStr
=
""
;
int
ret
=
wxcpt
.
VerifySignature
(
token
,
sVerifyTimeStamp
,
sVerifyNonce
,
sVerifyEchoStr
,
sVerifyMsgSig
)
;
if
(
ret
!=
0
)
string
query
=
string
.
Format
(
"echostr:{0} signature:{1} timestamp:{2} nonce:{3}"
,
echostr
,
signature
,
timestamp
,
nonce
);
Common
.
Plugin
.
LogHelper
.
Write
(
"CheckSignature_Query:: "
+
query
)
;
string
[]
ArrTmp
=
{
token
,
timestamp
,
nonce
}
;
Array
.
Sort
(
ArrTmp
)
;
string
tmpStr
=
string
.
Join
(
""
,
ArrTmp
)
;
Common
.
Plugin
.
LogHelper
.
Write
(
"CheckSignature_tmpStr:: "
+
tmpStr
);
SHA1
sha
;
string
hash
=
""
;
try
{
Common
.
Plugin
.
LogHelper
.
Write
(
"验证Url失败:"
+
ret
);
Common
.
Plugin
.
LogHelper
.
Write
(
"CheckSignature_hash:: 11"
);
sha
=
new
SHA1CryptoServiceProvider
();
Common
.
Plugin
.
LogHelper
.
Write
(
"CheckSignature_hash:: 22"
);
byte
[]
dataToHash
=
Encoding
.
UTF8
.
GetBytes
(
tmpStr
);
Common
.
Plugin
.
LogHelper
.
Write
(
"CheckSignature_hash:: 33"
);
byte
[]
dataHashed
=
sha
.
ComputeHash
(
dataToHash
);
Common
.
Plugin
.
LogHelper
.
Write
(
"CheckSignature_hash:: 44"
);
hash
=
BitConverter
.
ToString
(
dataHashed
).
Replace
(
"-"
,
""
);
Common
.
Plugin
.
LogHelper
.
Write
(
"CheckSignature_hash:: 55"
);
hash
=
hash
.
ToLower
();
}
return
sEchoStr
;
catch
(
Exception
ex
)
{
Common
.
Plugin
.
LogHelper
.
Write
(
ex
,
"CheckSignature"
);
}
Common
.
Plugin
.
LogHelper
.
Write
(
"CheckSignature_hash:: "
+
hash
);
Common
.
Plugin
.
LogHelper
.
Write
(
"CheckSignature_signature:: "
+
signature
);
if
(
hash
==
signature
)
{
return
echostr
;
}
return
""
;
}
/// <summary>
/// 接
收客服消息
/// 接
口认证
/// </summary>
/// <param name="echostr"></param>
/// <param name="signature"></param>
/// <param name="timestamp"></param>
/// <param name="nonce"></param>
/// <returns></returns>
[
HttpPost
]
public
async
Task
<
HttpResponseMessage
>
wx
()
{
//var content = await Request.Content.ReadAsStringAsync();
HttpResponseMessage
responseMessage
=
new
HttpResponseMessage
();
return
responseMessage
;
}
/// <summary>
/// 验证微信签名
/// </summary>
private
bool
CheckSignatureModule
(
string
token
,
string
signature
,
string
timestamp
,
string
nonce
)
public
string
CheckSignature
(
string
signature
,
string
timestamp
,
string
nonce
)
{
string
query
=
string
.
Format
(
"echostr1:signature:{1} timestamp:{2} nonce:{3}"
,
signature
,
timestamp
,
nonce
);
Common
.
Plugin
.
LogHelper
.
Write
(
"CheckSignature_Query1:: "
+
query
);
string
[]
ArrTmp
=
{
token
,
timestamp
,
nonce
};
Array
.
Sort
(
ArrTmp
);
string
tmpStr
=
string
.
Join
(
""
,
ArrTmp
);
var
data
=
SHA1
.
Create
().
ComputeHash
(
Encoding
.
UTF8
.
GetBytes
(
tmpStr
)
);
Common
.
Plugin
.
LogHelper
.
Write
(
"data:"
+
data
)
;
var
sb
=
new
StringBuilder
()
;
foreach
(
var
t
in
data
)
Common
.
Plugin
.
LogHelper
.
Write
(
"CheckSignature_tmpStr:: "
+
tmpStr
);
SHA1
sha
;
string
hash
=
""
;
try
{
sb
.
Append
(
t
.
ToString
(
"X2"
));
Common
.
Plugin
.
LogHelper
.
Write
(
"CheckSignature_hash:: 11"
);
sha
=
new
SHA1CryptoServiceProvider
();
Common
.
Plugin
.
LogHelper
.
Write
(
"CheckSignature_hash:: 22"
);
byte
[]
dataToHash
=
Encoding
.
UTF8
.
GetBytes
(
tmpStr
);
Common
.
Plugin
.
LogHelper
.
Write
(
"CheckSignature_hash:: 33"
);
byte
[]
dataHashed
=
sha
.
ComputeHash
(
dataToHash
);
Common
.
Plugin
.
LogHelper
.
Write
(
"CheckSignature_hash:: 44"
);
hash
=
BitConverter
.
ToString
(
dataHashed
).
Replace
(
"-"
,
""
);
Common
.
Plugin
.
LogHelper
.
Write
(
"CheckSignature_hash:: 55"
);
hash
=
hash
.
ToLower
();
}
tmpStr
=
sb
.
ToString
();
tmpStr
=
tmpStr
.
ToLower
();
if
(
tmpStr
==
signature
)
catch
(
Exception
ex
)
{
return
true
;
Common
.
Plugin
.
LogHelper
.
Write
(
ex
,
"CheckSignature"
)
;
}
else
Common
.
Plugin
.
LogHelper
.
Write
(
"CheckSignature_hash:: "
+
hash
);
Common
.
Plugin
.
LogHelper
.
Write
(
"CheckSignature_signature:: "
+
signature
);
if
(
hash
==
signature
)
{
return
false
;
return
echostr
;
}
return
""
;
}
}
}
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