56 lines
2.7 KiB
Go
56 lines
2.7 KiB
Go
package lib
|
|
|
|
import (
|
|
"log"
|
|
"testing"
|
|
)
|
|
|
|
// 测试获取access_token
|
|
func TestGetAccessToken(t *testing.T) {
|
|
clientId := "awts8aqjcu8pxqfp"
|
|
clientKey := "99e1e72abf3f34cdcde98ee66b7d1d3e"
|
|
code := "34fdab59ce00457fTmE0jpw4ScrHvHMg6qdO"
|
|
douyin, _ := NewDouyin(clientId, clientKey)
|
|
accessToken, err := douyin.GetAccessToken(code)
|
|
/*
|
|
{"data":{"access_token":"act.3.5_J-R8c9wfgUj0a4pZjEMRmIoaPD68Rvldasnfej2PVhwPxUkyqvRX3flBmbrsKv3l2GjGaJmaqEAKjPRKvimUcIEe3b-mYVVCtxS4A2LSmHy_1yameFiDIsx5s1WLuCjKHG7xkK2ttfF1P9ekMC2apY1gCx_svDOO7b4kpn_nQLHOspBkkia
|
|
tpHozM=","captcha":"","desc_url":"","description":"","error_code":0,"expires_in":1296000,"log_id":"20231116121115068D627E382AD903DBD0","open_id":"_000Nj35bpCjCEAK2FCs7tvT-tv8Wg67rXK7","refresh_expires_in":2592000,"refresh_token":"rf
|
|
t.20e16e44793c8f6c809c480957cc2a99sagZlVcN22xXTxFXdZZJnEA0OgbW","scope":"user_info,item.comment,trial.whitelist"},"message":"success"}
|
|
*/
|
|
log.Println(accessToken, err)
|
|
}
|
|
|
|
// 测试获取用户信息
|
|
func TestGetUserInfo(t *testing.T) {
|
|
accessToken := "act.3.5_J-R8c9wfgUj0a4pZjEMRmIoaPD68Rvldasnfej2PVhwPxUkyqvRX3flBmbrsKv3l2GjGaJmaqEAKjPRKvimUcIEe3b-mYVVCtxS4A2LSmHy_1yameFiDIsx5s1WLuCjKHG7xkK2ttfF1P9ekMC2apY1gCx_svDOO7b4kpn_nQLHOspBkkia\ntpHozM="
|
|
openId := "_000Nj35bpCjCEAK2FCs7tvT-tv8Wg67rXK7"
|
|
douyin, _ := NewDouyin("", "")
|
|
accessToken, err := douyin.GetUserInfo(accessToken, openId)
|
|
/*
|
|
{"data":{"avatar":"https://p3.douyinpic.com/aweme/100x100/aweme-avatar/tos-cn-i-0813_8b415d554ccb41858abb6e251089c06a.jpeg?from=4010531038","avatar_larger":"https://p3.douyinpic.com/aweme/1080x1080/aweme-avatar/t
|
|
os-cn-i-0813_8b415d554ccb41858abb6e251089c06a.jpeg?from=4010531038","captcha":"","city":"","client_key":"awts8aqjcu8pxqfp","country":"","desc_url":"","description":"","district":"","e_account_role":"","error_code":0,"gender":0,"log_
|
|
id":"2023111614325371846E270CC9EB10F5CA","nickname":"程序员老狼","open_id":"_000Nj35bpCjCEAK2FCs7tvT-tv8Wg67rXK7","province":"","union_id":"6e31ab03-83d9-42bd-9d83-e90e0b57ffe1"},"message":"success"}
|
|
*/
|
|
log.Println(accessToken, err)
|
|
}
|
|
|
|
// 刷新access_token
|
|
func TestRefeshNewAccessToken(t *testing.T) {
|
|
clientId := "awts8aqjcu8pxqfp"
|
|
clientKey := "99e1e72abf3f34cdcde98ee66b7d1d3e"
|
|
|
|
douyin, _ := NewDouyin(clientId, clientKey)
|
|
accessToken, err := douyin.RefeshNewAccessToken("rft.ac8727fbc14d1f8297176d5f1cc108e6EDei3JO9qJyT1I6tX15uxWGKqGsI")
|
|
log.Println(accessToken, err)
|
|
}
|
|
|
|
// 刷新access_token
|
|
func TestRenewRefreshToken(t *testing.T) {
|
|
clientId := "awts8aqjcu8pxqfp"
|
|
clientKey := "99e1e72abf3f34cdcde98ee66b7d1d3e"
|
|
|
|
douyin, _ := NewDouyin(clientId, clientKey)
|
|
accessToken, err := douyin.RenewRefreshToken("rft.ac8727fbc14d1f8297176d5f1cc108e6EDei3JO9qJyT1I6tX15uxWGKqGsI")
|
|
log.Println(accessToken, err)
|
|
}
|