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

82 lines
2.9 KiB

  1. package chanxuanTikTok
  2. import (
  3. zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
  4. "encoding/json"
  5. "fmt"
  6. "github.com/syyongx/php2go"
  7. "github.com/tidwall/gjson"
  8. "strings"
  9. "time"
  10. )
  11. const url = "https://open-api.chanmama.com"
  12. // https://xifld533us.feishu.cn/wiki/wikcnKRYjreG0wr59f1ZrRQ3T7b
  13. func GetGoods(acctoken string, args map[string]string) []ChanxuanTikTokGoods {
  14. send, _ := Send("/jx/v1/partner/product/getGoodsPage", acctoken, args)
  15. var list = make([]ChanxuanTikTokGoods, 0)
  16. str := gjson.Get(send, "data.list").String()
  17. json.Unmarshal([]byte(str), &list)
  18. return list
  19. }
  20. func GetGoodsDetail(acctoken string, args map[string]string) ChanxuanTikTokGoodsDetail {
  21. //goods_id
  22. send, _ := Send("/jx/v1/partner/product/jxGoodsDetails", acctoken, args)
  23. var list ChanxuanTikTokGoodsDetail
  24. str := gjson.Get(send, "data").String()
  25. json.Unmarshal([]byte(str), &list)
  26. return list
  27. }
  28. func GetGoodsUrl(acctoken, userId string, args map[string]string) ChanxuanTikTokGoodsUrl {
  29. //goods_id
  30. args["user_id"] = userId
  31. send, _ := SendPost("/jx/v1/partner/dklive/shareProductLink", acctoken, args)
  32. var list ChanxuanTikTokGoodsUrl
  33. str := gjson.Get(send, "data.data").String()
  34. json.Unmarshal([]byte(str), &list)
  35. return list
  36. }
  37. func GetOrder(acctoken, userId string, args map[string]string) []ChanxuanTikTokOrder {
  38. //goods_id
  39. args["user_id"] = userId
  40. send, _ := Send("/jx/v1/partner/dklive/qryDKOrders", acctoken, args)
  41. var list []ChanxuanTikTokOrder
  42. str := gjson.Get(send, "data.data").String()
  43. json.Unmarshal([]byte(str), &list)
  44. return list
  45. }
  46. func GetToken(appId, secret string) string {
  47. args := map[string]string{
  48. "app_id": appId,
  49. "timestamp": zhios_third_party_utils.Int64ToStr(time.Now().Unix()),
  50. }
  51. str := "app_id=" + appId + "&timestamp=" + args["timestamp"] + "&secret=" + secret
  52. sign := zhios_third_party_utils.Md5(str)
  53. args["sign"] = strings.ToUpper(sign)
  54. post, err := zhios_third_party_utils.CurlPost(url+"/auth/token/get", zhios_third_party_utils.SerializeStr(args), nil)
  55. fmt.Println(string(post))
  56. fmt.Println(err)
  57. //{"code":0,"message":"success","data":{"access_token":"1cd6b495-fa72-e7f8-bcf9-41aa17a49652","expires_in":7200,"expires_in_v2":1729075821}}
  58. return gjson.Get(string(post), "data").String()
  59. }
  60. func Send(router, acctoken string, args map[string]string) (string, error) {
  61. urlStr := url + router + "?access_token=" + acctoken
  62. for k, v := range args {
  63. urlStr += "&" + k + "=" + php2go.URLEncode(v)
  64. }
  65. post, err := zhios_third_party_utils.CurlGet(urlStr, nil)
  66. fmt.Println(urlStr)
  67. fmt.Println(string(post))
  68. fmt.Println(err)
  69. return string(post), err
  70. }
  71. func SendPost(router, acctoken string, args map[string]string) (string, error) {
  72. urlStr := url + router
  73. args["access_token"] = acctoken
  74. post, err := zhios_third_party_utils.CurlPost(urlStr, zhios_third_party_utils.SerializeStr(args), nil)
  75. fmt.Println(string(post))
  76. fmt.Println(err)
  77. return string(post), err
  78. }