提供对外短信发送功能,支持模板短信发送、状态查询等服务
| 参数名 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| action | string | 必填 | 操作类型,值为 send_sms 或 send |
| username | string | 必填 | 平台用户名,与API密钥配对使用 |
| api_key | string | 必填 | API密钥,在用户中心获取 |
| phone_number | string | 必填 | 接收短信的手机号码,格式为11位数字,如:13800138000 |
| template_code | string | 必填 | 短信模板ID,可通过获取模板列表接口获取 |
| template_params | array | 选填 | 模板参数,根据模板内容提供相应参数,JSON格式 |
| sign_name | string | 选填 | 短信签名,如不提供则使用默认签名 |
// GET 请求示例
api/sms_api.php?action=send_sms&username=your_username&api_key=your_api_key&phone_number=13800138000&template_code=SMS_123456789&template_params={"code":"123456"}
// POST 请求示例 (application/x-www-form-urlencoded)
action=send_sms
username=your_username
api_key=your_api_key
phone_number=13800138000
template_code=SMS_123456789
template_params={"code":"123456"}
// JSON 请求示例 (application/json)
{
"action": "send_sms",
"username": "your_username",
"api_key": "your_api_key",
"phone_number": "13800138000",
"template_code": "SMS_123456789",
"template_params": {
"code": "123456"
},
"sign_name": "测试签名"
}
{
"code": 0,
"message": "success",
"data": {
"phone_number": "13800138000",
"biz_id": "1234567890123456789",
"send_time": "2023-07-15 10:30:45",
"remaining_credits": 99
}
}
| 参数名 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| action | string | 必填 | 操作类型,值为 get_templates |
| username | string | 必填 | 平台用户名,与API密钥配对使用 |
| api_key | string | 必填 | API密钥,在用户中心获取 |
// GET 请求示例
api/sms_api.php?action=get_templates&username=your_username&api_key=your_api_key
// POST 请求示例
{
"action": "get_templates",
"username": "your_username",
"api_key": "your_api_key"
}
{
"code": 0,
"message": "success",
"data": [
{
"template_code": "SMS_123456789",
"template_name": "验证码短信",
"template_content": "您的验证码为${code},有效期5分钟,请勿泄露给他人。",
"status": "审核通过"
},
{
"template_code": "SMS_987654321",
"template_name": "通知短信",
"template_content": "尊敬的用户,您的订单${order_id}已发货,请注意查收。",
"status": "审核通过"
}
]
}
| 参数名 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| action | string | 必填 | 操作类型,值为 get_credits 或 check_credits |
| username | string | 必填 | 平台用户名,与API密钥配对使用 |
| api_key | string | 必填 | API密钥,在用户中心获取 |
| api_type | string | 选填 | API类型,默认为 'sms' |
// GET 请求示例
api/sms_api.php?action=get_credits&username=your_username&api_key=your_api_key&api_type=sms
// POST 请求示例
{
"action": "check_credits",
"username": "your_username",
"api_key": "your_api_key",
"api_type": "sms"
}
{
"code": 0,
"message": "success",
"data": {
"api_type": "sms",
"api_type_name": "短信API",
"total": 100,
"used": 1,
"remaining": 99,
"percentage_used": 1.0
}
}
| 参数名 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| action | string | 必填 | 操作类型,值为 get_status 或 get_logs |
| username | string | 必填 | 平台用户名,与API密钥配对使用 |
| api_key | string | 必填 | API密钥,在用户中心获取 |
| biz_id | string | 选填 | 短信发送流水号,与phone_number、start_date至少提供一个 |
| phone_number | string | 选填 | 接收短信的手机号码,与biz_id、start_date至少提供一个 |
| start_date | string | 选填 | 开始日期,格式为 YYYY-MM-DD,与biz_id、phone_number至少提供一个 |
| end_date | string | 选填 | 结束日期,格式为 YYYY-MM-DD |
// 根据手机号查询 api/sms_api.php?action=get_status&username=your_username&api_key=your_api_key&phone_number=13800138000 // 根据日期范围查询 api/sms_api.php?action=get_logs&username=your_username&api_key=your_api_key&start_date=2023-07-01&end_date=2023-07-31 // 根据biz_id查询 api/sms_api.php?action=get_status&username=your_username&api_key=your_api_key&biz_id=1234567890123456789
{
"code": 0,
"message": "success",
"data": [
{
"phone_number": "13800138000",
"template_code": "SMS_123456789",
"template_params": {
"code": "123456"
},
"sign_name": "测试签名",
"biz_id": "1234567890123456789",
"success": true,
"created_at": "2023-07-15 10:30:45",
"error_message": ""
},
{
"phone_number": "13800138000",
"template_code": "SMS_123456789",
"template_params": {
"code": "654321"
},
"sign_name": "测试签名",
"biz_id": "9876543210987654321",
"success": true,
"created_at": "2023-07-15 09:15:30",
"error_message": ""
}
]
}
| 错误码 | 描述 |
|---|---|
| 0 | 成功 |
| 1001 | 缺少必要参数 |
| 1002 | 参数验证失败 |
| 1003 | 用户名或API密钥无效 |
| 1004 | 权限不足或API调用次数不足 |
| 1005 | 短信发送失败 |
| 1006 | 短信服务未启用 |
| 1007 | 指定的短信模板不存在 |
| 5000 | 系统内部错误 |