|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- package tik_tok
-
- import (
- "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/comm"
- zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
- "crypto/hmac"
- "crypto/sha256"
- "encoding/hex"
- "github.com/syyongx/php2go"
- "strings"
- "time"
- )
-
- func Send(appkey, appSecret, method string, params map[string]interface{}, acctoken string) (string, error) {
- methodPath := strings.ReplaceAll(method, ".", "/")
- url := "https://openapi-fxg.jinritemai.com/" + methodPath
- paramJson := comm.GetSortJson(params)
- paramJson = strings.ReplaceAll(paramJson, "\n", "")
- param := map[string]string{
- "app_key": appkey,
- "method": method,
- "param_json": paramJson,
- "timestamp": zhios_third_party_utils.Int64ToStr(time.Now().Unix()),
- "v": "2",
- }
- sign := GetSign(appSecret, param)
- if acctoken != "" {
- param["access_token"] = acctoken
- }
- param["sign"] = sign
- param["sign_method"] = "hmac-sha256"
- for k, v := range param {
- if strings.Contains(url, "?") {
- url += "&" + k + "=" + php2go.URLEncode(v)
- } else {
- url += "?" + k + "=" + php2go.URLEncode(v)
- }
- }
- data, err := zhios_third_party_utils.CurlPost(url, paramJson, nil)
- return string(data), err
- }
- func GetSign(appSecret string, param map[string]string) string {
- str := ""
- keys := comm.KsortToStr(param)
- for _, k := range keys {
- str += k + param[k]
- }
- signStr := appSecret + str + appSecret
- h := hmac.New(sha256.New, []byte(appSecret))
- _, _ = h.Write([]byte(signStr))
- return hex.EncodeToString(h.Sum(nil))
- }
-
- func OpenSend(appkey, appSecret, method string, params map[string]string, acctoken string) (string, error) {
- url := "https://open.douyin.com/" + method + "/"
- param := map[string]string{
- "client_key": appkey,
- "client_secret": appSecret,
- }
- if acctoken != "" {
- param["access_token"] = acctoken
- }
- for k, v := range params {
- param[k] = v
- }
- data, err := zhios_third_party_utils.CurlPost(url, param, nil)
- return string(data), err
- }
- func OpenSendApi(method string, params map[string]interface{}, acctoken string) (string, error) {
- url := "https://open.douyinec.com/" + method
- param := params
- headers := map[string]string{
- "Content-Type": "application/json",
- }
- if acctoken != "" {
- headers["access-token"] = acctoken
- }
- paramStr := zhios_third_party_utils.SerializeStr(param)
- data, err := zhios_third_party_utils.CurlPost(url, paramStr, headers)
- return string(data), err
- }
- func OpenSendApiGet(method string, acctoken string) (string, error) {
- url := "https://open.douyin.com/" + method
- headers := map[string]string{
- "Content-Type": "application/json",
- }
- if acctoken != "" {
- headers["access-token"] = acctoken
- }
- data, err := zhios_third_party_utils.CurlGet(url, headers)
- return string(data), err
- }
|