> ## Documentation Index
> Fetch the complete documentation index at: https://pwapi.uuwallet.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Webhook 回调示例

回调 api 用于在特定事件发生时，PowerCard 向商户系统发送通知。这种机制允许 PowerCard系统异步告知商户操作的结果或状态变化。商户需要向
PowerCard 提供一个回调 api URL，按规则实现回调 api 的功能。

商户收到 PowerCard 的 Webhook 后，使用 RSA 私钥对请求体中的 key 进行解密，将解密后的数据进行 Base64 解码得到 AES 密钥。使用解码出的
AES 密钥对请求体中的 data 进行解密，将解密后的数据进行 Base64 解码后得到最终的数据。根据 eventType 对相应的业务类型进行处理。

```json
{
  "eventType": "CARD_CREATE",
  "key": "xxxxxxxxxx",
  "data": "xxxxxxxxxxx"
}
```

|      **事件类型**     |                    **说明**                   |
| :---------------: | :-----------------------------------------: |
|    card\_create   |      创建卡片成功的回调通知。只有在创建卡片成功后，商户才会收到该回调通知     |
|   card\_recharge  |  充值卡片的回调通知。当 PowerCard 成功处理一笔充值订单后，会发送该回调通知 |
|    card\_cancel   |  注销卡片的回调通知。当 PowerCard 成功处理一笔销卡订单后，会发送该回调通知 |
| card\_transaction | 用户消费订单的回调通知。当 PowerCard 收到商家的消费信息后，会发送该回调通知 |
|    card\_status   | 卡片状态变更的回调通知。当卡片被冻结或者解冻的时候，PowerCard会发送该回调通知 |

商户收到 Webhook 后，应当返回处理成功或者失败的响应。当 PowerCard 收到响应为 “success”的字符串时，将认定商户已成功处理本次
Webhook，不再进行通知；否则 PowerCard 会进行重复通知，频率为第 5 分钟、第 10 分钟、第 30 分钟、第 60
分钟。商户返回的响应，不应当进行任何加密，样例如下：

**Response 示例**

```json
    "success"
```


## OpenAPI

````yaml WEBHOOK /powercard/callbackExample
openapi: 3.1.0
info:
  title: powercard-api
  description: ''
  version: 1.0.0
servers:
  - url: http://dev-cn.your-api-server.com
    description: 开发环境
security: []
tags: []
paths:
  /powercard/callbackExample:
    post:
      tags: []
      summary: webhook参考
      parameters: []
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MerchantNotifyRequest'
            examples: {}
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                type:
                  - string
                  - 'null'
                const: success
          headers: {}
      deprecated: false
      security:
        - apikey-header-merchantId: []
components:
  schemas:
    MerchantNotifyRequest:
      type: object
      properties:
        eventType:
          type: string
          enum:
            - card_create
            - card_recharge
            - card_cancel
            - card_transaction
            - card_status
        data:
          type: string
        key:
          type: string
      required:
        - eventType
        - data
        - key

````