更新工具类

master
kanade 3 years ago
parent ce9a53200f
commit 6af295395f

@ -9,6 +9,7 @@ import (
"fmt" "fmt"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
"strconv"
"time" "time"
) )
@ -22,7 +23,6 @@ type api struct {
} }
type Config struct { type Config struct {
Url string Url string
ChannelId uint
AppKey string AppKey string
AppSecret string AppSecret string
} }
@ -49,19 +49,14 @@ type resp struct {
// @Title 调用接口 // @Title 调用接口
func exec(action string, data interface{}, result interface{}) error { func exec(action string, data interface{}, result interface{}) error {
body := execBody{ requestBody, _ := json.Marshal(&data)
Body: data, now := time.Now().Unix()
Public: public{ sign := HmacSha256(Api.Config.AppSecret, fmt.Sprintf("%d%s", now, requestBody))
ChannelId: Api.Config.ChannelId,
TraceId: uuid.New().String(),
Timestamp: time.Now().Unix(),
},
}
requestBody, _ := json.Marshal(&body)
sign := HmacSha256(Api.Config.AppSecret, fmt.Sprintf("%s%d", requestBody, len(requestBody)))
bytes, err := request(post, Api.Config.Url+action, string(requestBody), map[string]string{ bytes, err := request(post, Api.Config.Url+action, string(requestBody), map[string]string{
"AppKey": Api.Config.AppKey, "AppKey": Api.Config.AppKey,
"Sign": sign, "RequestId": uuid.New().String(),
"TimeStamp": strconv.Itoa(int(now)),
"Sign": sign,
}) })
if err != nil { if err != nil {
return err return err

Loading…
Cancel
Save