{
  "openapi": "3.1.0",
  "info": {
    "title": "Cloudsign Webhook receiver contract",
    "version": "1.3.0-preview.1",
    "description": "订阅需要的事件与来源，将通知发送到您自己的 HTTPS 接收地址。收到通知后，先用订阅密钥和原始请求字节验签，允许的时间偏差最多 300 秒。端点验证回显 event_id、challenge 和 CSWH1-ACK 证明。业务事件在持久保存并去重后回显 event_id。\n\n用接收端绑定的订阅区分 api（接口操作）、website（网站历史版本发布）和 website_upload（已有普通分发应用在网站更新版本）。在开发者中心确认需要的来源可用，并分别订阅。订阅前的活动不会补发，不同来源分别接收。网站更新通知中，上传任务 ID 用于关联这次网站操作。查询版本或当前发布状态时使用应用 ID 和版本 ID。\n\n需要财务通知时，新建具有相应权限的订阅，再选择所需的财务事件。通知提供交易标识和金额。使用 currency_revision 核对原报价的金额单位。收到重复或乱序事件时，按事件 ID 去重，并查询对应资源确认当前结果。"
  },
  "webhooks": {
    "notification": {
      "post": {
        "operationId": "receiveCloudsignNotification",
        "parameters": [
          {
            "name": "X-Cloudsign-Webhook-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^WHK[a-f0-9]{40}$"
            }
          },
          {
            "name": "X-Cloudsign-Event-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^E[a-f0-9]{32}$"
            }
          },
          {
            "name": "X-Cloudsign-Timestamp",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[1-9][0-9]{8,11}$"
            }
          },
          {
            "name": "X-Cloudsign-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^v1=[a-f0-9]{64}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Notification"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "必须在完成验签及幂等登记后确认接收；验证请求还须证明持有回调密钥",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/Receipt"
                    },
                    {
                      "$ref": "#/components/schemas/ChallengeReceipt"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "报文或签名无效；平台按有界策略重试"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "signing_succeeded": {
        "type": "object",
        "properties": {
          "schema_version": {
            "const": "1"
          },
          "id": {
            "type": "string",
            "pattern": "^E[a-f0-9]{32}$"
          },
          "webhook_id": {
            "type": "string",
            "pattern": "^WHK[a-f0-9]{40}$"
          },
          "type": {
            "const": "signing.succeeded"
          },
          "created_at": {
            "type": "integer",
            "minimum": 1
          },
          "data": {
            "type": "object",
            "properties": {
              "app_id": {
                "type": "string",
                "pattern": "^A[a-f0-9]{32}$"
              },
              "resource_id": {
                "type": "string",
                "pattern": "^J[a-f0-9]{32}$"
              },
              "status": {
                "const": "succeeded"
              }
            },
            "required": [
              "app_id",
              "resource_id",
              "status"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "schema_version",
          "id",
          "webhook_id",
          "type",
          "created_at",
          "data"
        ],
        "additionalProperties": false
      },
      "signing_failed": {
        "type": "object",
        "properties": {
          "schema_version": {
            "const": "1"
          },
          "id": {
            "type": "string",
            "pattern": "^E[a-f0-9]{32}$"
          },
          "webhook_id": {
            "type": "string",
            "pattern": "^WHK[a-f0-9]{40}$"
          },
          "type": {
            "const": "signing.failed"
          },
          "created_at": {
            "type": "integer",
            "minimum": 1
          },
          "data": {
            "type": "object",
            "properties": {
              "app_id": {
                "type": "string",
                "pattern": "^A[a-f0-9]{32}$"
              },
              "resource_id": {
                "type": "string",
                "pattern": "^J[a-f0-9]{32}$"
              },
              "status": {
                "const": "failed"
              }
            },
            "required": [
              "app_id",
              "resource_id",
              "status"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "schema_version",
          "id",
          "webhook_id",
          "type",
          "created_at",
          "data"
        ],
        "additionalProperties": false
      },
      "signing_cancelled": {
        "type": "object",
        "properties": {
          "schema_version": {
            "const": "1"
          },
          "id": {
            "type": "string",
            "pattern": "^E[a-f0-9]{32}$"
          },
          "webhook_id": {
            "type": "string",
            "pattern": "^WHK[a-f0-9]{40}$"
          },
          "type": {
            "const": "signing.cancelled"
          },
          "created_at": {
            "type": "integer",
            "minimum": 1
          },
          "data": {
            "type": "object",
            "properties": {
              "app_id": {
                "type": "string",
                "pattern": "^A[a-f0-9]{32}$"
              },
              "resource_id": {
                "type": "string",
                "pattern": "^J[a-f0-9]{32}$"
              },
              "status": {
                "const": "cancelled"
              }
            },
            "required": [
              "app_id",
              "resource_id",
              "status"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "schema_version",
          "id",
          "webhook_id",
          "type",
          "created_at",
          "data"
        ],
        "additionalProperties": false
      },
      "signing_superseded": {
        "type": "object",
        "properties": {
          "schema_version": {
            "const": "1"
          },
          "id": {
            "type": "string",
            "pattern": "^E[a-f0-9]{32}$"
          },
          "webhook_id": {
            "type": "string",
            "pattern": "^WHK[a-f0-9]{40}$"
          },
          "type": {
            "const": "signing.superseded"
          },
          "created_at": {
            "type": "integer",
            "minimum": 1
          },
          "data": {
            "type": "object",
            "properties": {
              "app_id": {
                "type": "string",
                "pattern": "^A[a-f0-9]{32}$"
              },
              "resource_id": {
                "type": "string",
                "pattern": "^J[a-f0-9]{32}$"
              },
              "status": {
                "const": "superseded"
              }
            },
            "required": [
              "app_id",
              "resource_id",
              "status"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "schema_version",
          "id",
          "webhook_id",
          "type",
          "created_at",
          "data"
        ],
        "additionalProperties": false
      },
      "upload_completed": {
        "type": "object",
        "properties": {
          "schema_version": {
            "const": "1"
          },
          "id": {
            "type": "string",
            "pattern": "^E[a-f0-9]{32}$"
          },
          "webhook_id": {
            "type": "string",
            "pattern": "^WHK[a-f0-9]{40}$"
          },
          "type": {
            "const": "upload.completed"
          },
          "created_at": {
            "type": "integer",
            "minimum": 1
          },
          "data": {
            "type": "object",
            "properties": {
              "app_id": {
                "type": "string",
                "pattern": "^A[a-f0-9]{32}$"
              },
              "resource_id": {
                "type": "string",
                "pattern": "^U[a-f0-9]{32}$"
              },
              "status": {
                "const": "succeeded"
              }
            },
            "required": [
              "app_id",
              "resource_id",
              "status"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "schema_version",
          "id",
          "webhook_id",
          "type",
          "created_at",
          "data"
        ],
        "additionalProperties": false
      },
      "upload_failed": {
        "type": "object",
        "properties": {
          "schema_version": {
            "const": "1"
          },
          "id": {
            "type": "string",
            "pattern": "^E[a-f0-9]{32}$"
          },
          "webhook_id": {
            "type": "string",
            "pattern": "^WHK[a-f0-9]{40}$"
          },
          "type": {
            "const": "upload.failed"
          },
          "created_at": {
            "type": "integer",
            "minimum": 1
          },
          "data": {
            "type": "object",
            "properties": {
              "app_id": {
                "type": "string",
                "pattern": "^A[a-f0-9]{32}$"
              },
              "resource_id": {
                "type": "string",
                "pattern": "^U[a-f0-9]{32}$"
              },
              "status": {
                "const": "failed"
              }
            },
            "required": [
              "app_id",
              "resource_id",
              "status"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "schema_version",
          "id",
          "webhook_id",
          "type",
          "created_at",
          "data"
        ],
        "additionalProperties": false
      },
      "upload_cancelled": {
        "type": "object",
        "properties": {
          "schema_version": {
            "const": "1"
          },
          "id": {
            "type": "string",
            "pattern": "^E[a-f0-9]{32}$"
          },
          "webhook_id": {
            "type": "string",
            "pattern": "^WHK[a-f0-9]{40}$"
          },
          "type": {
            "const": "upload.cancelled"
          },
          "created_at": {
            "type": "integer",
            "minimum": 1
          },
          "data": {
            "type": "object",
            "properties": {
              "app_id": {
                "type": "string",
                "pattern": "^A[a-f0-9]{32}$"
              },
              "resource_id": {
                "type": "string",
                "pattern": "^U[a-f0-9]{32}$"
              },
              "status": {
                "const": "cancelled"
              }
            },
            "required": [
              "app_id",
              "resource_id",
              "status"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "schema_version",
          "id",
          "webhook_id",
          "type",
          "created_at",
          "data"
        ],
        "additionalProperties": false
      },
      "endpoint_challenge": {
        "type": "object",
        "properties": {
          "schema_version": {
            "const": "1"
          },
          "id": {
            "type": "string",
            "pattern": "^E[a-f0-9]{32}$"
          },
          "webhook_id": {
            "type": "string",
            "pattern": "^WHK[a-f0-9]{40}$"
          },
          "type": {
            "const": "endpoint.challenge"
          },
          "created_at": {
            "type": "integer",
            "minimum": 1
          },
          "data": {
            "type": "object",
            "properties": {
              "challenge": {
                "type": "string",
                "pattern": "^[a-f0-9]{64}$"
              }
            },
            "required": [
              "challenge"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "schema_version",
          "id",
          "webhook_id",
          "type",
          "created_at",
          "data"
        ],
        "additionalProperties": false
      },
      "Notification": {
        "oneOf": [
          {
            "$ref": "#/components/schemas/signing_succeeded"
          },
          {
            "$ref": "#/components/schemas/signing_failed"
          },
          {
            "$ref": "#/components/schemas/signing_cancelled"
          },
          {
            "$ref": "#/components/schemas/signing_superseded"
          },
          {
            "$ref": "#/components/schemas/upload_completed"
          },
          {
            "$ref": "#/components/schemas/upload_failed"
          },
          {
            "$ref": "#/components/schemas/upload_cancelled"
          },
          {
            "$ref": "#/components/schemas/endpoint_challenge"
          },
          {
            "$ref": "#/components/schemas/order_paid"
          },
          {
            "$ref": "#/components/schemas/refund_completed"
          },
          {
            "$ref": "#/components/schemas/capacity_purchased"
          },
          {
            "$ref": "#/components/schemas/version_ready"
          },
          {
            "$ref": "#/components/schemas/distribution_published"
          }
        ]
      },
      "Receipt": {
        "type": "object",
        "properties": {
          "event_id": {
            "type": "string",
            "pattern": "^E[a-f0-9]{32}$"
          }
        },
        "required": [
          "event_id"
        ],
        "additionalProperties": false
      },
      "ChallengeReceipt": {
        "type": "object",
        "properties": {
          "event_id": {
            "type": "string",
            "pattern": "^E[a-f0-9]{32}$"
          },
          "challenge": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "proof": {
            "type": "string",
            "pattern": "^v1=[a-f0-9]{64}$"
          }
        },
        "required": [
          "event_id",
          "challenge",
          "proof"
        ],
        "additionalProperties": false
      },
      "order_paid": {
        "type": "object",
        "properties": {
          "schema_version": {
            "const": "1"
          },
          "id": {
            "type": "string",
            "pattern": "^E[a-f0-9]{32}$"
          },
          "webhook_id": {
            "type": "string",
            "pattern": "^WHK[a-f0-9]{40}$"
          },
          "type": {
            "const": "order.paid"
          },
          "created_at": {
            "type": "integer",
            "minimum": 1
          },
          "data": {
            "type": "object",
            "properties": {
              "app_id": {
                "type": "string",
                "pattern": "^A[a-f0-9]{32}$"
              },
              "resource_id": {
                "type": "string",
                "pattern": "^O[a-f0-9]{32}$"
              },
              "quote_id": {
                "type": "string",
                "pattern": "^Q[a-f0-9]{32}$"
              },
              "status": {
                "const": "paid"
              },
              "amount": {
                "type": "string",
                "pattern": "^(0|[1-9][0-9]{0,8})\\.[0-9]{2}$"
              },
              "currency_code": {
                "type": "string",
                "enum": [
                  "CNY",
                  "USD",
                  "EUR",
                  "HKD",
                  "GBP",
                  "POINT",
                  "CUSTOM"
                ]
              },
              "currency_revision": {
                "type": "string",
                "pattern": "^C[a-f0-9]{64}$"
              }
            },
            "required": [
              "app_id",
              "resource_id",
              "quote_id",
              "status",
              "amount",
              "currency_code",
              "currency_revision"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "schema_version",
          "id",
          "webhook_id",
          "type",
          "created_at",
          "data"
        ],
        "additionalProperties": false
      },
      "refund_completed": {
        "type": "object",
        "properties": {
          "schema_version": {
            "const": "1"
          },
          "id": {
            "type": "string",
            "pattern": "^E[a-f0-9]{32}$"
          },
          "webhook_id": {
            "type": "string",
            "pattern": "^WHK[a-f0-9]{40}$"
          },
          "type": {
            "const": "refund.completed"
          },
          "created_at": {
            "type": "integer",
            "minimum": 1
          },
          "data": {
            "type": "object",
            "properties": {
              "app_id": {
                "type": "string",
                "pattern": "^A[a-f0-9]{32}$"
              },
              "resource_id": {
                "type": "string",
                "pattern": "^O[a-f0-9]{32}$"
              },
              "quote_id": {
                "type": "string",
                "pattern": "^Q[a-f0-9]{32}$"
              },
              "status": {
                "const": "refunded"
              },
              "amount": {
                "type": "string",
                "pattern": "^(0|[1-9][0-9]{0,8})\\.[0-9]{2}$"
              },
              "currency_code": {
                "type": "string",
                "enum": [
                  "CNY",
                  "USD",
                  "EUR",
                  "HKD",
                  "GBP",
                  "POINT",
                  "CUSTOM"
                ]
              },
              "currency_revision": {
                "type": "string",
                "pattern": "^C[a-f0-9]{64}$"
              }
            },
            "required": [
              "app_id",
              "resource_id",
              "quote_id",
              "status",
              "amount",
              "currency_code",
              "currency_revision"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "schema_version",
          "id",
          "webhook_id",
          "type",
          "created_at",
          "data"
        ],
        "additionalProperties": false
      },
      "capacity_purchased": {
        "type": "object",
        "properties": {
          "schema_version": {
            "const": "1"
          },
          "id": {
            "type": "string",
            "pattern": "^E[a-f0-9]{32}$"
          },
          "webhook_id": {
            "type": "string",
            "pattern": "^WHK[a-f0-9]{40}$"
          },
          "type": {
            "const": "capacity.purchased"
          },
          "created_at": {
            "type": "integer",
            "minimum": 1
          },
          "data": {
            "type": "object",
            "properties": {
              "app_id": {
                "type": "string",
                "pattern": "^A[a-f0-9]{32}$"
              },
              "resource_id": {
                "type": "string",
                "pattern": "^O[a-f0-9]{32}$"
              },
              "quote_id": {
                "type": "string",
                "pattern": "^Q[a-f0-9]{32}$"
              },
              "status": {
                "const": "paid"
              },
              "amount": {
                "type": "string",
                "pattern": "^(0|[1-9][0-9]{0,8})\\.[0-9]{2}$"
              },
              "currency_code": {
                "type": "string",
                "enum": [
                  "CNY",
                  "USD",
                  "EUR",
                  "HKD",
                  "GBP",
                  "POINT",
                  "CUSTOM"
                ]
              },
              "currency_revision": {
                "type": "string",
                "pattern": "^C[a-f0-9]{64}$"
              }
            },
            "required": [
              "app_id",
              "resource_id",
              "quote_id",
              "status",
              "amount",
              "currency_code",
              "currency_revision"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "schema_version",
          "id",
          "webhook_id",
          "type",
          "created_at",
          "data"
        ],
        "additionalProperties": false
      },
      "version_ready": {
        "type": "object",
        "properties": {
          "schema_version": {
            "const": "1"
          },
          "id": {
            "type": "string",
            "pattern": "^E[a-f0-9]{32}$"
          },
          "webhook_id": {
            "type": "string",
            "pattern": "^WHK[a-f0-9]{40}$"
          },
          "type": {
            "const": "version.ready"
          },
          "created_at": {
            "type": "integer",
            "minimum": 1
          },
          "data": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "app_id",
              "resource_id",
              "status",
              "upload_id"
            ],
            "properties": {
              "app_id": {
                "type": "string",
                "pattern": "^A[a-f0-9]{32}$"
              },
              "resource_id": {
                "type": "string",
                "pattern": "^V[a-f0-9]{32}$"
              },
              "status": {
                "type": "string",
                "const": "ready"
              },
              "upload_id": {
                "type": "string",
                "pattern": "^U[a-f0-9]{32}$"
              }
            }
          }
        },
        "required": [
          "schema_version",
          "id",
          "webhook_id",
          "type",
          "created_at",
          "data"
        ],
        "additionalProperties": false
      },
      "distribution_published": {
        "type": "object",
        "properties": {
          "schema_version": {
            "const": "1"
          },
          "id": {
            "type": "string",
            "pattern": "^E[a-f0-9]{32}$"
          },
          "webhook_id": {
            "type": "string",
            "pattern": "^WHK[a-f0-9]{40}$"
          },
          "type": {
            "const": "distribution.published"
          },
          "created_at": {
            "type": "integer",
            "minimum": 1
          },
          "data": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "app_id",
              "resource_id",
              "status",
              "previous_version_id"
            ],
            "properties": {
              "app_id": {
                "type": "string",
                "pattern": "^A[a-f0-9]{32}$"
              },
              "resource_id": {
                "type": "string",
                "pattern": "^V[a-f0-9]{32}$"
              },
              "status": {
                "type": "string",
                "const": "published"
              },
              "previous_version_id": {
                "oneOf": [
                  {
                    "type": "string",
                    "pattern": "^V[a-f0-9]{32}$"
                  },
                  {
                    "type": "null"
                  }
                ]
              }
            }
          }
        },
        "required": [
          "schema_version",
          "id",
          "webhook_id",
          "type",
          "created_at",
          "data"
        ],
        "additionalProperties": false
      }
    }
  },
  "x-cloudsign-signature": {
    "request_canonical": [
      "CSWH1",
      "webhook_id",
      "event_id",
      "timestamp",
      "sha256(raw_body)"
    ],
    "challenge_ack_canonical": [
      "CSWH1-ACK",
      "webhook_id",
      "event_id",
      "challenge"
    ],
    "algorithm": "HMAC-SHA256; v1=<lowercase hex>",
    "max_body_bytes": 8192,
    "max_clock_skew_seconds": 300
  }
}
