Bladeren bron

更新

master
huangjiajun 1 jaar geleden
bovenliggende
commit
04a6eec0da
4 gewijzigde bestanden met toevoegingen van 87 en 14 verwijderingen
  1. +16
    -0
      tik_tok/api.go
  2. +5
    -7
      tik_tok/svc_tik_tok_auth.go
  3. +61
    -0
      tik_tok/svc_tik_tok_open_auth.go
  4. +5
    -7
      tik_tok/tik_tok_test.go

+ 16
- 0
tik_tok/api.go Bestand weergeven

@@ -50,3 +50,19 @@ func GetSign(appSecret string, param map[string]string) string {
_, _ = h.Write([]byte(signStr))
return hex.EncodeToString(h.Sum(nil))
}

func OpenSend(appkey, appSecret, method string, params map[string]string, acctoken string) (string, error) {
url := "https://open.douyin.com/oauth/" + method + "/"
param := map[string]string{
"client_key": appkey,
"client_secret": appSecret,
}
if acctoken != "" {
param["access_token"] = acctoken
}
for k, v := range params {
param[k] = v
}
data, err := zhios_third_party_utils.CurlPost(url, param, nil)
return string(data), err
}

+ 5
- 7
tik_tok/svc_tik_tok_auth.go Bestand weergeven

@@ -14,13 +14,11 @@ func FirstAuth(args map[string]string) 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()
endTime := time.Now().Unix() + gjson.Get(send, "data.expires_in").Int() - 10
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_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": gjson.Get(send, "data.refresh_token").String(),
}
return data
}
@@ -31,7 +29,7 @@ func RefreshAuth(args map[string]string) map[string]string {
if err != nil {
return data
}
endTime := time.Now().Unix() + gjson.Get(send, "data.expires_in").Int()
endTime := time.Now().Unix() + gjson.Get(send, "data.expires_in").Int() - 10
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),


+ 61
- 0
tik_tok/svc_tik_tok_open_auth.go Bestand weergeven

@@ -0,0 +1,61 @@
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
}

+ 5
- 7
tik_tok/tik_tok_test.go Bestand weergeven

@@ -6,12 +6,10 @@ import (

func TestGoods(t *testing.T) {
args := map[string]string{
"cursor": "0",
"size": "20",
"order_ids": "5017095963287082709",
"acctoken": "12620ec1-e018-461b-8b04-3074d79cd6f6",
"appkey": "7136155008692651560",
"appSecret": "b132549f-f62c-491e-86f1-89af3658896a",
"code": "9cce4c56aa248711wtfAoxliYmH5DFDtENQJ",
"grantType": "authorization_code",
"appkey": "awxen1ub0ipjum5s",
"appSecret": "f0eb041ad451bd3a943976079864246d",
}
TrusteeshipProduct(args)
OpenFirstAuth(args)
}

Laden…
Annuleren
Opslaan