QueryUSMSTemplate
查询短信模版
接口说明
查询指定的短信模板信息,支持批量查询。
请求信息
- 获取公私钥:
ACCESSKEY_ID:ACCESSKEY_SECRET - 请求方法:
GET - 请求路径:
/api/v1/usms/USMSTemplate - Content-Type:
application/json
请求参数
Header参数
| 参数名 | 类型 | 必填 | 说明 | 示例值 |
|---|---|---|---|---|
| Content-Type | string | 是 | 请求内容类型 | "application/json" |
| Authorization | string | 是 | HTTP Basic认证信息 | "Basic $(echo -n 'accesskeyId:accesskeySecret' |
Query参数
| 参数名 | 类型 | 必填 | 说明 | 示例值 |
|---|---|---|---|---|
| id | string[] | 是 | 模板ID列表(通过query参数传递,可多个) | ["template_id_1", "template_id_2"] |
注意: 参数通过URL查询字符串传递,格式为 ?id=template_id_1&id=template_id_2
请求示例
- CURL
- Golang
- Java
- Python
- PHP
curl -X GET "https://api.uspeedo.com/api/v1/usms/USMSTemplate?id=template_id_1&id=template_id_2" \
-H "Content-Type: application/json" \
-H "Authorization: Basic $(echo -n 'YOUR_ACCESSKEY_ID:YOUR_ACCESSKEY_SECRET' | base64)"
package main
import (
"encoding/base64"
"fmt"
"io"
"net/http"
"net/url"
)
func main() {
baseURL := "https://api.uspeedo.com/api/v1/usms/USMSTemplate"
// 构建查询参数
params := url.Values{}
params.Add("id", "template_id_1")
params.Add("id", "template_id_2")
fullURL := baseURL + "?" + params.Encode()
// 创建请求
req, _ := http.NewRequest("GET", fullURL, nil)
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.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
public class QueryUSMSTemplate {
public static void main(String[] args) {
try {
String baseURL = "https://api.uspeedo.com/api/v1/usms/USMSTemplate";
String[] templateIds = {"template_id_1", "template_id_2"};
// 构建查询参数
StringBuilder queryParams = new StringBuilder();
for (String id : templateIds) {
if (queryParams.length() > 0) {
queryParams.append("&");
}
queryParams.append("id=").append(URLEncoder.encode(id, StandardCharsets.UTF_8));
}
String url = baseURL + "?" + queryParams.toString();
// 创建连接
URL apiUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection) apiUrl.openConnection();
conn.setRequestMethod("GET");
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);
// 读取响应
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 query_usms_template(template_ids):
base_url = "https://api.uspeedo.com/api/v1/usms/USMSTemplate"
# 构建查询参数
params = [("id", tid) for tid in template_ids]
# 设置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.get(base_url, params=params, headers=headers)
print(f"响应状态码: {response.status_code}")
print(f"响应内容: {response.text}")
return response.json() if response.status_code == 200 else None
if __name__ == "__main__":
template_ids = ["template_id_1", "template_id_2"]
query_usms_template(template_ids)
<?php
function queryUSMSTemplate($templateIds) {
$baseURL = "https://api.uspeedo.com/api/v1/usms/USMSTemplate";
// 构建查询参数
$queryParams = array();
foreach ($templateIds as $id) {
$queryParams[] = "id=" . urlencode($id);
}
$url = $baseURL . "?" . implode("&", $queryParams);
// 设置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_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);
}
$templateIds = array("template_id_1", "template_id_2");
queryUSMSTemplate($templateIds);
?>
响应格式
成功响应
{
"RetCode": 0,
"Message": "success",
"Data": [
{
"TemplateId": "template_id_1",
"TemplateName": "MyTemplate",
"Template": "您的验证码是{1}",
"Purpose": 1,
"Status": "approved",
"Remark": "用于用户登录验证"
},
{
"TemplateId": "template_id_2",
"TemplateName": "AnotherTemplate",
"Template": "您的订单{1}已发货",
"Purpose": 2,
"Status": "pending",
"Remark": "订单通知"
}
]
}
响应字段说明
| 字段名 | 类型 | 说明 |
|---|---|---|
| RetCode | int | 返回码,0表示成功 |
| Message | string | 返回消息 |
| Data | array | 模板信息列表,每个元素包含:TemplateId(模板ID)、TemplateName(模板名称)、Template(模板内容)、Purpose(用途)、Status(状态)、Remark(备注)等 |
失败响应
{
"RetCode": 215392,
"Message": "Invalid parameter [id]"
}
常见错误码
| 错误码 | 说明 |
|---|---|
| 0 | 成功 |
| 215392 | 参数错误 |
| 215396 | 模板不存在 |
| 215400 | 服务器错误 |