Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nlt-pufa-interface
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
邓梁
nlt-pufa-interface
Commits
9ee05aca
Commit
9ee05aca
authored
Sep 26, 2024
by
dliangx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
加解密报文类型修改
parent
19a65ea4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
12 additions
and
12 deletions
+12
-12
handler/auth.go
+2
-2
handler/pay_result.go
+1
-1
handler/pay_result_test.go
+1
-1
model/http_body.go
+8
-8
No files found.
handler/auth.go
View file @
9ee05aca
...
@@ -14,10 +14,10 @@ import (
...
@@ -14,10 +14,10 @@ import (
func
Auth
(
ctx
context
.
Context
,
c
*
app
.
RequestContext
)
{
func
Auth
(
ctx
context
.
Context
,
c
*
app
.
RequestContext
)
{
var
err
error
var
err
error
var
creq
model
.
CryptHttpBodyReq
[[]
byte
]
var
creq
model
.
CryptHttpBodyReq
var
req
model
.
HttpBodyReq
[
model
.
AuthReq
]
var
req
model
.
HttpBodyReq
[
model
.
AuthReq
]
var
resp
model
.
HttpBodyResp
[
model
.
AuthResp
]
var
resp
model
.
HttpBodyResp
[
model
.
AuthResp
]
err
=
c
.
BindAndValidate
(
&
req
)
err
=
c
.
BindAndValidate
(
&
c
req
)
if
err
!=
nil
{
if
err
!=
nil
{
resp
.
Head
.
Code
=
nltconst
.
PARAM_ERROR
resp
.
Head
.
Code
=
nltconst
.
PARAM_ERROR
resp
.
Head
.
ServiceTime
=
nltconst
.
GetNowTime
()
resp
.
Head
.
ServiceTime
=
nltconst
.
GetNowTime
()
...
...
handler/pay_result.go
View file @
9ee05aca
...
@@ -14,7 +14,7 @@ import (
...
@@ -14,7 +14,7 @@ import (
func
QueryPayResult
(
ctx
context
.
Context
,
c
*
app
.
RequestContext
)
{
func
QueryPayResult
(
ctx
context
.
Context
,
c
*
app
.
RequestContext
)
{
var
err
error
var
err
error
var
creq
model
.
CryptHttpBodyReq
[[]
byte
]
var
creq
model
.
CryptHttpBodyReq
var
req
model
.
HttpBodyReq
[
model
.
PayResultReq
]
var
req
model
.
HttpBodyReq
[
model
.
PayResultReq
]
var
resp
model
.
HttpBodyResp
[
model
.
PayResultResp
]
var
resp
model
.
HttpBodyResp
[
model
.
PayResultResp
]
err
=
c
.
BindAndValidate
(
&
creq
)
err
=
c
.
BindAndValidate
(
&
creq
)
...
...
handler/pay_result_test.go
View file @
9ee05aca
...
@@ -30,7 +30,7 @@ func TestAuthDecrypt(t *testing.T) {
...
@@ -30,7 +30,7 @@ func TestAuthDecrypt(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
err
)
fmt
.
Println
(
err
)
}
}
var
res
model
.
CryptHttpBodyReq
[[]
byte
]
var
res
model
.
CryptHttpBodyReq
res
.
Request
.
Head
.
ServiceSn
=
cresp
.
Response
.
Head
.
ServiceSn
res
.
Request
.
Head
.
ServiceSn
=
cresp
.
Response
.
Head
.
ServiceSn
res
.
Request
.
Request
=
cresp
.
Response
.
Response
res
.
Request
.
Request
=
cresp
.
Response
.
Response
res
.
Signature
=
cresp
.
Signature
res
.
Signature
=
cresp
.
Signature
...
...
model/http_body.go
View file @
9ee05aca
...
@@ -11,13 +11,13 @@ import (
...
@@ -11,13 +11,13 @@ import (
"nlt.com/pf/nltconst"
"nlt.com/pf/nltconst"
)
)
type
CryptHttpBodyReq
[
T
any
]
struct
{
type
CryptHttpBodyReq
struct
{
Request
HttpBodyReq
[
T
]
Request
HttpBodyReq
[
[]
byte
]
Signature
[]
byte
Signature
[]
byte
}
}
type
CryptHttpBodyResp
[
T
any
]
struct
{
type
CryptHttpBodyResp
struct
{
Response
HttpBodyResp
[
T
]
Response
HttpBodyResp
[
[]
byte
]
Signature
[]
byte
Signature
[]
byte
}
}
...
@@ -42,8 +42,8 @@ type RespHead struct {
...
@@ -42,8 +42,8 @@ type RespHead struct {
ServiceSn
string
`json:"serviceSn"`
ServiceSn
string
`json:"serviceSn"`
}
}
func
EncryptAndSign
[
T
any
](
resp
HttpBodyResp
[
T
])
(
CryptHttpBodyResp
[[]
byte
]
,
error
)
{
func
EncryptAndSign
[
T
any
](
resp
HttpBodyResp
[
T
])
(
CryptHttpBodyResp
,
error
)
{
var
cresp
CryptHttpBodyResp
[[]
byte
]
var
cresp
CryptHttpBodyResp
privateKeyBytes
,
_
:=
sm2
.
GenerateKey
(
strings
.
NewReader
(
nltconst
.
SM2_PRIVATE_KEY
))
privateKeyBytes
,
_
:=
sm2
.
GenerateKey
(
strings
.
NewReader
(
nltconst
.
SM2_PRIVATE_KEY
))
// 对应的公钥
// 对应的公钥
...
@@ -80,7 +80,7 @@ func EncryptAndSign[T any](resp HttpBodyResp[T]) (CryptHttpBodyResp[[]byte], err
...
@@ -80,7 +80,7 @@ func EncryptAndSign[T any](resp HttpBodyResp[T]) (CryptHttpBodyResp[[]byte], err
return
cresp
,
err
return
cresp
,
err
}
}
func
VerifyAndDecrypt
[
T
any
](
creq
CryptHttpBodyReq
[[]
byte
]
)
(
HttpBodyReq
[
T
],
error
)
{
func
VerifyAndDecrypt
[
T
any
](
creq
CryptHttpBodyReq
)
(
HttpBodyReq
[
T
],
error
)
{
var
req
HttpBodyReq
[
T
]
var
req
HttpBodyReq
[
T
]
privateKeyBytes
,
_
:=
sm2
.
GenerateKey
(
strings
.
NewReader
(
nltconst
.
SM2_PRIVATE_KEY
))
privateKeyBytes
,
_
:=
sm2
.
GenerateKey
(
strings
.
NewReader
(
nltconst
.
SM2_PRIVATE_KEY
))
signature
:=
creq
.
Signature
signature
:=
creq
.
Signature
...
@@ -91,7 +91,7 @@ func VerifyAndDecrypt[T any](creq CryptHttpBodyReq[[]byte]) (HttpBodyReq[T], err
...
@@ -91,7 +91,7 @@ func VerifyAndDecrypt[T any](creq CryptHttpBodyReq[[]byte]) (HttpBodyReq[T], err
}
}
uid
:=
[]
byte
(
"tk"
)
uid
:=
[]
byte
(
"tk"
)
if
sm2
.
Sm2Verify
(
&
privateKeyBytes
.
PublicKey
,
creq
.
Signature
,
uid
,
r
,
s
)
{
if
sm2
.
Sm2Verify
(
&
privateKeyBytes
.
PublicKey
,
creq
.
Signature
,
uid
,
r
,
s
)
{
tx
,
err
:=
sm2
.
Decrypt
(
privateKeyBytes
,
[]
byte
(
creq
.
Request
.
Request
)
,
sm2
.
C1C2C3
)
tx
,
err
:=
sm2
.
Decrypt
(
privateKeyBytes
,
creq
.
Request
.
Request
,
sm2
.
C1C2C3
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Println
(
err
)
log
.
Println
(
err
)
return
req
,
errors
.
New
(
"解密错误"
)
return
req
,
errors
.
New
(
"解密错误"
)
...
...
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