huangjiajun před 1 rokem
rodič
revize
e23f7a6292
3 změnil soubory, kde provedl 173 přidání a 62 odebrání
  1. +14
    -1
      tik_tok/api.go
  2. +159
    -0
      tik_tok/svc_tik_tok_open_api.go
  3. +0
    -61
      tik_tok/svc_tik_tok_open_auth.go

+ 14
- 1
tik_tok/api.go Zobrazit soubor

@@ -52,7 +52,7 @@ func GetSign(appSecret string, param map[string]string) string {
}

func OpenSend(appkey, appSecret, method string, params map[string]string, acctoken string) (string, error) {
url := "https://open.douyin.com/oauth/" + method + "/"
url := "https://open.douyin.com/" + method + "/"
param := map[string]string{
"client_key": appkey,
"client_secret": appSecret,
@@ -66,3 +66,16 @@ func OpenSend(appkey, appSecret, method string, params map[string]string, acctok
data, err := zhios_third_party_utils.CurlPost(url, param, nil)
return string(data), err
}
func OpenSendApi(method string, params map[string]interface{}, acctoken string) (string, error) {
url := "https://open.douyinec.com/" + method
param := params
headers := map[string]string{
"Content-Type": "application/json",
}
if acctoken != "" {
headers["access-token"] = acctoken
}
paramStr := zhios_third_party_utils.SerializeStr(param)
data, err := zhios_third_party_utils.CurlPost(url, paramStr, headers)
return string(data), err
}

+ 159
- 0
tik_tok/svc_tik_tok_open_api.go Zobrazit soubor

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

import (
zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
"fmt"
"github.com/tidwall/gjson"
"time"
)

//第一次授权
func OpenFirstAuth(args map[string]string) map[string]string {
params := map[string]string{"code": args["code"], "grant_type": args["grantType"]}
send, err := OpenSend(args["appkey"], args["appSecret"], "oauth/access_token", params, args["acctoken"])
var data = map[string]string{}
if err != nil {
return data
}
endTime := time.Now().Unix() + gjson.Get(send, "data.expires_in").Int()
refreshEndTime := time.Now().Unix() + gjson.Get(send, "data.refresh_expires_in").Int()
data = map[string]string{
"tik_tok_acc_token": gjson.Get(send, "data.access_token").String(),
"tik_tok_acc_token_time": zhios_third_party_utils.Int64ToStr(endTime),
"tik_tok_acc_refresh_token_time": zhios_third_party_utils.Int64ToStr(refreshEndTime),
"tik_tok_acc_refresh_token": gjson.Get(send, "data.refresh_token").String(),
"tik_tok_open_id": gjson.Get(send, "data.open_id").String(),
"tik_tok_scope": gjson.Get(send, "data.scope").String(),
}
return data
}
func OpenRefreshAccessAuth(args map[string]string) map[string]string {
params := map[string]string{"refresh_token": args["refresh_token"], "grant_type": "refresh_token"}
send, err := OpenSend(args["appkey"], args["appSecret"], "oauth/refresh_token", params, args["acctoken"])
var data = map[string]string{}
if err != nil {
return data
}
endTime := time.Now().Unix() + gjson.Get(send, "data.expires_in").Int()
refreshEndTime := time.Now().Unix() + gjson.Get(send, "data.refresh_expires_in").Int()
data = map[string]string{
"tik_tok_acc_token": gjson.Get(send, "data.access_token").String(),
"tik_tok_acc_token_time": zhios_third_party_utils.Int64ToStr(endTime),
"tik_tok_acc_refresh_token_time": zhios_third_party_utils.Int64ToStr(refreshEndTime),
"tik_tok_acc_refresh_token": gjson.Get(send, "data.refresh_token").String(),
"tik_tok_open_id": gjson.Get(send, "data.open_id").String(),
"tik_tok_scope": gjson.Get(send, "data.scope").String(),
}
return data
}
func OpenRefreshAuth(args map[string]string) map[string]string {
params := map[string]string{"refresh_token": args["refresh_token"]}
send, err := OpenSend(args["appkey"], args["appSecret"], "oauth/renew_refresh_token", params, args["acctoken"])
var data = map[string]string{}
if err != nil {
return data
}
endTime := time.Now().Unix() + gjson.Get(send, "data.expires_in").Int()
data = map[string]string{
"tik_tok_acc_token": gjson.Get(send, "data.refresh_token").String(),
"tik_tok_acc_token_time": zhios_third_party_utils.Int64ToStr(endTime),
}
return data
}

//商品加橱窗
func OpenStoreAdd(args map[string]interface{}) (string, error) {
/**
products []AddStoreProductInfo
商品信息,最多20个商品
need_hide bool false 是否隐藏(true代表隐藏,false代表显示)
pick_extra string fasdfkl 自定义参数,携带到订单(只允许 数字、字母和_,限制长度为20)
keep_picksource bool true 是否保留商品链接原有选品来源,默认不保留(加橱窗时默认会生成新的选品来源参数覆盖旧参数,转链的自定义参数也会失效,此时选品来源为当前加橱窗应用),keep_picksource 为 true 时保留原有选品来源
*/
fmt.Println(args)
params := map[string]interface{}{"products": args["products"], "keep_picksource": args["keep_picksource"], "need_hide": args["need_hide"], "pick_extra": args["pick_extra"]}
send, err := OpenSendApi("alliance/store/add/?open_id="+zhios_third_party_utils.AnyToString(args["open_id"]), params, zhios_third_party_utils.AnyToString(args["acctoken"]))
fmt.Println(send)
fmt.Println(err)
return send, err
}

//达人订单
func OpenKolOrders(args map[string]interface{}) (string, error) {
/**
size int64 是 10 每页订单数目,取值区间: [1, 20]
cursor string 否 3425049063563865812 下一页索引(首次请求时参数不传)
start_time string 否 2006-01-02 15:04:05 支付时间开始,最早支持90天前
end_time string 否 2006-01-02 15:04:05 支付时间结束
time_type string 否 pay 查询时间类型。pay: 支付时间(默认); update:联盟侧更新时间,非订单状态更新时间
order_ids
string 否 4737996432465788974,4737996432465780075 订单号。多个订单号用英文,分隔,最多支持10个订单号
*/
fmt.Println(args)
params := map[string]interface{}{"size": args["size"], "start_time": args["start_time"], "end_time": args["end_time"], "time_type": args["time_type"]}
if args["cursor"] != "" {
params["cursor"] = args["cursor"]
}
send, err := OpenSendApi("alliance/kol/orders/?open_id="+zhios_third_party_utils.AnyToString(args["open_id"]), params, zhios_third_party_utils.AnyToString(args["acctoken"]))
fmt.Println(send)
fmt.Println(err)
return send, err
}

//达人带货口碑分和橱窗销量查询
func OpenKolReputation(args map[string]interface{}) (string, error) {
/**

*/
fmt.Println(args)
params := map[string]interface{}{}
send, err := OpenSendApi("alliance/kol/reputation/?open_id="+zhios_third_party_utils.AnyToString(args["open_id"]), params, zhios_third_party_utils.AnyToString(args["acctoken"]))
fmt.Println(send)
fmt.Println(err)
return send, err
}

//橱窗商品隐藏/显示接口
func OpenStoreHideStatus(args map[string]interface{}) (string, error) {
/**
products []BatchHideEditProductInfo
商品信息,最多20个商品
need_hide bool false 是否隐藏(true代表隐藏,false代表显示)
product_id int64 商品id
promotion_id int64 推广id
*/
fmt.Println(args)
params := map[string]interface{}{"products": args["products"], "need_hide": args["need_hide"]}
send, err := OpenSendApi("alliance/store/hide_status/?open_id="+zhios_third_party_utils.AnyToString(args["open_id"]), params, zhios_third_party_utils.AnyToString(args["acctoken"]))
fmt.Println(send)
fmt.Println(err)
return send, err
}

//达人橱窗商品列表
func OpenKolStoreList(args map[string]interface{}) (string, error) {
/**
page int64 1 分页[1,20]
page_size int64 20 每页的数量(小于等于20)
*/
fmt.Println(args)
params := map[string]interface{}{"page": args["page"], "page_size": args["page_size"]}
send, err := OpenSendApi("alliance/kol/store/list/?open_id="+zhios_third_party_utils.AnyToString(args["open_id"]), params, zhios_third_party_utils.AnyToString(args["acctoken"]))
fmt.Println(send)
fmt.Println(err)
return send, err
}

//达人橱窗商品删除
func OpenKolStoreRemove(args map[string]interface{}) (string, error) {
/**
product_id int64 3450632721376902816 商品ID
promotion_id int64 3450632721374033833 推广ID
*/
fmt.Println(args)
params := map[string]interface{}{"products": args["products"]}
send, err := OpenSendApi("alliance/kol/store/remove/?open_id="+zhios_third_party_utils.AnyToString(args["open_id"]), params, zhios_third_party_utils.AnyToString(args["acctoken"]))
fmt.Println(send)
fmt.Println(err)
return send, err
}

+ 0
- 61
tik_tok/svc_tik_tok_open_auth.go Zobrazit soubor

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

import (
zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
"github.com/tidwall/gjson"
"time"
)

//第一次授权
func OpenFirstAuth(args map[string]string) map[string]string {
params := map[string]string{"code": args["code"], "grant_type": args["grantType"]}
send, err := OpenSend(args["appkey"], args["appSecret"], "access_token", params, args["acctoken"])
var data = map[string]string{}
if err != nil {
return data
}
endTime := time.Now().Unix() + gjson.Get(send, "data.expires_in").Int()
refreshEndTime := time.Now().Unix() + gjson.Get(send, "data.refresh_expires_in").Int()
data = map[string]string{
"tik_tok_acc_token": gjson.Get(send, "data.access_token").String(),
"tik_tok_acc_token_time": zhios_third_party_utils.Int64ToStr(endTime),
"tik_tok_acc_refresh_token_time": zhios_third_party_utils.Int64ToStr(refreshEndTime),
"tik_tok_acc_refresh_token": gjson.Get(send, "data.refresh_token").String(),
"tik_tok_open_id": gjson.Get(send, "data.open_id").String(),
"tik_tok_scope": gjson.Get(send, "data.scope").String(),
}
return data
}
func OpenRefreshAccessAuth(args map[string]string) map[string]string {
params := map[string]string{"refresh_token": args["refresh_token"], "grant_type": "refresh_token"}
send, err := OpenSend(args["appkey"], args["appSecret"], "refresh_token", params, args["acctoken"])
var data = map[string]string{}
if err != nil {
return data
}
endTime := time.Now().Unix() + gjson.Get(send, "data.expires_in").Int()
refreshEndTime := time.Now().Unix() + gjson.Get(send, "data.refresh_expires_in").Int()
data = map[string]string{
"tik_tok_acc_token": gjson.Get(send, "data.access_token").String(),
"tik_tok_acc_token_time": zhios_third_party_utils.Int64ToStr(endTime),
"tik_tok_acc_refresh_token_time": zhios_third_party_utils.Int64ToStr(refreshEndTime),
"tik_tok_acc_refresh_token": gjson.Get(send, "data.refresh_token").String(),
"tik_tok_open_id": gjson.Get(send, "data.open_id").String(),
"tik_tok_scope": gjson.Get(send, "data.scope").String(),
}
return data
}
func OpenRefreshAuth(args map[string]string) map[string]string {
params := map[string]string{"refresh_token": args["refresh_token"]}
send, err := OpenSend(args["appkey"], args["appSecret"], "renew_refresh_token", params, args["acctoken"])
var data = map[string]string{}
if err != nil {
return data
}
endTime := time.Now().Unix() + gjson.Get(send, "data.expires_in").Int()
data = map[string]string{
"tik_tok_acc_token": gjson.Get(send, "data.refresh_token").String(),
"tik_tok_acc_token_time": zhios_third_party_utils.Int64ToStr(endTime),
}
return data
}

Načítá se…
Zrušit
Uložit