API 参考
短信 API
从已批准的发送方 ID 或号码发送单条消息或批量活动。在消息正文中加入 #OTP4# 或 #OTP6# 即可生成一次性密码。
基础 URL https://portal.par-infinity.com/api/v1 · 认证 · 错误 · 产品概览
发送短信
POST /sms/send
向全球任意号码发送短信。
请求体 application/json
| 名称 | 类型 | 说明 |
|---|---|---|
from 必填 |
string | 使用已批准的发送方 ID 或号码。
示例: 12345
|
to 必填 |
string |
示例: 123456789
|
message 必填 |
string | 使用 #OTP4# 和 #OTP6# 作为占位符来生成 OTP。
示例: This is a test message
|
bind_name 必填 |
string |
示例: bind1
|
pe_id |
string | 用于印度国内 DLT。
示例: 54342445353452
|
template_id |
string | 用于印度国内 DLT。
示例: 2372168395432
|
请求示例
cURL
curl -X POST 'https://portal.par-infinity.com/api/v1/sms/send/' \
-H 'Authorization: YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"from": "12345",
"to": "123456789",
"message": "This is a test message",
"bind_name": "bind1",
"pe_id": "54342445353452",
"template_id": "2372168395432"
}'
Python
import requests
url = "https://portal.par-infinity.com/api/v1/sms/send/"
headers = {"Authorization": "YOUR_API_KEY"}
payload = {
"from": "12345",
"to": "123456789",
"message": "This is a test message",
"bind_name": "bind1",
"pe_id": "54342445353452",
"template_id": "2372168395432"
}
response = requests.post(url, headers=headers, json=payload, timeout=30)
print(response.status_code, response.json())
Node.js
const res = await fetch("https://portal.par-infinity.com/api/v1/sms/send/", {
method: "POST",
headers: {
Authorization: process.env.PAR_API_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify({
"from": "12345",
"to": "123456789",
"message": "This is a test message",
"bind_name": "bind1",
"pe_id": "54342445353452",
"template_id": "2372168395432"
}),
});
console.log(res.status, await res.json());
PHP
<?php
$ch = curl_init('https://portal.par-infinity.com/api/v1/sms/send/');
$headers = ['Authorization: YOUR_API_KEY'];
$payload = <<<'JSON'
{
"from": "12345",
"to": "123456789",
"message": "This is a test message",
"bind_name": "bind1",
"pe_id": "54342445353452",
"template_id": "2372168395432"
}
JSON;
$headers[] = 'Content-Type: application/json';
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $payload,
CURLOPT_HTTPHEADER => $headers,
]);
$response = curl_exec($ch);
echo curl_getinfo($ch, CURLINFO_HTTP_CODE), ' ', $response, PHP_EOL;
curl_close($ch);
Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Example {
public static void main(String[] args) throws Exception {
String payload = """
{
"from": "12345",
"to": "123456789",
"message": "This is a test message",
"bind_name": "bind1",
"pe_id": "54342445353452",
"template_id": "2372168395432"
}
""";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://portal.par-infinity.com/api/v1/sms/send/"))
.header("Authorization", "YOUR_API_KEY")
.header("Content-Type", "application/json")
.method("POST", HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode() + " " + response.body());
}
}
Go
package main
import (
"fmt"
"io"
"net/http"
"strings"
)
func main() {
payload := `{
"from": "12345",
"to": "123456789",
"message": "This is a test message",
"bind_name": "bind1",
"pe_id": "54342445353452",
"template_id": "2372168395432"
}`
req, err := http.NewRequest("POST", "https://portal.par-infinity.com/api/v1/sms/send/", strings.NewReader(payload))
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "YOUR_API_KEY")
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
data, _ := io.ReadAll(res.Body)
fmt.Println(res.StatusCode, string(data))
}
Ruby
require 'net/http'
require 'uri'
uri = URI('https://portal.par-infinity.com/api/v1/sms/send/')
request = Net::HTTP::Post.new(uri)
request['Authorization'] = 'YOUR_API_KEY'
request['Content-Type'] = 'application/json'
request.body = <<~JSON
{
"from": "12345",
"to": "123456789",
"message": "This is a test message",
"bind_name": "bind1",
"pe_id": "54342445353452",
"template_id": "2372168395432"
}
JSON
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(request) }
puts response.code, response.body
C# (.NET)
using System.Net.Http.Headers;
using System.Text;
var client = new HttpClient();
var request = new HttpRequestMessage(new HttpMethod("POST"), "https://portal.par-infinity.com/api/v1/sms/send/");
request.Headers.TryAddWithoutValidation("Authorization", "YOUR_API_KEY");
var payload = """
{
"from": "12345",
"to": "123456789",
"message": "This is a test message",
"bind_name": "bind1",
"pe_id": "54342445353452",
"template_id": "2372168395432"
}
""";
request.Content = new StringContent(payload, Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");
响应示例 200
{
"status": "ok",
"message": "Message Sent",
"origination_message_id": "acba1293an"
}
错误
批量发送短信
POST /sms/send/batch
向多个号码发送短信。
请求体 application/json
| 名称 | 类型 | 说明 |
|---|---|---|
from 必填 |
string | 使用已批准的发送方 ID 或号码。
示例: 12345
|
phone_numbers 必填 |
array<string> |
示例: ['15551231241', '155512846124', '15551246192']
|
message 必填 |
string |
示例: This is a test message
|
bind_name 必填 |
string |
示例: bind1
|
campaign_name 必填 |
string |
示例: Test Campaign
|
pe_id |
string | 用于印度国内 DLT。
示例: 54342445353452
|
template_id |
string | 用于印度国内 DLT。
示例: 2372168395432
|
请求示例
cURL
curl -X POST 'https://portal.par-infinity.com/api/v1/sms/send/batch/' \
-H 'Authorization: YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"from": "12345",
"phone_numbers": [
"15551231241",
"155512846124",
"15551246192"
],
"message": "This is a test message",
"bind_name": "bind1",
"campaign_name": "Test Campaign",
"pe_id": "54342445353452",
"template_id": "2372168395432"
}'
Python
import requests
url = "https://portal.par-infinity.com/api/v1/sms/send/batch/"
headers = {"Authorization": "YOUR_API_KEY"}
payload = {
"from": "12345",
"phone_numbers": [
"15551231241",
"155512846124",
"15551246192"
],
"message": "This is a test message",
"bind_name": "bind1",
"campaign_name": "Test Campaign",
"pe_id": "54342445353452",
"template_id": "2372168395432"
}
response = requests.post(url, headers=headers, json=payload, timeout=30)
print(response.status_code, response.json())
Node.js
const res = await fetch("https://portal.par-infinity.com/api/v1/sms/send/batch/", {
method: "POST",
headers: {
Authorization: process.env.PAR_API_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify({
"from": "12345",
"phone_numbers": [
"15551231241",
"155512846124",
"15551246192"
],
"message": "This is a test message",
"bind_name": "bind1",
"campaign_name": "Test Campaign",
"pe_id": "54342445353452",
"template_id": "2372168395432"
}),
});
console.log(res.status, await res.json());
PHP
<?php
$ch = curl_init('https://portal.par-infinity.com/api/v1/sms/send/batch/');
$headers = ['Authorization: YOUR_API_KEY'];
$payload = <<<'JSON'
{
"from": "12345",
"phone_numbers": [
"15551231241",
"155512846124",
"15551246192"
],
"message": "This is a test message",
"bind_name": "bind1",
"campaign_name": "Test Campaign",
"pe_id": "54342445353452",
"template_id": "2372168395432"
}
JSON;
$headers[] = 'Content-Type: application/json';
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $payload,
CURLOPT_HTTPHEADER => $headers,
]);
$response = curl_exec($ch);
echo curl_getinfo($ch, CURLINFO_HTTP_CODE), ' ', $response, PHP_EOL;
curl_close($ch);
Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Example {
public static void main(String[] args) throws Exception {
String payload = """
{
"from": "12345",
"phone_numbers": [
"15551231241",
"155512846124",
"15551246192"
],
"message": "This is a test message",
"bind_name": "bind1",
"campaign_name": "Test Campaign",
"pe_id": "54342445353452",
"template_id": "2372168395432"
}
""";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://portal.par-infinity.com/api/v1/sms/send/batch/"))
.header("Authorization", "YOUR_API_KEY")
.header("Content-Type", "application/json")
.method("POST", HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode() + " " + response.body());
}
}
Go
package main
import (
"fmt"
"io"
"net/http"
"strings"
)
func main() {
payload := `{
"from": "12345",
"phone_numbers": [
"15551231241",
"155512846124",
"15551246192"
],
"message": "This is a test message",
"bind_name": "bind1",
"campaign_name": "Test Campaign",
"pe_id": "54342445353452",
"template_id": "2372168395432"
}`
req, err := http.NewRequest("POST", "https://portal.par-infinity.com/api/v1/sms/send/batch/", strings.NewReader(payload))
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "YOUR_API_KEY")
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
data, _ := io.ReadAll(res.Body)
fmt.Println(res.StatusCode, string(data))
}
Ruby
require 'net/http'
require 'uri'
uri = URI('https://portal.par-infinity.com/api/v1/sms/send/batch/')
request = Net::HTTP::Post.new(uri)
request['Authorization'] = 'YOUR_API_KEY'
request['Content-Type'] = 'application/json'
request.body = <<~JSON
{
"from": "12345",
"phone_numbers": [
"15551231241",
"155512846124",
"15551246192"
],
"message": "This is a test message",
"bind_name": "bind1",
"campaign_name": "Test Campaign",
"pe_id": "54342445353452",
"template_id": "2372168395432"
}
JSON
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(request) }
puts response.code, response.body
C# (.NET)
using System.Net.Http.Headers;
using System.Text;
var client = new HttpClient();
var request = new HttpRequestMessage(new HttpMethod("POST"), "https://portal.par-infinity.com/api/v1/sms/send/batch/");
request.Headers.TryAddWithoutValidation("Authorization", "YOUR_API_KEY");
var payload = """
{
"from": "12345",
"phone_numbers": [
"15551231241",
"155512846124",
"15551246192"
],
"message": "This is a test message",
"bind_name": "bind1",
"campaign_name": "Test Campaign",
"pe_id": "54342445353452",
"template_id": "2372168395432"
}
""";
request.Content = new StringContent(payload, Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");
响应示例 200
{
"status": "ok",
"message": "Message Sent"
}