更新工具类

master
kanade 3 years ago
parent ce9a53200f
commit 6af295395f

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

Loading…
Cancel
Save