Files
baseapi/platformapi/tiktok/tiktok.go
richboo111 909cc9ab3f tt
2022-08-19 09:22:22 +08:00

56 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package tiktok
import (
"encoding/json"
"fmt"
"git.rosy.net.cn/baseapi/platformapi"
"git.rosy.net.cn/jx-callback/globals"
"net/http"
"strings"
)
func (a *API) GetAppID() string {
return a.clientKey
}
func (a *API) GetSecret() string {
return a.clientSecret
}
func New(clientSecret, clientKey string, config ...*platformapi.APIConfig) *API {
curConfig := platformapi.DefAPIConfig
if len(config) > 0 {
curConfig = *config[0]
}
return &API{
clientSecret: clientSecret,
clientKey: clientKey,
client: &http.Client{Timeout: curConfig.ClientTimeout},
config: &curConfig,
}
}
func (a *API) AccessAPI2(url string, params map[string]interface{}) (retVal map[string]interface{}, err error) {
data, err := json.Marshal(params)
if err != nil {
return nil, err
}
globals.SugarLogger.Debug("进入AccessAPI2DATA=================", data)
err = platformapi.AccessPlatformAPIWithRetry(a.client,
func() *http.Request {
request, _ := http.NewRequest(http.MethodPost, url, strings.NewReader(string(data)))
request.Header.Set("Content-Type", "application/json")
return request
},
a.config,
func(response *http.Response, bodyStr string, jsonResult1 map[string]interface{}) (errLevel string, err error) {
if jsonResult1 == nil {
return platformapi.ErrLevelRecoverableErr, fmt.Errorf("mapData is nil")
}
retVal = jsonResult1
return platformapi.ErrLevelSuccess, nil
})
globals.SugarLogger.Debug("我也不知道哪里出错返回一下retVal", retVal)
return retVal, err
}