UpdateUSMSTemplate
修改短信模版
接口说明
修改已存在的短信模板信息。
请求信息
- 获取公私钥:
ACCESSKEY_ID:ACCESSKEY_SECRET - 请求方法:
PUT - 请求路径:
/api/v1/usms/USMSTemplate/{id} - Content-Type:
application/json
请求参数
Header参数
| 参数名 | 类型 | 必填 | 说明 | 示例值 |
|---|---|---|---|---|
| Content-Type | string | 是 | 请求内容类型 | "application/json" |
| Authorization | string | 是 | HTTP Basic认证信息 | "Basic $(echo -n 'accesskeyId:accesskeySecret' |
Path参数
| 参数名 | 类型 | 必填 | 说明 | 示例值 |
|---|---|---|---|---|
| id | string | 是 | 模板ID | "template_id_1" |
Body参数
| 参数名 | 类型 | 必填 | 说明 | 示例值 |
|---|---|---|---|---|
| TemplateName | string | 否 | 模板名称 | "UpdatedTemplate" |
| Template | string | 否 | 模板内容 | "您的验证码是{1}" |
| Instruction | string | 否 | 使用说明 | - |
| Tags | []int | 否 | 标签列表 | [1, 2] |
| VariableAttr | string | 否 | 模板变量属性 | - |
请求示例
- CURL
- Golang
- Java
- Python
- PHP
curl -X PUT "https://api.uspeedo.com/api/v1/usms/USMSTemplate/template_id_1" \
-H "Content-Type: application/json" \
-H "Authorization: Basic $(echo -n 'YOUR_ACCESSKEY_ID:YOUR_ACCESSKEY_SECRET' | base64)" \
-d '{
"TemplateName": "UpdatedTemplate",
"Template": "您的验证码是{1},请勿泄露"
}'
package main
import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"net/http"
)
func main() {
templateId := "template_id_1"
url := fmt.Sprintf("https://api.uspeedo.com/api/v1/usms/USMSTemplate/%s", templateId)
// 准备请求体
requestBody := map[string]interface{}{
"TemplateName": "UpdatedTemplate",
"Template": "您的验证码是{1},请勿泄露",
}
jsonData, _ := json.Marshal(requestBody)
// 创建请求
req, _ := http.NewRequest("PUT", url, bytes.NewBuffer(jsonData))
req.Header.Set("Content-Type", "application/json")
// 设置HTTP Basic认证
accesskeyId := "YOUR_ACCESSKEY_ID"
accesskeySecret := "YOUR_ACCESSKEY_SECRET"
auth := base64.StdEncoding.EncodeToString([]byte(accesskeyId + ":" + accesskeySecret))
req.Header.Set("Authorization", "Basic "+auth)
// 发送请求
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Printf("请求失败: %v\n", err)
return
}
defer resp.Body.Close()
// 读取响应
body, _ := io.ReadAll(resp.Body)
fmt.Printf("响应状态码: %d\n", resp.StatusCode)
fmt.Printf("响应内容: %s\n", string(body))
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
public class UpdateUSMSTemplate {
public static void main(String[] args) {
try {
String templateId = "template_id_1";
String url = "https://api.uspeedo.com/api/v1/usms/USMSTemplate/" + templateId;
// 准备请求体
String jsonBody = "{\n" +
" \"TemplateName\": \"UpdatedTemplate\",\n" +
" \"Template\": \"您的验证码是{1},请勿泄露\"\n" +
"}";
// 创建连接
URL apiUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection) apiUrl.openConnection();
conn.setRequestMethod("PUT");
conn.setRequestProperty("Content-Type", "application/json");
// 设置HTTP Basic认证
String accesskeyId = "YOUR_ACCESSKEY_ID";
String accesskeySecret = "YOUR_ACCESSKEY_SECRET";
String auth = accesskeyId + ":" + accesskeySecret;
String encodedAuth = Base64.getEncoder().encodeToString(auth.getBytes(StandardCharsets.UTF_8));
conn.setRequestProperty("Authorization", "Basic " + encodedAuth);
// 发送请求体
conn.setDoOutput(true);
try (OutputStream os = conn.getOutputStream()) {
byte[] input = jsonBody.getBytes(StandardCharsets.UTF_8);
os.write(input, 0, input.length);
}
// 读取响应
int responseCode = conn.getResponseCode();
System.out.println("响应状态码: " + responseCode);
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println("响应内容: " + response.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
import requests
import base64
def update_usms_template(template_id, template_name=None, template_content=None):
url = f"https://api.uspeedo.com/api/v1/usms/USMSTemplate/{template_id}"
# 准备请求体
payload = {}
if template_name:
payload["TemplateName"] = template_name
if template_content:
payload["Template"] = template_content
# 设置HTTP Basic认证
accesskey_id = "YOUR_ACCESSKEY_ID"
accesskey_secret = "YOUR_ACCESSKEY_SECRET"
credentials = base64.b64encode(f"{accesskey_id}:{accesskey_secret}".encode()).decode()
headers = {
"Content-Type": "application/json",
"Authorization": f"Basic {credentials}"
}
# 发送请求
response = requests.put(url, json=payload, headers=headers)
print(f"响应状态码: {response.status_code}")
print(f"响应内容: {response.text}")
return response.json() if response.status_code == 200 else None
if __name__ == "__main__":
update_usms_template(
template_id="template_id_1",
template_name="UpdatedTemplate",
template_content="您的验证码是{1},请勿泄露"
)
<?php
function updateUSMSTemplate($templateId, $data) {
$url = "https://api.uspeedo.com/api/v1/usms/USMSTemplate/" . urlencode($templateId);
$jsonData = json_encode($data);
// 设置HTTP Basic认证
$accesskeyId = "YOUR_ACCESSKEY_ID";
$accesskeySecret = "YOUR_ACCESSKEY_SECRET";
$auth = base64_encode($accesskeyId . ":" . $accesskeySecret);
// 初始化cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Authorization: Basic " . $auth
));
// 执行请求
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo "响应状态码: " . $httpCode . "\n";
echo "响应内容: " . $response . "\n";
return json_decode($response, true);
}
$data = array(
"TemplateName" => "UpdatedTemplate",
"Template" => "您的验证码是{1},请勿泄露"
);
updateUSMSTemplate("template_id_1", $data);
?>
响应格式
成功响应
{
"RetCode": 0,
"Message": "success"
}
响应字段说明
| 字段名 | 类型 | 说明 |
|---|---|---|
| RetCode | int | 返回码,0表示成功 |
| Message | string | 返回消息 |
失败响应
{
"RetCode": 215392,
"Message": "Invalid parameter [TemplateId]"
}
常见错误码
| 错误码 | 说明 |
|---|---|
| 0 | 成功 |
| 215392 | 参数错误 |
| 215396 | 模板不存在 |
| 215400 | 服务器错误 |