开发文档

重要提示:API 访问权限

P12 API 接口仅对以下用户开放:

  • 官方认证的代理商
  • 合作伙伴

普通用户无法访问 API 接口。如果您需要 API 访问权限,请先申请成为我们的代理商或合作伙伴。

欢迎使用智多星分发平台开发文档。本文档提供了完整的 API 接口说明、SDK 使用指南和示例代码,帮助您快速集成平台功能。

认证方式

所有 API 请求都需要进行身份验证。我们支持两种认证方式:

1. API Key 认证

在请求头中添加 API Key:

Authorization: Bearer YOUR_API_KEY

2. 签名认证

对于敏感操作,需要使用签名认证:

Authorization: Bearer YOUR_API_KEY
X-Timestamp: 1647834567
X-Signature: SHA256(API_KEY + TIMESTAMP + BODY)

API 接口

应用管理

接口 方法 描述 权限
/api/v1/apps POST 上传新应用 代理商合作伙伴
/api/v1/apps/{app_id} PUT 更新应用信息 代理商合作伙伴
/api/v1/apps/{app_id} DELETE 删除应用 代理商合作伙伴

设备管理

接口 方法 描述 权限
/api/v1/devices POST 添加设备 代理商合作伙伴
/api/v1/devices/{device_id} DELETE 删除设备 代理商合作伙伴
/api/v1/devices GET 查询设备列表 代理商合作伙伴

SDK 使用

我们提供了多种编程语言的 SDK,帮助您快速集成平台功能:

Python SDK

pip install p12-sdk

Node.js SDK

npm install p12-sdk

Java SDK

<dependency>
    <groupId>com.p12</groupId>
    <artifactId>p12-sdk</artifactId>
    <version>1.0.0</version>
</dependency>

示例代码

Python 示例

from p12_sdk import P12Client

client = P12Client(api_key='YOUR_API_KEY')

# 上传应用
response = client.upload_app(
    file_path='app.ipa',
    name='MyApp',
    version='1.0.0'
)

# 创建分发链接
distribution = client.create_distribution(
    app_id='app_123',
    expire_time='2024-12-31',
    install_limit=1000
)

Node.js 示例

const P12Client = require('p12-sdk');

const client = new P12Client({
    apiKey: 'YOUR_API_KEY'
});

// 上传应用
client.uploadApp({
    filePath: 'app.ipa',
    name: 'MyApp',
    version: '1.0.0'
}).then(response => {
    console.log(response);
});

// 创建分发链接
client.createDistribution({
    appId: 'app_123',
    expireTime: '2024-12-31',
    installLimit: 1000
}).then(distribution => {
    console.log(distribution);
});

错误码

错误码 说明 解决方案
400 请求参数错误 检查请求参数是否符合要求
401 认证失败 检查 API Key 是否正确
403 权限不足 确认是否有操作权限
429 请求频率超限 降低请求频率

最佳实践

1. 错误处理

  • 实现请求重试机制
  • 使用指数退避算法
  • 记录错误日志

2. 性能优化

  • 使用连接池
  • 实现请求缓存
  • 批量处理请求

3. 安全建议

  • 定期轮换 API Key
  • 使用 HTTPS 传输
  • 实现请求签名验证