|
- package chanxuanTikTok
-
- import (
- zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
- "encoding/json"
- "fmt"
- "github.com/syyongx/php2go"
- "github.com/tidwall/gjson"
- "strings"
- "time"
- )
-
- const url = "https://open-api.chanmama.com"
-
- // https://xifld533us.feishu.cn/wiki/wikcnKRYjreG0wr59f1ZrRQ3T7b
- func GetGoods(acctoken string, args map[string]string) []ChanxuanTikTokGoods {
- send, _ := Send("/jx/v1/partner/product/getGoodsPage", acctoken, args)
- var list = make([]ChanxuanTikTokGoods, 0)
- str := gjson.Get(send, "data.list").String()
- json.Unmarshal([]byte(str), &list)
- return list
- }
- func GetGoodsDetail(acctoken string, args map[string]string) ChanxuanTikTokGoodsDetail {
- //goods_id
- send, _ := Send("/jx/v1/partner/product/jxGoodsDetails", acctoken, args)
- var list ChanxuanTikTokGoodsDetail
- str := gjson.Get(send, "data").String()
- json.Unmarshal([]byte(str), &list)
- return list
- }
- func GetGoodsUrl(acctoken, userId string, args map[string]string) ChanxuanTikTokGoodsUrl {
- //goods_id
- args["user_id"] = userId
- send, _ := SendPost("/jx/v1/partner/dklive/shareProductLink", acctoken, args)
- var list ChanxuanTikTokGoodsUrl
- str := gjson.Get(send, "data.data").String()
- json.Unmarshal([]byte(str), &list)
- return list
- }
- func GetOrder(acctoken, userId string, args map[string]string) []ChanxuanTikTokOrder {
- //goods_id
- args["user_id"] = userId
- send, _ := Send("/jx/v1/partner/dklive/qryDKOrders", acctoken, args)
- var list []ChanxuanTikTokOrder
- str := gjson.Get(send, "data.data").String()
- json.Unmarshal([]byte(str), &list)
- return list
- }
- func GetToken(appId, secret string) string {
- args := map[string]string{
- "app_id": appId,
- "timestamp": zhios_third_party_utils.Int64ToStr(time.Now().Unix()),
- }
- str := "app_id=" + appId + "×tamp=" + args["timestamp"] + "&secret=" + secret
- sign := zhios_third_party_utils.Md5(str)
- args["sign"] = strings.ToUpper(sign)
- post, err := zhios_third_party_utils.CurlPost(url+"/auth/token/get", zhios_third_party_utils.SerializeStr(args), nil)
- fmt.Println(string(post))
- fmt.Println(err)
- //{"code":0,"message":"success","data":{"access_token":"1cd6b495-fa72-e7f8-bcf9-41aa17a49652","expires_in":7200,"expires_in_v2":1729075821}}
- return gjson.Get(string(post), "data").String()
- }
- func Send(router, acctoken string, args map[string]string) (string, error) {
- urlStr := url + router + "?access_token=" + acctoken
- for k, v := range args {
- urlStr += "&" + k + "=" + php2go.URLEncode(v)
- }
- post, err := zhios_third_party_utils.CurlGet(urlStr, nil)
- fmt.Println(urlStr)
- fmt.Println(string(post))
- fmt.Println(err)
- return string(post), err
- }
- func SendPost(router, acctoken string, args map[string]string) (string, error) {
- urlStr := url + router
- args["access_token"] = acctoken
- post, err := zhios_third_party_utils.CurlPost(urlStr, zhios_third_party_utils.SerializeStr(args), nil)
- fmt.Println(string(post))
- fmt.Println(err)
- return string(post), err
- }
|