Help Center SMS 消息

SMS 消息

使用 SMSBAT API 发送标准文本消息。SMS 是最通用的消息渠道,在所有手机设备上的送达率最高。

概述

SMS(短消息服务)适用于:

  • 时效性强的通知
  • 作为 Viber/RCS 消息的备用方案
  • 触达没有智能手机的用户
  • 在所有移动网络上的通用兼容性
  • 高送达率(95%+)

基本 SMS 消息

请求

{
  "from": "YourSender",
  "to": "+380XXXXXXXXX",
  "type": "sms",
  "text": "Your SMS message text"
}

参数

参数类型必填说明
fromstring是字母数字发件人 ID(最多 11 个字符)
tostring是E.164 格式的收件人手机号码
typestring是设置为 "sms"
textstring是消息内容
customerMessageIdstring否您的内部跟踪 ID
ttlinteger否以秒为单位的生存时间

示例

简单 SMS

curl -X POST https://restapi.smsbat.com/bat/messagelist \
  -H "X-Authorization-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [{
      "from": "YourBrand",
      "to": "+380XXXXXXXXX",
      "type": "sms",
      "text": "Hello! This is a test SMS message."
    }]
  }'

带客户 ID 的 SMS

{
  "messages": [{
    "from": "YourStore",
    "to": "+380XXXXXXXXX",
    "type": "sms",
    "text": "Your order #12345 has been shipped.",
    "customerMessageId": "order-12345-notification"
  }]
}

带 TTL 的 SMS

{
  "messages": [{
    "from": "YourApp",
    "to": "+380XXXXXXXXX",
    "type": "sms",
    "text": "Your verification code is: 123456",
    "ttl": 300
  }]
}

字符编码

GSM 7 位编码

标准 GSM 字母表(每条 SMS 160 个字符):

A-Z a-z 0-9
@ £ $ ¥ è é ù ì ò Ç Ø ø Å å
Δ _ Φ Γ Λ Ω Π Ψ Σ Θ Ξ
! " # % & ' ( ) * + , - . / : ; < = > ?

扩展 GSM 字符

这些字符按 2 个字符计算:

| ^ € { } [ ] ~ \

Unicode(UCS-2)编码

包含特殊字符的消息使用 Unicode 编码(每条 SMS 70 个字符):

  • 表情符号:😀 🎉 ❤️
  • 西里尔字母:А Б В Г Д Е Ж
  • 特殊符号:✓ ✗ ★ ♥

消息长度

单条 SMS

  • GSM 7 位:160 个字符
  • Unicode:70 个字符

多段 SMS

当消息超过限制时,会被拆分为多个部分:

  • GSM 7 位:每段 153 个字符
  • Unicode:每段 67 个字符

示例

{
  "messages": [{
    "from": "YourBrand",
    "to": "+380XXXXXXXXX",
    "type": "sms",
    "text": "This is a very long message that will be split into multiple parts. Each part will be delivered separately but will appear as a single message on the recipient's phone. The system automatically handles the splitting and reassembly."
  }]
}

这条消息(201 个字符)将被拆分为 2 段。

响应

成功响应

{
  "messagelistId": 123456,
  "messages": [
    {
      "messageId": "abc123def456",
      "status": "accepted",
      "parts": 2,
      "customerMessageId": "order-12345-notification",
      "to": "+380XXXXXXXXX"
    }
  ]
}

响应字段

字段说明
messageId用于跟踪的唯一标识符
status消息状态(accepted、rejected)
partsSMS 段数
to收件人手机号码

发件人 ID

字母数字发件人

使用您的品牌名称作为发件人(最多 11 个字符):

{
  "from": "YourBrand",
  "to": "+380XXXXXXXXX",
  "type": "sms",
  "text": "Hello from YourBrand!"
}

限制:

  • 最多 11 个字符
  • 仅限字母和数字
  • 不能包含空格或特殊字符
  • 收件人无法回复字母数字发件人

数字发件人

使用手机号码作为发件人(用于双向 SMS):

{
  "from": "+380123456789",
  "to": "+380XXXXXXXXX",
  "type": "sms",
  "text": "Hello! You can reply to this message."
}

使用场景

OTP 验证

{
  "from": "YourApp",
  "to": "+380XXXXXXXXX",
  "type": "sms",
  "text": "Your verification code is: 123456. Valid for 5 minutes.",
  "ttl": 300
}

订单通知

{
  "from": "YourStore",
  "to": "+380XXXXXXXXX",
  "type": "sms",
  "text": "Your order #12345 has been delivered. Thank you for shopping with us!"
}

预约提醒

{
  "from": "YourClinic",
  "to": "+380XXXXXXXXX",
  "type": "sms",
  "text": "Reminder: Your appointment is scheduled for tomorrow at 2:00 PM."
}

付款确认

{
  "from": "YourBank",
  "to": "+380XXXXXXXXX",
  "type": "sms",
  "text": "Payment of 100 USD to Merchant ABC was successful. Transaction ID: 789xyz"
}

最佳实践

消息内容

  • ✅ 保持消息简洁明了
  • ✅ 包含发件人标识
  • ✅ 如有需要,添加行动号召
  • ✅ 使用正确的语法和拼写
  • ❌ 避免过多的标点符号!!!
  • ❌ 不要全部使用大写字母
  • ❌ 避免使用看起来可疑的短链接服务

字符使用

  • 发送前检查字符数
  • 注意扩展 GSM 字符(按 2 个字符计算)
  • 批量发送前先用特殊字符进行测试
  • 较长的消息可考虑使用 GSM 编码

手机号码

  • 始终使用 E.164 格式:+380XXXXXXXXX
  • 发送前验证手机号码
  • 从列表中移除无效号码
  • 保持联系人列表为最新

发送时间

  • 尊重当地时区
  • 避免在夜间发送(晚上 10 点至早上 8 点)
  • 商业消息应考虑营业时间
  • 为时效性强的消息设置合适的 TTL

合规

  • 发送营销消息前获得同意
  • 在促销 SMS 中包含退订说明
  • 遵守当地法规(GDPR 等)
  • 尊重“请勿打扰”名单

错误处理

常见错误

错误原因解决方案
INVALID_RECIPIENT手机号码格式错误使用 E.164 格式
INVALID_SENDER发件人 ID 无效检查发件人 ID 规则
MESSAGE_TOO_LONG超出最大长度拆分或缩短消息
INVALID_ENCODING不支持的字符使用 GSM 或 Unicode

成本优化

减少消息段数

  • 将消息保持在 160 个字符(GSM)或 70 个字符(Unicode)以内
  • 避免使用会触发 Unicode 编码的特殊字符
  • 在适当时使用缩写
  • 删除不必要的空格

优化示例

❌ 优化前(171 个字符,2 条 SMS):

Hello John! Your order #12345 has been successfully delivered to your address at 123 Main Street. Thank you for shopping with us! We hope to see you again soon.

✅ 优化后(156 个字符,1 条 SMS):

Hi John! Order #12345 delivered to 123 Main St. Thanks for shopping with us! Visit example.com/order/12345 for details.

批量发送

在一次请求中发送多条消息:

{
  "messages": [
    {
      "from": "YourBrand",
      "to": "+380111111111",
      "type": "sms",
      "text": "Message 1"
    },
    {
      "from": "YourBrand",
      "to": "+380222222222",
      "type": "sms",
      "text": "Message 2"
    },
    {
      "from": "YourBrand",
      "to": "+380333333333",
      "type": "sms",
      "text": "Message 3"
    }
  ]
}

后续步骤