Selaa lähdekoodia

抖音本地

master
huangjiajun 4 kuukautta sitten
vanhempi
commit
1d81db16c6
1 muutettua tiedostoa jossa 139 lisäystä ja 0 poistoa
  1. +139
    -0
      tik_tok/csjp_life.go

+ 139
- 0
tik_tok/csjp_life.go Näytä tiedosto

@@ -0,0 +1,139 @@
package tik_tok

import (
"code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/md/csjp"
zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
"encoding/json"
"fmt"
"github.com/tidwall/gjson"
)

//4.2.1 商品列表接口
func GetGoods(args map[string]string) (*[]csjp.CsjpProductList, int64) {
params := map[string]interface{}{
"count": zhios_third_party_utils.StrToInt(args["count"]),
}
if args["sort_by"] != "" {
params["sort_by"] = zhios_third_party_utils.StrToInt(args["sort_by"])
}
if args["cursor"] != "" {
params["cursor"] = zhios_third_party_utils.StrToInt(args["cursor"])
}
if args["order_by"] != "" {
params["order_by"] = zhios_third_party_utils.StrToInt(args["order_by"])
}
if args["city_code"] != "" {
params["city_code"] = args["city_code"]
}
if args["longitude"] != "" {
params["longitude"] = zhios_third_party_utils.StrToFloat64(args["longitude"])
}
if args["latitude"] != "" {
params["latitude"] = zhios_third_party_utils.StrToFloat64(args["latitude"])
}
if args["distance_max"] != "" {
params["distance_max"] = zhios_third_party_utils.StrToInt(args["distance_max"])
}
if args["category_id"] != "" {
params["category_id"] = zhios_third_party_utils.StrToInt(args["category_id"])
}
if args["keyword"] != "" {
params["keyword"] = args["keyword"]
}
send, _ := CsjpSend(args["app_id"], args["app_secret"], "life/product/search", params)
fmt.Println(send)
cursor := gjson.Get(send, "data.cursor").Int()
data := gjson.Get(send, "data.product_list").String()
list := make([]csjp.CsjpProductList, 0)
json.Unmarshal([]byte(data), &list)
return &list, cursor
}

//4.2.2 商品详情接口
func GetGoodsDetail(args map[string]string) *csjp.CsjpProductList {
params := map[string]interface{}{
"product_id_list": []int64{zhios_third_party_utils.StrToInt64(args["gid"])},
}
send, _ := CsjpSend(args["app_id"], args["app_secret"], "life/product/detail", params)
fmt.Println(send)
detail := gjson.Get(send, "data.product_map").String()
detailData := gjson.Get(detail, args["gid"]).String()
if detailData == "" {
return nil
}
var tikTokGoods csjp.CsjpProductList
err := json.Unmarshal([]byte(detailData), &tikTokGoods)
if err != nil {
return nil
}
return &tikTokGoods
}

//4.2.3 商品转链接口
func GetLink(args map[string]string) (map[string]string, error) {
params := map[string]interface{}{
"command": args["command"],
"command_external_info": args["command_external_info"],
}
if args["need_qr_code"] == "1" {
params["need_qr_code"] = true
}
if args["need_share_link"] == "1" {
params["need_share_link"] = true
}
if args["need_zlink"] == "1" {
params["need_zlink"] = true
}
if args["need_share_command"] == "1" {
params["need_share_command"] = true
}
send, err := CsjpSend(args["app_id"], args["app_secret"], "life/product/link", params)
fmt.Println(send)
res := map[string]string{
"dy_share_command": gjson.Get(send, "data.command_share_info.dy_share_command").String(),
"qr_code_url": gjson.Get(send, "data.command_share_info.qr_code_url").String(),
"share_link": gjson.Get(send, "data.command_share_info.share_link").String(),
"dy_deeplink": gjson.Get(send, "data.command_share_info.dy_deeplink").String(),
"dy_zlink": gjson.Get(send, "data.command_share_info.dy_zlink").String(),
}
return res, err
}

//4.2.4 商品转链解析接口
func GetCommand(args map[string]string) (map[string]string, error) {
params := map[string]interface{}{
"command": args["command"],
}
send, err := CsjpSend(args["app_id"], args["app_secret"], "life/command_parse", params)
fmt.Println(send)
res := map[string]string{
"product_id": zhios_third_party_utils.Int64ToStr(gjson.Get(send, "data.command_product_info.product_id").Int()),
}
return res, err
}

//4.3 订单接口
func GetOrder(args map[string]string) (*[]csjp.CsjpOrder, int64) {
params := map[string]interface{}{
"count": zhios_third_party_utils.StrToInt(args["count"]),
}
if args["pay_time_begin"] != "" {
params["pay_time_begin"] = zhios_third_party_utils.StrToInt(args["pay_time_begin"])
}
if args["pay_time_end"] != "" {
params["pay_time_end"] = zhios_third_party_utils.StrToInt(args["pay_time_end"])
}
if args["update_time_begin"] != "" {
params["update_time_begin"] = zhios_third_party_utils.StrToInt(args["update_time_begin"])
}
if args["update_time_end"] != "" {
params["update_time_end"] = zhios_third_party_utils.StrToInt(args["update_time_end"])
}
send, _ := CsjpSend(args["app_id"], args["app_secret"], "life/order/search", params)
fmt.Println(send)
cursor := gjson.Get(send, "data.cursor").Int()
data := gjson.Get(send, "data.order_list").String()
list := make([]csjp.CsjpOrder, 0)
json.Unmarshal([]byte(data), &list)
return &list, cursor
}

Ladataan…
Peruuta
Tallenna