Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zhichan
Overview
Overview
Details
Activity
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
蒋勇
zhichan
Commits
bf897934
Commit
bf897934
authored
Aug 24, 2020
by
gxfeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fgx--增加md5签名验证
parent
121e2fd8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
2 deletions
+61
-2
tx-fi-tax/app/base/system.js
+61
-2
No files found.
tx-fi-tax/app/base/system.js
View file @
bf897934
...
...
@@ -3,6 +3,7 @@ var objsettings = require("../config/objsettings");
var
settings
=
require
(
"../config/settings"
);
const
request
=
require
(
'request'
);
const
cryptoJS
=
require
(
'crypto-js'
);
const
md5
=
require
(
'MD5'
);
class
System
{
static
declare
(
ns
)
{
...
...
@@ -330,6 +331,46 @@ class System {
return
plaintext
;
}
/**
* 签名认证
* @param {json} vo json对象
* @param {string} secret 签名信息
*/
static
signValid
(
obj
,
secret
)
{
console
.
log
(
"secret:{}"
,
secret
);
// obj json字符串
var
svrSign
;
if
(
obj
==
"{}"
||
!
secret
||
secret
==
'undefined'
)
{
svrSign
=
""
;
}
else
{
// 对传入的json obj进行处理得到toSignStr
let
arr
=
[];
for
(
var
key
in
obj
)
{
arr
.
push
(
key
)
}
arr
.
sort
();
let
str
=
''
;
for
(
var
i
in
arr
)
{
if
(
arr
[
i
]
!=
"sign"
&&
arr
[
i
]
!=
"ip"
&&
(
!
(
Object
.
prototype
.
toString
.
call
(
obj
[
arr
[
i
]])
==
'[object Object]'
||
Object
.
prototype
.
toString
.
call
(
obj
[
arr
[
i
]])
==
'[object Array]'
)
&&
(
obj
[
arr
[
i
]]
&&
obj
[
arr
[
i
]]
!=
'undefined'
)))
{
str
+=
arr
[
i
]
+
"="
+
obj
[
arr
[
i
]]
+
"&"
;
}
}
var
toSignStr
=
str
.
substr
(
0
,
str
.
length
-
1
);
var
sb
=
toSignStr
+
secret
;
console
.
log
(
"cmd=ApiSignUtils:toSign msg=original Sign:"
+
sb
.
toString
()
+
" req param:"
+
obj
);
// 对sb进行md5加密后得到svrSign
svrSign
=
md5
(
sb
);
console
.
log
(
"svrSign===>"
+
svrSign
);
}
if
(
svrSign
.
toLowerCase
()
==
obj
[
"sign"
].
toLowerCase
())
{
console
.
log
(
"cmd=ApiSignUtils:SignValid msg=original Sign:"
+
svrSign
)
return
true
;
}
console
.
error
(
"cmd=ApiSignUtils:SignValid msg=Sign validtate fail! svrSign:"
+
svrSign
+
" reqSign:"
+
obj
[
"sign"
]);
return
false
;
}
}
Date
.
prototype
.
Format
=
function
(
fmt
)
{
//author: meizz
...
...
@@ -415,4 +456,22 @@ module.exports = System;
// }catch(e){
// console.log(e);
// }
// })()
\ No newline at end of file
// })()
(
async
()
=>
{
var
obj
=
{
"postWay"
:
'2'
,
"courier_number"
:
'1805679087555'
,
"companyId"
:
102
,
"customerId"
:
499482
,
"sign"
:
'57acb7037f64d558edf2e844340791e2'
,
"currentPeriod"
:
202001
}
var
secret
=
"2a24a72dc78679bb0796dd3af50a429a"
;
try
{
var
flag
=
await
System
.
signValid
(
obj
,
secret
)
console
.
log
(
flag
);
}
catch
(
e
)
{
console
.
log
(
e
);
}
})()
\ No newline at end of file
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