第三方api接口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

api.go 1.5 KiB

1 year ago
1 year ago
1 year ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package tik_tok
  2. import (
  3. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/comm"
  4. zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
  5. "crypto/hmac"
  6. "crypto/sha256"
  7. "encoding/hex"
  8. "github.com/syyongx/php2go"
  9. "strings"
  10. "time"
  11. )
  12. func Send(appkey, appSecret, method string, params map[string]interface{}, acctoken string) (string, error) {
  13. methodPath := strings.ReplaceAll(method, ".", "/")
  14. url := "https://openapi-fxg.jinritemai.com/" + methodPath
  15. paramJson := comm.GetSortJson(params)
  16. paramJson = strings.ReplaceAll(paramJson, "\n", "")
  17. param := map[string]string{
  18. "app_key": appkey,
  19. "method": method,
  20. "param_json": paramJson,
  21. "timestamp": zhios_third_party_utils.Int64ToStr(time.Now().Unix()),
  22. "v": "2",
  23. }
  24. sign := GetSign(appSecret, param)
  25. if acctoken != "" {
  26. param["access_token"] = acctoken
  27. }
  28. param["sign"] = sign
  29. param["sign_method"] = "hmac-sha256"
  30. for k, v := range param {
  31. if strings.Contains(url, "?") {
  32. url += "&" + k + "=" + php2go.URLEncode(v)
  33. } else {
  34. url += "?" + k + "=" + php2go.URLEncode(v)
  35. }
  36. }
  37. data, err := zhios_third_party_utils.CurlPost(url, paramJson, nil)
  38. return string(data), err
  39. }
  40. func GetSign(appSecret string, param map[string]string) string {
  41. str := ""
  42. keys := comm.KsortToStr(param)
  43. for _, k := range keys {
  44. str += k + param[k]
  45. }
  46. signStr := appSecret + str + appSecret
  47. h := hmac.New(sha256.New, []byte(appSecret))
  48. _, _ = h.Write([]byte(signStr))
  49. return hex.EncodeToString(h.Sum(nil))
  50. }