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)) }