feat: 添加商品绑定功能

- 在图文发布和视频发布流程中集成商品绑定功能
- 新增 Products 字段到发布请求结构体
- 实现 go-rod 原生商品绑定函数(bindProducts)
- 商品绑定失败将阻断发布流程并返回具体错误信息

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
tanjun
2026-01-24 19:30:59 +08:00
committed by tan jun
parent bc7fc864b5
commit d092830b67
5 changed files with 306 additions and 7 deletions

View File

@@ -129,6 +129,7 @@ func (s *AppServer) handlePublishContent(ctx context.Context, args map[string]in
content, _ := args["content"].(string)
imagePathsInterface, _ := args["images"].([]interface{})
tagsInterface, _ := args["tags"].([]interface{})
productsInterface, _ := args["products"].([]interface{})
var imagePaths []string
for _, path := range imagePathsInterface {
@@ -144,6 +145,13 @@ func (s *AppServer) handlePublishContent(ctx context.Context, args map[string]in
}
}
var products []string
for _, p := range productsInterface {
if pStr, ok := p.(string); ok {
products = append(products, pStr)
}
}
// 解析定时发布参数
scheduleAt, _ := args["schedule_at"].(string)
visibility := parseVisibility(args)
@@ -151,7 +159,7 @@ func (s *AppServer) handlePublishContent(ctx context.Context, args map[string]in
// 解析原创参数
isOriginal, _ := args["is_original"].(bool)
logrus.Infof("MCP: 发布内容 - 标题: %s, 图片数量: %d, 标签数量: %d, 定时: %s, 原创: %v, visibility: %s", title, len(imagePaths), len(tags), scheduleAt, isOriginal, visibility)
logrus.Infof("MCP: 发布内容 - 标题: %s, 图片数量: %d, 标签数量: %d, 定时: %s, 原创: %v, visibility: %s, 商品: %v", title, len(imagePaths), len(tags), scheduleAt, isOriginal, visibility, products)
// 构建发布请求
req := &PublishRequest{
@@ -162,6 +170,7 @@ func (s *AppServer) handlePublishContent(ctx context.Context, args map[string]in
ScheduleAt: scheduleAt,
IsOriginal: isOriginal,
Visibility: visibility,
Products: products,
}
// 执行发布
@@ -193,6 +202,7 @@ func (s *AppServer) handlePublishVideo(ctx context.Context, args map[string]inte
content, _ := args["content"].(string)
videoPath, _ := args["video"].(string)
tagsInterface, _ := args["tags"].([]interface{})
productsInterface, _ := args["products"].([]interface{})
var tags []string
for _, tag := range tagsInterface {
@@ -201,6 +211,13 @@ func (s *AppServer) handlePublishVideo(ctx context.Context, args map[string]inte
}
}
var products []string
for _, p := range productsInterface {
if pStr, ok := p.(string); ok {
products = append(products, pStr)
}
}
if videoPath == "" {
return &MCPToolResult{
Content: []MCPContent{{
@@ -215,7 +232,7 @@ func (s *AppServer) handlePublishVideo(ctx context.Context, args map[string]inte
scheduleAt, _ := args["schedule_at"].(string)
visibility := parseVisibility(args)
logrus.Infof("MCP: 发布视频 - 标题: %s, 标签数量: %d, 定时: %s, visibility: %s", title, len(tags), scheduleAt, visibility)
logrus.Infof("MCP: 发布视频 - 标题: %s, 标签数量: %d, 定时: %s, visibility: %s, 商品: %v", title, len(tags), scheduleAt, visibility, products)
// 构建发布请求
req := &PublishVideoRequest{
@@ -225,6 +242,7 @@ func (s *AppServer) handlePublishVideo(ctx context.Context, args map[string]inte
Tags: tags,
ScheduleAt: scheduleAt,
Visibility: visibility,
Products: products,
}
// 执行发布