This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/perfect-panel/server/pkg/kutt"
|
||||
)
|
||||
|
||||
// 测试 Kutt 短链接 API
|
||||
// 运行方式: go run cmd/test_kutt/main.go
|
||||
func main() {
|
||||
// Kutt 配置 - 请根据实际情况修改
|
||||
apiURL := "https://getsapp.net/api/v2"
|
||||
apiKey := "6JSjGOzLF1NCYQXuUGZjvrkqU0Jy3upDkYX87DPO"
|
||||
targetURL := "https://gethifast.net"
|
||||
|
||||
// 测试邀请码
|
||||
testInviteCode := "TEST123"
|
||||
|
||||
fmt.Println("====== Kutt 短链接 API 测试 ======")
|
||||
fmt.Printf("API URL: %s\n", apiURL)
|
||||
fmt.Printf("Target URL: %s\n", targetURL)
|
||||
fmt.Printf("测试邀请码: %s\n", testInviteCode)
|
||||
fmt.Println("----------------------------------")
|
||||
|
||||
// 创建客户端
|
||||
client := kutt.NewClient(apiURL, apiKey)
|
||||
ctx := context.Background()
|
||||
|
||||
// 测试 1: 使用便捷方法创建邀请短链接
|
||||
fmt.Println("\n[测试 1] 创建邀请短链接...")
|
||||
shortLink, err := client.CreateInviteShortLink(ctx, targetURL, testInviteCode, "getsapp.net")
|
||||
if err != nil {
|
||||
log.Printf("❌ 创建短链接失败: %v\n", err)
|
||||
} else {
|
||||
fmt.Printf("✅ 短链接创建成功: %s\n", shortLink)
|
||||
}
|
||||
|
||||
// 测试 2: 使用完整参数创建短链接
|
||||
fmt.Println("\n[测试 2] 使用完整参数创建短链接...")
|
||||
req := &kutt.CreateLinkRequest{
|
||||
Target: fmt.Sprintf("%s/register?invite=%s", targetURL, "CUSTOM456"),
|
||||
Description: "Test custom short link",
|
||||
Reuse: true,
|
||||
}
|
||||
link, err := client.CreateShortLink(ctx, req)
|
||||
if err != nil {
|
||||
log.Printf("❌ 创建短链接失败: %v\n", err)
|
||||
} else {
|
||||
// 打印详细返回信息
|
||||
linkJSON, _ := json.MarshalIndent(link, "", " ")
|
||||
fmt.Printf("✅ 短链接创建成功:\n%s\n", string(linkJSON))
|
||||
}
|
||||
|
||||
fmt.Println("\n====== 测试完成 ======")
|
||||
}
|
||||
Reference in New Issue
Block a user