更新 API 端点
这是向插件发送更新的 JavaScript 代码示例
interface AppInfos { version_name: string version_build: string version_os: string custom_id?: string is_prod?: boolean is_emulator?: boolean plugin_version: string platform: string app_id: string device_id: string}
export const handler: Handler = async (event) => { const body = JSON.parse(event.body || '{}') as AppInfos const { platform, app_id, version_os, device_id, version_name, version_build, plugin_version, } = body console.log('update asked', platform, app_id, version_os, device_id, version_name, version_build, plugin_version) if (version_name === '1.0.0') { return { version: '1.0.1', url: 'https://apiurl.com/mybuild_101.zip', checksum: 'sha256_checksum_of_bundle', } } else if (version_name === '1.0.1') { return { version: '1.0.2', url: 'https://apiurl.com/mybuild_102.zip', checksum: 'sha256_checksum_of_bundle', } } else { return { message: 'Error version not found' version: '', url: '', } }}对于非加密 bundle,您的端点应返回:
{ "version": "1.0.2", "url": "https://apiurl.com/mybuild_102.zip", "checksum": "sha256_checksum_of_bundle"}对于加密 bundle,您还需要包含会话密钥:
{ "version": "1.0.2", "url": "https://apiurl.com/mybuild_102.zip", "checksum": "encrypted_checksum_from_encrypt_command", "session_key": "ivSessionKey_from_encrypt_command"}如果没有更新或出现错误,请添加 message 键和可选的 error:
{ "message": "Version not found", "error": "The backend crashed", "version": "1.0.2",}checksum: 您的 bundle zip 文件的 SHA256 哈希,用于完整性验证session_key: 仅加密 bundle 需要 - 这是 encrypt 命令返回的ivSessionKeyversion: semver 格式的版本标识符url: 可以下载 bundle 的 HTTPS URL
Bundle 创建
Section titled “Bundle 创建”要了解如何创建兼容的 bundle 并生成校验和,请参阅自动更新文档。
对于加密 bundle,请参阅加密 Bundle 文档,其中说明了完整的加密工作流程。