宝付短信渠道接口
本文档描述平台短信发送所使用的宝付(Mandao)短信网关接口规范,供后端通知服务(Celery Worker)集成使用。
环境地址
| 环境 |
接口地址 |
说明 |
| 测试环境 |
http://10.254.90.70:8000/sendSms |
内网访问,仅开发调试使用 |
| 准生产环境 |
https://qas-sms.mandao.com/sendSms |
上线前回归测试 |
| 生产环境 |
https://sms.mandao.com/sendSms |
需开通网络访问权限,正式上线使用 |
注意: 生产环境需在宝付侧开通服务器出口 IP 白名单,部署前需提前申请。
请求规范
- 请求方式:
POST - Content-Type:
multipart/form-data
请求参数
| 参数名 |
类型 |
必填 |
说明 |
userName |
string |
是 |
账号,固定值(见配置) |
userPass |
string |
是 |
密码,固定值(见配置) |
mobile |
string |
是 |
手机号,多个号码用英文逗号 , 或分号 ; 分隔 |
content |
string |
是 |
短信内容 |
domain |
string |
否 |
应用标识,建议填写应用名称;不填默认为测试 |
singCode |
string |
否 |
签名编码 |
regTime |
string |
否 |
请求时间 |
sendType |
int |
否 |
发送类型,默认为 3(见枚举说明) |
sms_business |
string |
否 |
短信业务名称 |
memberId |
string |
否 |
商户号 |
businessType |
int |
否 |
系统业务类型(见枚举说明) |
areaCode |
string |
否 |
地区码,境外手机必填 |
senderId |
string |
否 |
发件人 |
requestId |
string |
否 |
请求流水号,用于幂等控制和问题排查,建议填写 |
sendType 枚举
| 值 |
说明 |
1 |
注册发短信验证码 |
2 |
注册成功发送短信 |
3 |
直接发送短信内容(默认) |
businessType 枚举
| 值 |
说明 |
1 |
签约发送短信 |
2 |
支付成功通知 |
3 |
预支付发送短信 |
4 |
普通业务通知 |
响应参数
| 字段 |
类型 |
说明 |
success |
bool |
请求是否成功 |
result |
int |
发送结果,> 0 表示发送成功 |
errorCode |
string|null |
错误码,成功时为 null |
errorMsg |
string|null |
错误描述,成功时为 null |
判断标准: success == true 且 result > 0 为短信发送成功。
成功响应示例:
{
"success": true,
"result": 1,
"errorCode": null,
"errorMsg": null
}
失败响应示例:
{
"success": false,
"result": 0,
"errorCode": "SMS_001",
"errorMsg": "手机号格式不正确"
}
请求示例
Python(Celery Worker 集成)
import httpx
import uuid
from app.config import settings
async def send_sms(mobile: str, content: str, business_type: int = 4) -> bool:
"""
发送短信
:param mobile: 手机号,多个用逗号分隔
:param content: 短信内容
:param business_type: 业务类型,默认 4(普通业务通知)
:return: 是否发送成功
"""
payload = {
"userName": settings.BAOFOO_SMS_USERNAME,
"userPass": settings.BAOFOO_SMS_PASSWORD,
"mobile": mobile,
"content": content,
"domain": settings.APP_NAME,
"sendType": "3",
"businessType": str(business_type),
"requestId": str(uuid.uuid4()),
}
async with httpx.AsyncClient(timeout=10.0) as client:
response = await client.post(settings.BAOFOO_SMS_URL, data=payload)
result = response.json()
success = result.get("success") is True and (result.get("result") or 0) > 0
if not success:
logger.error(
"宝付短信发送失败",
mobile=mobile,
error_code=result.get("errorCode"),
error_msg=result.get("errorMsg"),
)
return success
配置项(存入 KMS / 环境变量)
| 配置键 |
说明 |
BAOFOO_SMS_USERNAME |
账号(userName) |
BAOFOO_SMS_PASSWORD |
密码(userPass) |
BAOFOO_SMS_URL |
当前环境接口地址 |
APP_NAME |
应用名称,作为 domain 字段值 |
平台短信场景映射
| 场景 |
sendType |
businessType |
content 模板 |
| 登录验证码 |
1 |
4 |
您的登录验证码为 {code},30分钟内有效,请勿泄露。 |
| 注册验证码 |
1 |
4 |
您的注册验证码为 {code},30分钟内有效,请勿泄露。 |
| 找回密码 |
3 |
4 |
您的重置密码验证码为 {code},30分钟内有效。 |
| 充值成功 |
3 |
2 |
您已成功充值 {amount} 元,当前余额 {balance} 元。 |
| 余额不足 |
3 |
4 |
您的账户余额仅剩 {balance} 元,请及时充值以免影响使用。 |
| 会员到期提醒 |
3 |
4 |
您的{plan}会员将于 {date} 到期,请及时续费。 |
注意事项
- 生产环境 IP 白名单: 部署前需将服务器出口 IP 提交给宝付侧开通,否则生产环境请求会被拦截。
- requestId 幂等: 建议每次请求生成唯一 UUID 作为
requestId,便于宝付侧排查问题。 - 凭证安全:
userName 和 userPass 禁止明文写入代码或 Git,统一存入 KMS,参见 00d-preparation-checklist.md。 - 发送频率: 同一手机号短信发送需在业务层做频率限制(如 60 秒 1 次),避免触发运营商拦截。
- 境外手机号: 发送境外号码时需填写
areaCode(如中国大陆 +86、香港 +852)。