سرویس API پیامدهی
نمونه کد REST
REST API — معرفی
REST API هُما از HTTP ساده پشتیبانی میکند:
GET — پارامترها در QueryString
https://api.homais.com/services/messaging/sms/api/sendMessage/direct/?username=YOUR_API_TOKEN&password=&PortalCode=ZZZZ&mobile=09121234567&message=textMessage&ServerType=100
- POST: پارامترها در body (
application/x-www-form-urlencoded) OTP:
پاسخ موفق: عدد بزرگتر از ۱۰۰۰.
REST API — GET (QueryString)
پارامترها در URL — قابل فراخوانی مستقیم از مرورگر. توکن API در username؛ password خالی.
singleSMS — sendMessage/direct
JavaScript// JavaScript (Browser / Node 18+)
const q = new URLSearchParams({
username: 'YOUR_API_TOKEN',
password: '',
PortalCode: '12345',
mobile: '09121234567',
message: 'سلام، پیام تست',
ServerType: '100',
});
const res = await fetch('https://api.homais.com/services/messaging/sms/api/sendMessage/direct/?' + q);
const id = parseInt(await res.text(), 10);
console.log(id > 1000 ? 'OK:' + id : 'ERR:' + id);
Python# Python
import requests
r = requests.get('https://api.homais.com/services/messaging/sms/api/sendMessage/direct/', params={
'username': 'YOUR_API_TOKEN', 'password': '',
'PortalCode': 12345, 'mobile': '09121234567',
'message': 'سلام', 'ServerType': 100}, timeout=30)
print(r.text)
PHP<?php
$url = 'https://api.homais.com/services/messaging/sms/api/sendMessage/direct/?' . http_build_query([
'username' => 'YOUR_API_TOKEN', 'password' => '',
'PortalCode' => 12345, 'mobile' => '09121234567',
'message' => 'سلام', 'ServerType' => 100,
]);
echo file_get_contents($url);
cURLcurl -G "https://api.homais.com/services/messaging/sms/api/sendMessage/direct/" \
--data-urlencode "username=YOUR_API_TOKEN" \
--data-urlencode "password=" \
--data-urlencode "PortalCode=12345" \
--data-urlencode "mobile=09121234567" \
--data-urlencode "message=سلام" \
--data-urlencode "ServerType=100"
Gopackage main
import ("fmt"; "io"; "net/http"; "net/url")
func main() {
p := url.Values{}
p.Set("username", "YOUR_API_TOKEN")
p.Set("password", "")
p.Set("PortalCode", "12345")
p.Set("mobile", "09121234567")
p.Set("message", "سلام")
p.Set("ServerType", "100")
u := "https://api.homais.com/services/messaging/sms/api/sendMessage/direct/?" + p.Encode()
resp, _ := http.Get(u)
defer resp.Body.Close()
b, _ := io.ReadAll(resp.Body)
fmt.Println(string(b))
}
OTP — sendMessage/OTP
cURL — OTP GETcurl -G "https://api.homais.com/services/messaging/sms/api/sendMessage/OTP/" \
--data-urlencode "username=YOUR_API_TOKEN" \
--data-urlencode "password=" \
--data-urlencode "PortalCode=12345" \
--data-urlencode "mobile=09121234567" \
--data-urlencode "message=کد تایید شما" \
--data-urlencode "ServerType=100"
Rubyrequire 'net/http'
require 'uri'
uri = URI('https://api.homais.com/services/messaging/sms/api/sendMessage/direct/')
uri.query = URI.encode_www_form(
username: 'YOUR_API_TOKEN', password: '',
PortalCode: 12345, mobile: '09121234567',
message: 'سلام', ServerType: 100)
puts Net::HTTP.get(uri)
REST API — POST (Form Body)
همان endpoint؛ پارامترها در body — مناسب when URL طولانی است یا امنیت بیشتر.
singleSMS — POST form-urlencoded
JavaScript// JavaScript (fetch)
const body = new URLSearchParams({
username: 'YOUR_API_TOKEN', password: '',
PortalCode: '12345', mobile: '09121234567',
message: 'سلام', ServerType: '100',
});
const res = await fetch('https://api.homais.com/services/messaging/sms/api/sendMessage/direct/', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: body.toString(),
});
console.log(await res.text());
Python# Python
import requests
r = requests.post('https://api.homais.com/services/messaging/sms/api/sendMessage/direct/', data={
'username': 'YOUR_API_TOKEN', 'password': '',
'PortalCode': 12345, 'mobile': '09121234567',
'message': 'سلام', 'ServerType': 100,
}, timeout=30)
print(r.text)
PHP<?php
$ch = curl_init('https://api.homais.com/services/messaging/sms/api/sendMessage/direct/');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query([
'username' => 'YOUR_API_TOKEN', 'password' => '',
'PortalCode' => 12345, 'mobile' => '09121234567',
'message' => 'سلام', 'ServerType' => 100,
]),
CURLOPT_RETURNTRANSFER => true,
]);
echo curl_exec($ch);
curl_close($ch);
cURLcurl -X POST "https://api.homais.com/services/messaging/sms/api/sendMessage/direct/" \
-H "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "username=YOUR_API_TOKEN" \
--data-urlencode "password=" \
--data-urlencode "PortalCode=12345" \
--data-urlencode "mobile=09121234567" \
--data-urlencode "message=سلام" \
--data-urlencode "ServerType=100"
OTP — POST form-urlencoded
cURL — OTP POSTcurl -X POST "https://api.homais.com/services/messaging/sms/api/sendMessage/OTP/" \
-H "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "username=YOUR_API_TOKEN" \
--data-urlencode "password=" \
--data-urlencode "PortalCode=12345" \
--data-urlencode "mobile=09121234567" \
--data-urlencode "message=کد تایید" \
--data-urlencode "ServerType=100"
Node.js — axios// Node.js — axios
const axios = require('axios');
const { data } = await axios.post('https://api.homais.com/services/messaging/sms/api/sendMessage/direct/',
new URLSearchParams({
username: 'YOUR_API_TOKEN', password: '',
PortalCode: '12345', mobile: '09121234567',
message: 'سلام', ServerType: '100',
}), { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } });
console.log(data);
REST API — PowerShell & VB.NET
PowerShell — GET
PowerShell — GET$params = @{
username = 'YOUR_API_TOKEN'
password = ''
PortalCode = 12345
mobile = '09121234567'
message = 'سلام'
ServerType = 100
}
$uri = 'https://api.homais.com/services/messaging/sms/api/sendMessage/direct/' + '?' + ($params.GetEnumerator() | ForEach-Object {
"$($_.Key)=$([uri]::EscapeDataString([string]$_.Value))"
}) -join '&'
(Invoke-WebRequest -Uri $uri -UseBasicParsing).Content
PowerShell — POST
PowerShell — POST$body = @{
username='YOUR_API_TOKEN'; password=''
PortalCode=12345; mobile='09121234567'
message='سلام'; ServerType=100
}
Invoke-RestMethod -Method Post -Uri 'https://api.homais.com/services/messaging/sms/api/sendMessage/direct/' -Body $body
VB.NET — WebClient GET
VB.NETImports System.Net
Dim url = "https://api.homais.com/services/messaging/sms/api/sendMessage/direct/?username=YOUR_API_TOKEN&password=" &
"&PortalCode=12345&mobile=09121234567&message=سلام&ServerType=100"
Dim wc As New WebClient()
wc.Encoding = System.Text.Encoding.UTF8
Dim result = wc.DownloadString(url)
Console.WriteLine(result)
نکات
- برای اتصال نرمافزارهای حسابداری از بخش «اتصال سایر نرمافزارها» استفاده کنید: نام کاربری = توکن API، کد پرتال = پارامتر PortalCode.
- اتصال مستقیم فقط وقتی ممکن است که نرمافزار اجازه تعریف URL و پارامترهای دلخواه را بدهد؛ در غیر این صورت افزونه/واسط اختصاصی لازم است.
- ServerType=100 برای ارسال عمومی و OTP (لیست سیاه مخابرات) توصیه میشود.
- پاسخ موفق: عدد بزرگتر از ۱۰۰۰؛ هر عدد دیگر کد خطاست.
- برای پیام حاوی لینک یا ارسال از شماره عمومی، پروفایل WhoIS باید تکمیل و تأیید شده باشد.
- برای تست سریع REST API، URL را با پارامترها در مرورگر باز کنید.
- در صورت خطا، کد بازگشتی و ServerType را در تیکت پشتیبانی ذکر کنید.