> ## Documentation Index
> Fetch the complete documentation index at: https://docs-zns.adflex.vn/llms.txt
> Use this file to discover all available pages before exploring further.

# Gửi mã hoá đầu-cuối (RSA)

> Gửi tin mã hoá đầu-cuối. AdFlex không lưu số điện thoại.

Thông số mã hoá: `RSA/ECB/OAEP`, hash OAEP = SHA-256, MGF1 = SHA-1. Khoá công khai lấy tại Console → Official Account → Thiết lập RSA key.

Thư viện chuẩn của Node.js và Go không hỗ trợ chọn MGF1. Xem hướng dẫn Gửi RSA.

Scope: `messages:send`



## OpenAPI

````yaml https://business.adflex.vn/openapi.json post /api/v1/messages/rsa
openapi: 3.1.0
info:
  title: AdFlex ZNS API
  version: 1.0.0
  description: >-
    API gửi tin Zalo ZNS của AdFlex.


    API vận hành ở chế độ production, không có môi trường sandbox. Mỗi request
    thành công tạo một tin thật và trừ phí theo giá template.
  contact:
    name: AdFlex for Business
    url: https://business.adflex.vn
servers:
  - url: https://business.adflex.vn
    description: Production
security:
  - bearerAuth: []
  - apiKeyAuth: []
tags:
  - name: Template
    description: Khám phá template và OA khả dụng
  - name: Gửi tin
    description: Gửi một tin, gửi lô, gửi mã hoá đầu-cuối
  - name: Tra cứu
    description: Trạng thái tin và huỷ tin chưa gửi
paths:
  /api/v1/messages/rsa:
    post:
      tags:
        - Gửi tin
      summary: Gửi mã hoá đầu-cuối (RSA)
      description: >-
        Gửi tin mã hoá đầu-cuối. AdFlex không lưu số điện thoại.


        Thông số mã hoá: `RSA/ECB/OAEP`, hash OAEP = SHA-256, MGF1 = SHA-1. Khoá
        công khai lấy tại Console → Official Account → Thiết lập RSA key.


        Thư viện chuẩn của Node.js và Go không hỗ trợ chọn MGF1. Xem hướng dẫn
        Gửi RSA.


        Scope: `messages:send`
      operationId: sendRsa
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - template_id
                - recipients
              properties:
                template_id:
                  type: string
                  example: '123456'
                send_at:
                  type: string
                  format: date-time
                recipients:
                  type: array
                  minItems: 1
                  maxItems: 500
                  items:
                    type: object
                    required:
                      - rsa_phone
                    properties:
                      rsa_phone:
                        type: string
                        description: >-
                          Số điện thoại đã chuẩn hoá 84xxxxxxxxx rồi mã hoá RSA,
                          base64 một dòng (684 ký tự).
                      template_data:
                        type: object
                        additionalProperties:
                          type: string
                        description: >-
                          Từng GIÁ TRỊ đã mã hoá riêng, base64. Tên tham số giữ
                          nguyên, không mã hoá.
                      tracking_id:
                        type: string
                        description: >-
                          Mã đối soát do hệ thống của bạn định nghĩa. Không
                          truyền thì AdFlex dùng msg_id.


                          Tối đa 48 ký tự; chỉ chấp nhận chữ, số, dấu chấm, gạch
                          ngang, gạch dưới. Vi phạm trả lỗi 400.
                        maxLength: 48
                        pattern: ^[A-Za-z0-9._-]+$
      responses:
        '202':
          description: Lô đã được nhận
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RsaAccepted'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/PaymentRequired'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
components:
  schemas:
    RsaAccepted:
      type: object
      description: >-
        202 nghĩa là lô đã được nhận, KHÔNG nghĩa là mọi người nhận đều hợp lệ.
        Luôn đọc results.
      properties:
        accepted:
          type: integer
          description: Số người nhận thực sự vào hàng đợi
        total:
          type: integer
        scheduled_at:
          type:
            - string
            - 'null'
          format: date-time
        results:
          type: array
          items:
            $ref: '#/components/schemas/RsaResult'
    RsaResult:
      type: object
      description: Không có trường phone — hệ thống không biết số nên không trả lại được.
      properties:
        msg_id:
          type: string
        tracking_id:
          type: string
          description: >-
            Mã đối soát do hệ thống của bạn định nghĩa. Không truyền thì AdFlex
            dùng msg_id.


            Tối đa 48 ký tự; chỉ chấp nhận chữ, số, dấu chấm, gạch ngang, gạch
            dưới. Vi phạm trả lỗi 400.
          maxLength: 48
          pattern: ^[A-Za-z0-9._-]+$
        status:
          type: string
          enum:
            - queued
            - error
        error:
          type: string
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: integer
              example: 401
            message:
              type: string
              example: API key không hợp lệ hoặc đã bị thu hồi
  responses:
    BadRequest:
      description: Body sai hoặc thiếu trường bắt buộc
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Unauthorized:
      description: Thiếu API key, key sai hoặc đã bị thu hồi
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    PaymentRequired:
      description: Ví không đủ cho cả lô — không tin nào được gửi
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Forbidden:
      description: Key thiếu scope, hoặc workspace đang tạm dừng
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    NotFound:
      description: Không tìm thấy tài nguyên trong workspace của key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: 'Authorization: Bearer ak_live_…'
    apiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key
      description: Cách thay thế cho Bearer. Dùng một trong hai là đủ.

````