btafoya/mixpost-api 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

btafoya/mixpost-api

Composer 安装命令:

composer require btafoya/mixpost-api

包简介

REST API add-on for Mixpost - enables n8n and external integrations

README 文档

README

Mixpost Logo

REST API extension for Mixpost - Enable powerful automation with n8n and external integrations

Latest Version on Packagist GitHub Tests Action Status Total Downloads License

📖 About

Mixpost REST API is a powerful Laravel package that extends Mixpost with comprehensive REST API capabilities. Built specifically to enable seamless integration with workflow automation tools like n8n, this add-on transforms Mixpost into a fully API-driven social media management platform.

🎯 Perfect For

  • Workflow Automation: Integrate with n8n, Zapier, Make.com
  • Custom Applications: Build your own social media management tools
  • AI-Powered Content: Auto-generate and publish content with AI services
  • Content Pipelines: Automate blog-to-social workflows
  • Team Collaboration: External tools can interact with Mixpost programmatically
  • Scheduled Automation: Time-based social media campaigns

✨ Features

🚀 API Coverage (v1.0.0)

  • Posts Management: Full CRUD operations, scheduling, and publishing
  • Media Handling: Upload files, download from URLs, manage library
  • Account Management: List and manage social media accounts
  • Tags & Organization: Create, update, delete tags

🔮 Planned Features (Future Releases)

  • 📅 Analytics & Reports: Dashboard metrics, account stats, post performance
  • 📅 Calendar Integration: View and manage scheduled content
  • 📅 System Monitoring: Check status, queue health, service configuration

🔐 Security & Performance

  • Laravel Sanctum Authentication: Secure token-based API access
  • Rate Limiting: Configurable request throttling (default: 60/min)
  • Permission System: Token abilities for granular access control
  • HTTPS Enforcement: Production-ready security
  • IP Whitelisting: Optional IP restriction
  • Input Validation: Comprehensive server-side validation

🎨 Developer Experience

  • RESTful Design: Clean, predictable API structure
  • JSON Responses: Consistent response formats
  • Pagination: Efficient data handling for large datasets
  • Error Handling: Detailed, actionable error messages
  • Comprehensive Documentation: Full API specification and examples
  • n8n Ready: Pre-built workflow examples included

📋 Requirements

  • PHP: ^8.2
  • Laravel: ^10.47 | ^11.0
  • Mixpost: ^1.0 (installed automatically as dev dependency)
  • Laravel Sanctum: ^3.0 | ^4.0

🚀 Installation

Step 1: Install via Composer

composer require inovector/mixpost-api

Step 2: Publish Configuration (Optional)

php artisan vendor:publish --tag=mixpost-api-config

This creates config/mixpost-api.php where you can customize:

  • API prefix
  • Rate limiting
  • Token expiration
  • Security settings
  • Pagination defaults

Step 3: Run Migrations

php artisan migrate

This creates the personal_access_tokens table for Laravel Sanctum.

Step 4: Update User Model

Add the HasApiTokens trait to your User model:

<?php

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable
{
    use HasApiTokens;

    // ... rest of your model
}

Step 5: You're Ready! 🎉

Your Mixpost installation now has REST API endpoints available at:

https://your-domain.com/api/mixpost/*

🔧 Configuration

Environment Variables

Add to your .env file:

# API Configuration
MIXPOST_API_RATE_LIMIT=60
MIXPOST_API_HTTPS_ONLY=true

# Token Configuration
MIXPOST_API_TOKEN_EXPIRATION=null  # null = never expire

Configuration File

Edit config/mixpost-api.php:

return [
    'prefix' => 'api/mixpost',

    'rate_limit' => [
        'enabled' => true,
        'max_attempts' => env('MIXPOST_API_RATE_LIMIT', 60),
        'decay_minutes' => 1,
    ],

    'token' => [
        'expiration' => env('MIXPOST_API_TOKEN_EXPIRATION'),
        'abilities_enabled' => true,
    ],

    'pagination' => [
        'default_per_page' => 20,
        'max_per_page' => 100,
    ],

    'security' => [
        'ip_whitelist_enabled' => false,
        'ip_whitelist' => [],
        'https_only' => env('MIXPOST_API_HTTPS_ONLY', true),
    ],
];

📚 Quick Start Guide

1. Generate API Token

Using cURL:

curl -X POST https://your-domain.com/api/mixpost/auth/tokens \
  -H "Content-Type: application/json" \
  -d '{
    "email": "admin@example.com",
    "password": "your-password",
    "token_name": "n8n-integration"
  }'

Response:

{
  "token": "1|abc123def456ghi789jkl012mno345pqr678stu901vwx234yz",
  "token_type": "Bearer",
  "expires_at": null
}

2. Use Token in Requests

curl -X GET https://your-domain.com/api/mixpost/posts \
  -H "Authorization: Bearer 1|abc123def456..." \
  -H "Accept: application/json"

3. Create a Post

curl -X POST https://your-domain.com/api/mixpost/posts \
  -H "Authorization: Bearer 1|abc123def456..." \
  -H "Content-Type: application/json" \
  -d '{
    "accounts": [1, 2, 3],
    "tags": [1],
    "date": "2025-10-24",
    "time": "10:00",
    "versions": [
      {
        "is_original": true,
        "account_id": null,
        "content": [
          {
            "body": "Check out our latest blog post! 🚀",
            "media": []
          }
        ]
      }
    ]
  }'

🎯 API Endpoints Overview

Authentication

  • POST /api/mixpost/auth/tokens - Generate API token
  • GET /api/mixpost/auth/tokens - List user tokens
  • DELETE /api/mixpost/auth/tokens/{id} - Revoke token

Posts

  • GET /api/mixpost/posts - List posts (with filtering & pagination)
  • POST /api/mixpost/posts - Create post
  • GET /api/mixpost/posts/{id} - Get post details
  • PUT /api/mixpost/posts/{id} - Update post
  • DELETE /api/mixpost/posts/{id} - Delete post
  • POST /api/mixpost/posts/{id}/schedule - Schedule post
  • POST /api/mixpost/posts/{id}/publish - Publish immediately
  • POST /api/mixpost/posts/{id}/duplicate - Duplicate post
  • DELETE /api/mixpost/posts - Bulk delete posts

Media

  • GET /api/mixpost/media - List media files
  • POST /api/mixpost/media - Upload media file
  • POST /api/mixpost/media/download - Download from URL
  • GET /api/mixpost/media/{id} - Get media details
  • DELETE /api/mixpost/media/{id} - Delete media file
  • DELETE /api/mixpost/media - Bulk delete media

Accounts

  • GET /api/mixpost/accounts - List social media accounts
  • GET /api/mixpost/accounts/{id} - Get account details
  • PUT /api/mixpost/accounts/{id} - Update account
  • DELETE /api/mixpost/accounts/{id} - Delete account

Tags

  • GET /api/mixpost/tags - List tags
  • POST /api/mixpost/tags - Create tag
  • PUT /api/mixpost/tags/{id} - Update tag
  • DELETE /api/mixpost/tags/{id} - Delete tag

📖 Full API Documentation: API_SPECIFICATION.md

Planned Endpoints (Future Releases)

Reports & Analytics

  • GET /api/mixpost/reports/dashboard - Dashboard summary
  • GET /api/mixpost/reports/accounts/{id} - Account analytics
  • GET /api/mixpost/reports/posts/{id} - Post performance

Calendar

  • GET /api/mixpost/calendar - Get scheduled posts

System Monitoring

  • GET /api/mixpost/system/status - System health check

🔌 n8n Integration

Quick Setup

  1. Create n8n Credential

    • Type: Header Auth
    • Name: Authorization
    • Value: Bearer YOUR_TOKEN_HERE
  2. Use HTTP Request Node

    • Method: POST
    • URL: https://your-domain.com/api/mixpost/posts
    • Authentication: Use the credential from step 1
    • Body: JSON with post data

Example Workflows

📝 Auto-Post from Blog Publication

Webhook (Blog Published)
  ↓
Upload Featured Image
  ↓
Create Social Post
  ↓
Publish Immediately

🤖 AI Content Generation

Schedule Trigger (Daily 9am)
  ↓
OpenAI (Generate Content)
  ↓
DALL-E (Generate Image)
  ↓
Upload to Mixpost
  ↓
Create Scheduled Post

📊 Performance Monitoring

Schedule Trigger (Daily 6pm)
  ↓
Get Dashboard Stats
  ↓
Check for Failed Posts
  ↓
Send Slack Notification

📖 Complete n8n Examples: N8N_INTEGRATION_EXAMPLES.md

📖 Documentation

Core Documentation

Example Use Cases

Use Case 1: Blog to Social Media

Automatically create social media posts when new blog articles are published.

Use Case 2: AI-Powered Content

Generate content with OpenAI and schedule posts across multiple platforms.

Use Case 3: Content Curation

Monitor RSS feeds and share relevant content automatically.

Use Case 4: Bulk Scheduling

Schedule multiple posts from CSV files or spreadsheets.

Use Case 5: Emergency Announcements

Publish urgent content immediately across all platforms.

🧪 Testing

Run Tests

# Run all tests
composer test

# Run with coverage
composer test-coverage

# Run specific test
vendor/bin/pest tests/Feature/PostsApiTest.php

Example Test

public function test_can_create_post_via_api()
{
    Sanctum::actingAs($this->user, ['*']);

    $response = $this->postJson('/api/mixpost/posts', [
        'accounts' => [1, 2],
        'versions' => [
            [
                'is_original' => true,
                'content' => [
                    ['body' => 'Test post', 'media' => []]
                ]
            ]
        ]
    ]);

    $response->assertStatus(201)
             ->assertJsonStructure(['data', 'message']);
}

🤝 Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests (composer test)
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

Development Guidelines

  • Follow PSR-12 coding standards
  • Write tests for new features
  • Update documentation for API changes
  • Keep backward compatibility when possible
  • Add changelog entries for notable changes

Code Style

# Format code
composer format

# Check code style
./vendor/bin/pint --test

🐛 Security Vulnerabilities

If you discover a security vulnerability, please send an email to security@example.com. All security vulnerabilities will be promptly addressed.

Do not open public issues for security vulnerabilities.

📜 Changelog

Please see CHANGELOG.md for recent changes.

Recent Updates

v1.0.0 (2025-10-23)

  • Initial release
  • Complete REST API for Mixpost
  • Laravel Sanctum authentication
  • n8n integration support
  • Comprehensive documentation

🙏 Credits

  • Mixpost - The amazing social media management platform this extends
  • Laravel - The PHP framework
  • Laravel Sanctum - API authentication
  • n8n - Workflow automation platform

Built With

📄 License

The MIT License (MIT). Please see LICENSE.md for more information.

MIT License

Copyright (c) 2025 Your Name

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software...

💬 Support

🌟 Star History

If you find this package useful, please consider giving it a ⭐ on GitHub!

Star History Chart

🔗 Links

Made with ❤️ for the Mixpost community

Transform your social media management with powerful API automation

btafoya/mixpost-api 适用场景与选型建议

btafoya/mixpost-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 10 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「rest」 「api」 「laravel」 「automation」 「social-media」 「laravel-package」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 btafoya/mixpost-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 btafoya/mixpost-api 我们能提供哪些服务?
定制开发 / 二次开发

基于 btafoya/mixpost-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 30
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-24