第三方api接口
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

api.go 3.2 KiB

2ヶ月前
2ヶ月前
2ヶ月前
2ヶ月前
2ヶ月前
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 GetGoodsCate(acctoken string, args map[string]string) ChanxuanTikTokGoodsDetail {
  21. //goods_id
  22. send, _ := Send("/jx/v1/partner/product/categoryQry", 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 GetGoodsDetail(acctoken string, args map[string]string) ChanxuanTikTokGoodsDetail {
  29. //goods_id
  30. send, _ := Send("/jx/v1/partner/product/jxGoodsDetails", acctoken, args)
  31. var list ChanxuanTikTokGoodsDetail
  32. str := gjson.Get(send, "data").String()
  33. json.Unmarshal([]byte(str), &list)
  34. return list
  35. }
  36. func GetGoodsUrl(acctoken, userId string, args map[string]string) ChanxuanTikTokGoodsUrl {
  37. //goods_id
  38. args["user_id"] = userId
  39. send, _ := SendPost("/jx/v1/partner/dklive/shareProductLink", acctoken, args)
  40. var list ChanxuanTikTokGoodsUrl
  41. str := gjson.Get(send, "data").String()
  42. json.Unmarshal([]byte(str), &list)
  43. return list
  44. }
  45. func GetOrder(acctoken, userId string, args map[string]string) []ChanxuanTikTokOrder {
  46. //goods_id
  47. args["user_id"] = userId
  48. send, _ := Send("/jx/v1/partner/dklive/qryDKOrders", acctoken, args)
  49. var list []ChanxuanTikTokOrder
  50. str := gjson.Get(send, "data.data").String()
  51. json.Unmarshal([]byte(str), &list)
  52. return list
  53. }
  54. func GetToken(appId, secret string) string {
  55. args := map[string]string{
  56. "app_id": appId,
  57. "timestamp": zhios_third_party_utils.Int64ToStr(time.Now().Unix()),
  58. }
  59. str := "app_id=" + appId + "&timestamp=" + args["timestamp"] + "&secret=" + secret
  60. sign := zhios_third_party_utils.Md5(str)
  61. args["sign"] = strings.ToUpper(sign)
  62. post, err := zhios_third_party_utils.CurlPost(url+"/auth/token/get", zhios_third_party_utils.SerializeStr(args), nil)
  63. fmt.Println(string(post))
  64. fmt.Println(err)
  65. //{"code":0,"message":"success","data":{"access_token":"1cd6b495-fa72-e7f8-bcf9-41aa17a49652","expires_in":7200,"expires_in_v2":1729075821}}
  66. return gjson.Get(string(post), "data").String()
  67. }
  68. func Send(router, acctoken string, args map[string]string) (string, error) {
  69. urlStr := url + router + "?access_token=" + acctoken
  70. for k, v := range args {
  71. urlStr += "&" + k + "=" + php2go.URLEncode(v)
  72. }
  73. post, err := zhios_third_party_utils.CurlGet(urlStr, nil)
  74. fmt.Println(urlStr)
  75. fmt.Println(string(post))
  76. fmt.Println(err)
  77. return string(post), err
  78. }
  79. func SendPost(router, acctoken string, args map[string]string) (string, error) {
  80. urlStr := url + router
  81. args["access_token"] = acctoken
  82. post, err := zhios_third_party_utils.CurlPost(urlStr, zhios_third_party_utils.SerializeStr(args), nil)
  83. fmt.Println(string(post))
  84. fmt.Println(err)
  85. return string(post), err
  86. }