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
9212bdf5
Commit
9212bdf5
authored
Oct 31, 2024
by
dliangx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add common test
parent
8b89145e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
83 additions
and
0 deletions
+83
-0
handler/pay_result_test.go
+23
-0
model/http_body.go
+60
-0
No files found.
handler/pay_result_test.go
View file @
9212bdf5
...
@@ -24,3 +24,26 @@ func TestAuthEncrypt(t *testing.T) {
...
@@ -24,3 +24,26 @@ func TestAuthEncrypt(t *testing.T) {
fmt
.
Println
(
string
(
jsonResp
))
fmt
.
Println
(
string
(
jsonResp
))
}
}
func
TestEncrypt
(
t
*
testing
.
T
)
{
var
req
model
.
HttpBody
[
model
.
ReqHead
,
model
.
AuthReq
]
req
.
Head
.
BusinessChannel
=
"spdbmbank"
req
.
Head
.
RequestTime
=
"20550623072501"
req
.
Head
.
VersionId
=
"V1.0"
req
.
Head
.
ChannelId
=
"APP-01"
req
.
Head
.
ServiceSn
=
"00175506230725010158298153"
req
.
Head
.
Sid
=
"00175506230725010158298153"
req
.
Head
.
ServiceId
=
"pfyhcxzfjg"
req
.
Body
.
Addr
=
""
req
.
Body
.
UserName
=
"龙一"
req
.
Body
.
IdNo
=
"420982198604026032"
req
.
Body
.
DuebillNoOrg
=
"1234567890"
req
.
Body
.
LoanAmt
=
"2000000"
req
.
Body
.
Term
=
"12"
req
.
Body
.
CellPhone
=
"1311111111"
req
.
Body
.
Addr
=
"234567890"
req
.
Body
.
JumURL
=
"www.baidu.com"
model
.
Ecas
[
model
.
ReqHead
,
model
.
AuthReq
](
req
)
}
model/http_body.go
View file @
9212bdf5
...
@@ -33,9 +33,29 @@ type HttpBodyResp[T any] struct {
...
@@ -33,9 +33,29 @@ type HttpBodyResp[T any] struct {
Response
T
`json:"body"`
Response
T
`json:"body"`
}
}
type
HttpBody
[
T
any
,
V
any
]
struct
{
Head
T
`json:"head"`
Body
V
`json:"body"`
}
type
CryptReq
[
T
any
]
struct
{
Request
T
`json:"request"`
Signature
string
`json:"signature"`
}
type
CryptResp
[
T
any
]
struct
{
Response
T
`json:"response"`
Signature
string
`json:"signature"`
}
type
ReqHead
struct
{
type
ReqHead
struct
{
RequestTime
string
`json:"requestTime"`
RequestTime
string
`json:"requestTime"`
VersionId
string
`json:"versionId"`
ServiceId
string
`json:"serviceId"`
ServiceSn
string
`json:"serviceSn"`
ServiceSn
string
`json:"serviceSn"`
ChannelId
string
`json:"channelId"`
Sid
string
`json:"sid"`
BusinessChannel
string
`json:"businessChannel"`
}
}
type
RespHead
struct
{
type
RespHead
struct
{
...
@@ -66,6 +86,46 @@ func hexToPrivateKey(hexPrivKey string) (*sm2.PrivateKey, error) {
...
@@ -66,6 +86,46 @@ func hexToPrivateKey(hexPrivKey string) (*sm2.PrivateKey, error) {
return
privateKey
,
nil
return
privateKey
,
nil
}
}
func
Ecas
[
T
any
,
V
any
](
req
HttpBody
[
T
,
V
])
(
cresp
CryptReq
[
HttpBody
[
T
,
string
]],
err
error
)
{
privateKeyBytes
,
_
:=
hexToPrivateKey
(
nltconst
.
TEST_BANK_PRIVTE_KEY
)
// 对应的公钥
privateBankey
,
err
:=
hexToPrivateKey
(
nltconst
.
SM2_PRIVATE_KEY
)
if
err
!=
nil
{
log
.
Println
(
err
)
return
cresp
,
err
}
publicKey
:=
privateBankey
.
PublicKey
body
,
err
:=
json
.
Marshal
(
req
.
Body
)
if
err
!=
nil
{
log
.
Println
(
err
.
Error
())
return
cresp
,
err
}
ciphertext
,
err
:=
sm2
.
Encrypt
(
&
publicKey
,
body
,
rand
.
Reader
,
sm2
.
C1C3C2
)
if
err
!=
nil
{
log
.
Println
(
err
)
return
cresp
,
err
}
cresp
.
Request
.
Head
=
req
.
Head
cresp
.
Request
.
Body
=
hex
.
EncodeToString
(
ciphertext
)
jsonResp
,
err
:=
json
.
Marshal
(
cresp
.
Request
)
if
err
!=
nil
{
log
.
Println
(
err
)
return
cresp
,
err
}
fmt
.
Println
(
string
(
jsonResp
))
signature
,
err
:=
privateKeyBytes
.
Sign
(
rand
.
Reader
,
jsonResp
,
nil
)
cresp
.
Signature
=
hex
.
EncodeToString
(
signature
)
crespjson
,
_
:=
json
.
Marshal
(
cresp
)
fmt
.
Println
(
string
(
crespjson
))
return
cresp
,
err
}
func
EncryptAndSign
[
T
any
](
resp
HttpBodyResp
[
T
])
(
CryptHttpBodyResp
,
error
)
{
func
EncryptAndSign
[
T
any
](
resp
HttpBodyResp
[
T
])
(
CryptHttpBodyResp
,
error
)
{
var
cresp
CryptHttpBodyResp
var
cresp
CryptHttpBodyResp
privateKeyBytes
,
_
:=
hexToPrivateKey
(
nltconst
.
SM2_PRIVATE_KEY
)
privateKeyBytes
,
_
:=
hexToPrivateKey
(
nltconst
.
SM2_PRIVATE_KEY
)
...
...
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