API Integration Demo
Use our simple HTTP API to integrate SMS capabilities into your application.
PHP Example Code
<?php
// SMS One-to-One Sending Interface
$userName = 'lsgy'; // Account Username
$password = 'VWjFR'; // Account Password
$timestamp = time() * 1000; // Get current timestamp, precise to milliseconds
$messageList = [ // List of SMS content and phone numbers
[
'phone' => '15011111111',
'content' => '[Signature] SMS Content 1'
],
[
'phone' => '15022222222',
'content' => '[Signature] SMS Content 2'
]
];
// Calculate sign parameter value
$sign = md5($userName . $timestamp . md5($password));
// Define request data
$data = [
'userName' => $userName,
'messageList' => $messageList,
'timestamp' => $timestamp,
'sign' => $sign
];
// Define request options
$options = [
'http' => [
'header' => "Content-Type: application/json;charset=utf-8\r\nAccept: application/json\r\n",
'method' => 'POST',
'content' => json_encode($data)
]
];
// Send HTTP request
$context = stream_context_create($options);
$result = file_get_contents('https://sdksms.com/api/sendMessageOne', false, $context);
// Output response data
echo $result;
?>
Java Example Code
import java.io.*;
import java.net.*;
import java.security.MessageDigest;
import java.nio.charset.StandardCharsets;
public class SmsDemo {
public static void main(String[] args) {
try {
String userName = "lsgy";
String password = "VWjFR";
long timestamp = System.currentTimeMillis();
// Calculate Sign: md5(userName + timestamp + md5(password))
String sign = md5(userName + timestamp + md5(password));
// Construct JSON Payload (Manual construction for no-dependency demo)
String json = String.format(
"{\"userName\": \"%s\", \"timestamp\": %d, \"sign\": \"%s\", \"messageList\": [" +
"{\"phone\": \"15011111111\", \"content\": \"[Signature] SMS Content 1\"}," +
"{\"phone\": \"15022222222\", \"content\": \"[Signature] SMS Content 2\"}" +
"]}", userName, timestamp, sign);
URL url = new URL("https://sdksms.com/api/sendMessageOne");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json; charset=utf-8");
conn.setDoOutput(true);
try(OutputStream os = conn.getOutputStream()) {
byte[] input = json.getBytes(StandardCharsets.UTF_8);
os.write(input, 0, input.length);
}
try(BufferedReader br = new BufferedReader(
new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8))) {
StringBuilder response = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
response.append(line.trim());
}
System.out.println(response.toString());
}
} catch (Exception e) {
e.printStackTrace();
}
}
private static String md5(String s) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] digest = md.digest(s.getBytes());
StringBuilder sb = new StringBuilder();
for (byte b : digest) {
sb.append(String.format("%02x", b));
}
return sb.toString();
} catch (Exception e) { return ""; }
}
}
C# Example Code
using System;
using System.Net.Http;
using System.Text;
using System.Security.Cryptography;
using System.Threading.Tasks;
class SmsDemo
{
static async Task Main(string[] args)
{
string userName = "lsgy";
string password = "VWjFR";
long timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
// Calculate Sign
string sign = CalculateMD5(userName + timestamp + CalculateMD5(password));
string json = $@"{{
""userName"": ""{userName}"",
""timestamp"": {timestamp},
""sign"": ""{sign}"",
""messageList"": [
{{ ""phone"": ""15011111111"", ""content"": ""[Signature] SMS Content 1"" }},
{{ ""phone"": ""15022222222"", ""content"": ""[Signature] SMS Content 2"" }}
]
}}";
using (var client = new HttpClient())
{
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync("https://sdksms.com/api/sendMessageOne", content);
string result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);
}
}
static string CalculateMD5(string input)
{
using (MD5 md5 = MD5.Create())
{
byte[] inputBytes = Encoding.UTF8.GetBytes(input);
byte[] hashBytes = md5.ComputeHash(inputBytes);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hashBytes.Length; i++)
{
sb.Append(hashBytes[i].ToString("x2"));
}
return sb.ToString();
}
}
}
Python Example Code
# Python Example (Requires requests library)
import hashlib
import time
import json
import requests
def md5(s):
return hashlib.md5(s.encode('utf-8')).hexdigest()
userName = 'lsgy'
password = 'VWjFR'
timestamp = int(time.time() * 1000)
# Calculate Sign
sign = md5(userName + str(timestamp) + md5(password))
data = {
"userName": userName,
"timestamp": timestamp,
"sign": sign,
"messageList": [
{"phone": "15011111111", "content": "[Signature] SMS Content 1"},
{"phone": "15022222222", "content": "[Signature] SMS Content 2"}
]
}
url = "https://sdksms.com/api/sendMessageOne"
headers = {'Content-Type': 'application/json;charset=utf-8'}
try:
response = requests.post(url, json=data, headers=headers)
print(response.text)
except Exception as e:
print(e)
C++ Example Code
// C++ Example (Requires libcurl and openssl)
#include <iostream>
#include <string>
#include <curl/curl.h>
#include <openssl/md5.h>
#include <iomanip>
#include <sstream>
// Simple MD5 wrapper
std::string md5(const std::string& str) {
unsigned char hash[MD5_DIGEST_LENGTH];
MD5((unsigned char*)str.c_str(), str.size(), hash);
std::stringstream ss;
for(int i = 0; i < MD5_DIGEST_LENGTH; i++)
ss << std::hex << std::setw(2) << std::setfill('0') << (int)hash[i];
return ss.str();
}
int main() {
std::string userName = "lsgy";
std::string password = "VWjFR";
long long timestamp = 1672531200000; // Use actual timestamp
std::string sign = md5(userName + std::to_string(timestamp) + md5(password));
// Manual JSON construction
std::string json = "{"
"\"userName\": \"" + userName + "\","
"\"timestamp\": " + std::to_string(timestamp) + ","
"\"sign\": \"" + sign + "\","
"\"messageList\": ["
"{\"phone\": \"15011111111\", \"content\": \"[Signature] SMS Content 1\"},"
"{\"phone\": \"15022222222\", \"content\": \"[Signature] SMS Content 2\"}"
"]"
"}";
CURL* curl = curl_easy_init();
if(curl) {
struct curl_slist* headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json;charset=utf-8");
curl_easy_setopt(curl, CURLOPT_URL, "https://sdksms.com/api/sendMessageOne");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json.c_str());
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}