第三方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.

55 lines
2.0 KiB

  1. package t3
  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. "encoding/json"
  6. "fmt"
  7. "github.com/syyongx/php2go"
  8. "github.com/tidwall/gjson"
  9. "time"
  10. )
  11. func GetT3Url(key, secret string, param map[string]string) map[string]string {
  12. jsonStr := comm.GetSortJson(param)
  13. send, _ := GetSend("/openapi/marketing/union/v1/generate/link", key, secret, param["sourceId"], jsonStr)
  14. res := map[string]string{
  15. "link": gjson.Get(send, "data.link").String(),
  16. "appId": gjson.Get(send, "data.appId").String(),
  17. "appSource": gjson.Get(send, "data.appSource").String(),
  18. }
  19. return res
  20. }
  21. func GetT3Order(key, secret string, param map[string]string) []T3Order {
  22. jsonStr := comm.GetSortJson(param)
  23. send, _ := GetSend("/openapi/api/v1/marketing/union/activity/order/page", key, secret, param["sourceId"], jsonStr)
  24. list := make([]T3Order, 0)
  25. json.Unmarshal([]byte(gjson.Get(send, "data.data").String()), &list)
  26. return list
  27. }
  28. func GetSend(method, key, secret, sourceId, jsonStr string) (string, error) {
  29. url := "https://exchange.t3go.cn" + method
  30. now := zhios_third_party_utils.Int64ToStr(time.Now().Unix() * 1000)
  31. tmp := map[string]string{
  32. "x-t3-nonce": php2go.Md5(sourceId + now),
  33. "x-t3-timestamp": now,
  34. "x-t3-version": "V1",
  35. "x-t3-key": key,
  36. "x-t3-signature-method": "MD5",
  37. }
  38. signStr := "POST" + method
  39. headers := make(map[string]string)
  40. keyList := []string{"x-t3-key", "x-t3-nonce", "x-t3-signature-method", "x-t3-timestamp", "x-t3-version"}
  41. for _, v := range keyList {
  42. headers[v] = tmp[v]
  43. signStr += v + ":" + tmp[v]
  44. }
  45. signStr += php2go.Md5(jsonStr) + secret
  46. headers["x-t3-signature-headers"] = "x-t3-nonce,x-t3-timestamp,x-t3-version,x-t3-key,x-t3-signature-method"
  47. headers["x-t3-signature"] = php2go.Md5(signStr)
  48. post, err := zhios_third_party_utils.CurlPost(url, jsonStr, headers)
  49. fmt.Println(string(post))
  50. fmt.Println(err)
  51. return string(post), err
  52. }