feat: 添加商品绑定功能
- 在图文发布和视频发布流程中集成商品绑定功能 - 新增 Products 字段到发布请求结构体 - 实现 go-rod 原生商品绑定函数(bindProducts) - 商品绑定失败将阻断发布流程并返回具体错误信息 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -21,6 +21,7 @@ type PublishVideoContent struct {
|
||||
VideoPath string
|
||||
ScheduleTime *time.Time // 定时发布时间,nil 表示立即发布
|
||||
Visibility string // 可见范围: "公开可见"(默认), "仅自己可见", "仅互关好友可见"
|
||||
Products []string // 商品关键词列表,用于绑定带货商品
|
||||
}
|
||||
|
||||
// NewPublishVideoAction 进入发布页并切换到"上传视频"
|
||||
@@ -63,7 +64,7 @@ func (p *PublishAction) PublishVideo(ctx context.Context, content PublishVideoCo
|
||||
return errors.Wrap(err, "小红书上传视频失败")
|
||||
}
|
||||
|
||||
if err := submitPublishVideo(page, content.Title, content.Content, content.Tags, content.ScheduleTime, content.Visibility); err != nil {
|
||||
if err := submitPublishVideo(page, content.Title, content.Content, content.Tags, content.ScheduleTime, content.Visibility, content.Products); err != nil {
|
||||
return errors.Wrap(err, "小红书发布失败")
|
||||
}
|
||||
return nil
|
||||
@@ -131,7 +132,7 @@ func waitForPublishButtonClickable(page *rod.Page) (*rod.Element, error) {
|
||||
}
|
||||
|
||||
// submitPublishVideo 填写标题、正文、标签并点击发布(等待按钮可点击后再提交)
|
||||
func submitPublishVideo(page *rod.Page, title, content string, tags []string, scheduleTime *time.Time, visibility string) error {
|
||||
func submitPublishVideo(page *rod.Page, title, content string, tags []string, scheduleTime *time.Time, visibility string, products []string) error {
|
||||
// 标题
|
||||
titleElem, err := page.Element("div.d-input input")
|
||||
if err != nil {
|
||||
@@ -172,6 +173,11 @@ func submitPublishVideo(page *rod.Page, title, content string, tags []string, sc
|
||||
return errors.Wrap(err, "设置可见范围失败")
|
||||
}
|
||||
|
||||
// 绑定商品
|
||||
if err := bindProducts(page, products); err != nil {
|
||||
return errors.Wrap(err, "绑定商品失败")
|
||||
}
|
||||
|
||||
// 等待发布按钮可点击
|
||||
btn, err := waitForPublishButtonClickable(page)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user