# SMS API

import { Badge } from '@astrojs/starlight/components';

<Aside type="caution" title="/createSMSMessage 已弃用">
新的集成应使用 [Messaging API v2](/zh/developer/api-reference/messaging-api-v2/) — 将 `platforms: ["SMS"]` 传递给 `Notify`。请参阅[迁移指南](/zh/developer/api-reference/messaging-api-v2/migration-from-v1/#from-createsmsmessage)。
</Aside>

<Aside type="note">
在发送 SMS 消息之前，请在控制面板中连接您的 SMS 提供商。[了解更多](/zh/developer/first-steps/connect-messaging-services/sms-configuration/)
</Aside>

## createSMSMessage <Badge text="已弃用" variant="caution" size="small" />

用于向用户发送 SMS 通知

POST `https://api.pushwoosh.com/json/1.3/createSMSMessage`

### 请求正文

| 名称                           | 必需 | 类型    | 描述                                                                                                  |
|--------------------------------|----------|---------|--------------------------------------------------------------------------------------------------------------|
| **auth***                      | 是      | string  | 来自 Pushwoosh 控制面板的 [API access token](/zh/developer/api-reference/api-identifiers/#api-access-token)。                                                               |
| **application***               | 是      | string  | [Pushwoosh application code](/zh/developer/api-reference/api-identifiers/#application-code)                                                                                 |
| **notifications***             | 是      | array   | 内容设置。消息参数的 JSON 数组。详见下文。                                       |

**通知参数**

| 名称                             | 必需 | 类型    | 描述                                                                                                                                                                                   |
|----------------------------------|----------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **send_date***                   | 是      | string  | 发送通知的日期和时间。使用格式 `YYYY-MM-DD HH:mm` 或 `now` 立即发送。                                                                                           |
| **content***                     | 是      | string  | SMS 消息的文本内容。                                                                                                                                                              |
| **devices***                     | 是      | array   | 客户电话号码（必须使用 `/registerDevice` 与 UserId 关联，并在 `hwid` 参数中指定，或使用 `use_auto_registration`）。此处只能指定一个号码。 |
| **use_auto_registration**        | 否       | boolean | 如果设置为 `true`，在 `devices` 参数中指定的电话号码将被自动注册。                                                                                      |
| **dynamic_content_placeholders** | 否       | object  | 动态内容占位符，用于自定义消息内容。每个占位符都将被替换为相应的动态值。                                                           |
| **preset**                       | 否       | string  | 来自您控制面板的 SMS [Preset Code](/zh/developer/api-reference/api-identifiers/#preset-code)。                                                                                                                                                      |

### 请求示例

```json
{
  "request": {
    "application": "12345-67891",    // 必需。Pushwoosh application code。
    "auth": "yxoPUlwqm…………pIyEX4H",  // 必需。来自 Pushwoosh 控制面板的 API access token。
    "notifications": [{
      "send_date": "now",            // 必需。YYYY-MM-DD HH:mm 或 "now"。
      "content": "Hello!",           // 必需。SMS 文本 (字符串)。
      "devices": ["+1234567890"],    // 必需。客户电话号码（必须使用 /registerDevice 与
                                     //           UserId 关联，并在 "hwid" 参数中指定，
                                     //           或使用 "use_auto_registration"）。
                                     //           此处只能指定一个号码。
      "preset": "XXXXX-XXXXX",       // 可选。来自您控制面板的 SMS Preset Code。
      "use_auto_registration": true  // 可选。自动注册在 "devices" 参数中指定的电话号码。
    }]
  }
}
```

### 响应示例

```json
{
  "status_code": 200,
  "status_message": "OK",
  "response": {
    "Messages": [
      "9648-0B10ECB6-0D9F214D"
    ]
  }
}
```

### 错误响应
```json
{
  "status_code": 210,
  "status_message": "Invalid devices list. \"devices\" must be an array.",
  "response": {
    "Messages": []
  }
}
```

<Aside type="note">
目前，每条 SMS 都必须为每个客户在单独的请求中发送。
</Aside>

要获取 SMS 统计数据，请使用 [totalsByIntervals](/zh/developer/api-reference/statistics-api/message-statistics-api/#totalsbyintervals) 方法。

您还可以在 [Message History](/zh/product/statistics-and-analytics/message-history/) 部分查看每条消息的统计数据。

<Aside type="caution">
请注意，一些移动运营商不传输送达状态数据，因此统计数据可能不够准确。您可以与为您的客户提供号码的移动运营商核实详细信息。
</Aside>