mcpField
T
third-party-integration

third-party-integration

github.com/aj-geddes开发373440 次安装34 周前更新
代码仓库

关于 third-party-integration

面向开发者的外部服务集成技能,提供 API 调用、身份验证、错误处理和数据转换的实践模式与参考指南。

主要功能

  1. 01API 客户端模式
  2. 02身份验证与错误处理
  3. 03重试和速率限制建议
  4. 04Webhook 验证
  5. 05支付、邮件和 Python 集成指南

适用场景

  1. 01集成支付或消息服务
  2. 02连接分析、存储或 CRM 系统
  3. 03构建多服务架构

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill third-party-integration

安装后在 Claude Code 中输入/third-party-integration确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

references/
data-transformation.md
email-service-integration-sendgrid.md
payment-processor-integration-stripe.md
python-third-party-integration.md
third-party-client-wrapper.md
scripts/
validate-api.sh
templates/
api-scaffold.yaml

详细介绍

第三方集成

目录

概述

使用标准化模式处理 API 调用、错误处理、身份验证和数据转换,构建稳健的外部服务集成。

适用场景

  • 集成支付处理服务(Stripe、PayPal)
  • 使用消息服务(SendGrid、Twilio)
  • 连接分析平台(Mixpanel、Segment)
  • 与存储服务同步(AWS S3、Google Cloud)
  • 集成 CRM 系统(Salesforce、HubSpot)
  • 构建多服务架构

快速开始

最简可运行示例:

const axios = require("axios");

class ThirdPartyClient {
  constructor(config) {
    this.apiKey = config.apiKey;
    this.baseUrl = config.baseUrl;
    this.timeout = config.timeout || 30000;
    this.retryAttempts = config.retryAttempts || 3;
    this.retryDelay = config.retryDelay || 1000;
    this.client = axios.create({
      baseURL: this.baseUrl,
      timeout: this.timeout,
      headers: {
        Authorization: `Bearer ${this.apiKey}`,
        "Content-Type": "application/json",
      },
    });
  }

  async request(method, endpoint, data = null, options = {}) {
    let lastError;

    for (let attempt = 0; attempt < this.retryAttempts; attempt++) {
      try {
        const response = await this.client({
// ... (see reference guides for full implementation)

参考指南

references/ 目录中的详细实现:

指南内容
第三方客户端封装第三方客户端封装
支付处理服务集成(Stripe)支付处理服务集成(Stripe)
电子邮件服务集成(SendGrid)电子邮件服务集成(SendGrid)
Python 第三方集成Python 第三方集成
数据转换数据转换

最佳实践

✅ 应做
  • 使用指数退避实现重试逻辑
  • 验证 Webhook 签名
  • 记录所有 API 交互
  • 使用环境变量存储密钥
  • 将 API 响应转换为内部模型
  • 为关键服务实现熔断器
  • 监控 API 配额和速率限制
  • 添加适当的错误处理
  • 合理设置超时时间
  • 使用沙盒/测试 API 密钥进行测试
❌ 不要做
  • 将 API 密钥硬编码
  • 无限重试所有错误
  • 记录敏感数据
  • 信任未经验证的 Webhook 数据
  • 忽略速率限制
  • 发起同步阻塞调用
  • 向客户端暴露特定供应商的细节
  • 跳过错误处理
  • 在测试中使用生产密钥

评论

支持 Markdown