TestZc_DctWServer

This commit is contained in:
李子铭 2024-11-15 11:00:16 +08:00
parent 0823da7786
commit 990030fff3
2 changed files with 10 additions and 9 deletions

View File

@ -117,8 +117,7 @@ func (c *DctWServer) verify(authorization, path string, body []byte) error {
if !ok { if !ok {
return fmt.Errorf("时间戳获取失败") return fmt.Errorf("时间戳获取失败")
} }
calculatedSign := c.Sign(string(body), path, timestamp) if sign == c.Sign(string(body), path, timestamp) {
if sign == calculatedSign {
return nil return nil
} }
@ -144,8 +143,7 @@ func (c *DctWServer) VerifyDctW(authorization string, body []byte) error {
} }
signStr := fmt.Sprintf("%s%s%s", c.Config.AppId, string(body), c.Config.AppKey) signStr := fmt.Sprintf("%s%s%s", c.Config.AppId, string(body), c.Config.AppKey)
calculatedSign := utils.Md5([]byte(signStr)) if sign == utils.Md5([]byte(signStr)) {
if sign == calculatedSign {
return nil return nil
} }

View File

@ -5,11 +5,14 @@ import (
) )
func TestZc_DctWServer(t *testing.T) { func TestZc_DctWServer(t *testing.T) {
server, err := NewDctWServer(&DctWConfig{ server, err := NewDctWServer(
&DctWConfig{
AppId: "101", AppId: "101",
AppKey: "5k8bJV6axIukpkwz5vdte8QCw5etlC+txi+Nu69nIhOMN4VhmcNgf/THdllpt0jO", AppKey: "5k8bJV6axIukpkwz5vdte8QCw5etlC+txi+Nu69nIhOMN4VhmcNgf/THdllpt0jO",
BaseUri: "http://openapi.1688sup.cn", BaseUri: "http://openapi.1688sup.cn",
}) },
WithDebug(true),
)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }