Test ortamında OTPMOCK_URL=https://api.otpmock.com tanımlayın, Sinch istemcisini bu adrese yönlendirin ve Sinch kimlik bilgisi olarak otpmock API anahtarınızı kullanın. Uygulama kodunuz değişmez; canlı ortam Sinch ile göndermeye devam eder.
Kurulum
SDK'nın belgelenmiş smsHostname ve verificationHostname seçenekleri var.
import { SinchClient } from "@sinch/sdk-core";
export const sinch = new SinchClient({
servicePlanId: process.env.SINCH_SERVICE_PLAN_ID,
apiToken: process.env.SINCH_API_TOKEN, // testte: otpmock API anahtarı
applicationKey: process.env.SINCH_APPLICATION_KEY, // testte: otpmock API anahtarı (Verification)
applicationSecret: process.env.SINCH_APPLICATION_SECRET,
...(process.env.OTPMOCK_URL && { smsHostname: process.env.OTPMOCK_URL, verificationHostname: process.env.OTPMOCK_URL }),
});import os
from sinch import SinchClient
sinch = SinchClient(
service_plan_id=os.environ["SINCH_SERVICE_PLAN_ID"],
sms_api_token=os.environ["SINCH_API_TOKEN"], # testte: otpmock API anahtarı
sms_region="us",
)
if os.environ.get("OTPMOCK_URL"):
sinch.configuration.sms_domain_with_service_plan_id = os.environ["OTPMOCK_URL"]
# Verification API (HTTP): Application auth, key = testte: otpmock API anahtarı
VERIFY_URL = os.environ.get("OTPMOCK_URL", "https://verification.api.sinch.com")
VERIFY_AUTH = {"Authorization": f"Application {os.environ['SINCH_APP_KEY']}:{os.environ['SINCH_APP_SECRET']}"}
# POST {VERIFY_URL}/verification/v1/verifications, PUT ./id/{id} {"method": "sms", "sms": {"code": ...}}import com.sinch.sdk.SinchClient;
import com.sinch.sdk.models.*;
String otpmock = System.getenv("OTPMOCK_URL");
Configuration.Builder config = Configuration.builder()
.setSmsServicePlanId(System.getenv("SINCH_SERVICE_PLAN_ID"))
.setSmsApiToken(System.getenv("SINCH_API_TOKEN")) // testte: otpmock API anahtarı
.setApplicationKey(System.getenv("SINCH_APPLICATION_KEY")) // Verification: testte: otpmock API anahtarı
.setApplicationSecret(System.getenv("SINCH_APPLICATION_SECRET"));
if (otpmock != null) {
config.setSmsContext(SmsContext.builder().setSmsUrl(otpmock).setSmsRegion(SMSRegion.US).build());
config.setVerificationContext(VerificationContext.builder().setVerificationUrl(otpmock).build());
}
SinchClient sinch = new SinchClient(config.build());using Sinch;
using Sinch.SMS;
var otpmock = Environment.GetEnvironmentVariable("OTPMOCK_URL");
var sinch = new SinchClient(default, default, default, options =>
{
options.UseServicePlanIdWithSms(
Environment.GetEnvironmentVariable("SINCH_SERVICE_PLAN_ID"),
Environment.GetEnvironmentVariable("SINCH_API_TOKEN"), // testte: otpmock API anahtarı
SmsServicePlanIdRegion.Us);
if (otpmock is not null) options.ApiUrlOverrides = new ApiUrlOverrides { SmsUrl = otpmock };
});
// Verification over HTTPS (application key = testte: otpmock API anahtarı; signature isn't checked):
var verifyHttp = new HttpClient { BaseAddress = new Uri(otpmock ?? "https://verification.api.sinch.com") };
verifyHttp.DefaultRequestHeaders.Authorization = new("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes(
$"{Environment.GetEnvironmentVariable("SINCH_APPLICATION_KEY")}:{Environment.GetEnvironmentVariable("SINCH_APPLICATION_SECRET")}")));
// POST /verification/v1/verifications { identity = { type = "number", endpoint }, method = "sms" } -> id
// PUT /verification/v1/verifications/id/{id} { method = "sms", sms = { code } } -> status "SUCCESSFUL"use GuzzleHttp\Client;
$sinchUrl = getenv('OTPMOCK_URL') ?: 'https://us.sms.api.sinch.com';
$planId = getenv('SINCH_SERVICE_PLAN_ID');
(new Client())->post("$sinchUrl/xms/v1/$planId/batches", [
'headers' => ['Authorization' => 'Bearer ' . getenv('SINCH_API_TOKEN')], // testte: otpmock API anahtarı
'json' => ['from' => '12345', 'to' => ['+15550142'], 'body' => "Your code is $code"],
]);
// Verification API: application key/secret auth.
$verifyUrl = getenv('OTPMOCK_URL') ?: 'https://verification.api.sinch.com';
$appAuth = ['Authorization' => 'Application ' . getenv('SINCH_APPLICATION_KEY') . ':' . $signature]; // key = testte: otpmock API anahtarı
(new Client())->post("$verifyUrl/verification/v1/verifications", [
'headers' => $appAuth,
'json' => ['identity' => ['type' => 'number', 'endpoint' => '+15550142'], 'method' => 'sms'],
]);require "net/http"
require "json"
# Sinch has no official Ruby SDK; apps call the REST API, so only the host changes.
SINCH_URL = ENV.fetch("OTPMOCK_URL", "https://us.sms.api.sinch.com")
res = Net::HTTP.post(
URI("#{SINCH_URL}/xms/v1/#{ENV["SINCH_SERVICE_PLAN_ID"]}/batches"),
{ to: ["+15550142"], from: "12345", body: "Your code: #{code}" }.to_json,
"Content-Type" => "application/json",
"Authorization" => "Bearer #{ENV["SINCH_API_TOKEN"]}" # testte: otpmock API anahtarı
)// Sinch has no official Go SDK; call its HTTP API with net/http, only the host changes.
base := os.Getenv("OTPMOCK_URL")
if base == "" {
base = "https://us.sms.api.sinch.com"
}
body, _ := json.Marshal(map[string]any{"to": []string{"+15550142"}, "from": os.Getenv("SINCH_NUMBER"), "body": msg})
req, _ := http.NewRequest("POST", base+"/xms/v1/"+os.Getenv("SINCH_SERVICE_PLAN_ID")+"/batches", bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+os.Getenv("SINCH_API_TOKEN")) // testte: otpmock API anahtarı
res, err := http.DefaultClient.Do(req)
// Verification: POST {base}/verification/v1/verifications, then PUT .../verifications/id/{id}.
// Production host is https://verification.api.sinch.com. Basic auth with the application key and secret:
req.SetBasicAuth(os.Getenv("SINCH_APPLICATION_KEY"), os.Getenv("SINCH_APPLICATION_SECRET")) // key = otpmock key in testsHer dil, CI'da sağlayıcının resmi SDK'sıyla (ya da başka bir adrese yönlendirilemeyen SDK'larda düz HTTP API'siyle) otpmock'a karşı sınanır.
Kimlik bilgisi. Test ortamında Sinch API belirtecinizi (servicePlanId ile kullanılan) otpmock API anahtarınıza çevirin. Verification API için uygulama anahtarını otpmock API anahtarınıza çevirin; SDK istekleri uygulama gizli anahtarınızla imzalar, otpmock imzayı denetlemez.
otpmock neyi taklit ediyor?
| Uç nokta | Ne yapar |
|---|---|
POST /xms/v1/{service_plan_id}/batches | Bir SMS grubu (batch) gönderir (mt_text) |
POST /verification/v1/verifications | Verification: SMS doğrulaması başlatır (otpmock 4 haneli kod üretir) |
PUT /verification/v1/verifications/id/{id} | Verification: kodu kimlikle bildirir (200, durum SUCCESSFUL ya da FAIL) |
PUT /verification/v1/verifications/number/{number} | Verification: kodu telefon numarasıyla bildirir |
GET /verification/v1/verifications/id/{id} | Verification: durum |
Yanıtlar ve hatalar Sinch API'sinin kendi biçimindedir, bu yüzden istemci kütüphanesi onları her zamanki gibi çözümler. Yanlış anahtar ve aylık hakkın dolması da aynı hata biçimiyle döner.
Telefon numaraları
E.164 biçiminde ya da + olmadan gönderin; ikisi de aynı gelen kutusuna düşer.
Testinizde kodu okuyun
const telefon = otp.randomPhone(); // her test için ayrı numara
const since = Date.now() - 5_000;
await page.getByRole("button", { name: "Kod gönder" }).click(); // uygulamanız Sinch API'sini çağırır
const { code } = await otp.waitForCode(telefon, { since });otp yardımcısı bağımlılığı olmayan tek bir dosyadır: dokümandan alın (İngilizce). Baştan sona örnekler: Playwright ve Cypress rehberleri (İngilizce).
Bilmeniz gerekenler
- Yalnızca servis planı kimliği ve API belirteci kimlik doğrulama modu taklit edilir; OAuth (proje kimliği / anahtar) modu edilmez.
Sık sorulanlar
otpmock Sinch üzerinden gerçek SMS gönderiyor mu?
Hayır. Test ortamında uygulamanızın Sinch istekleri otpmock'a gider; mesaj 10 dakika saklanır ve Sinch ya da herhangi bir operatör ağına hiç ulaşmaz. Canlı ortamınız Sinch kullanmaya devam eder, çünkü otpmock yalnızca OTPMOCK_URL tanımlıyken devreye girer.
Resmi @sinch/sdk-core SDK'sı destekleniyor mu?
Evet. Sinch uç noktaları, resmi @sinch/sdk-core paketiyle Node.js'te uçtan uca sınanır. Adres değiştirmeye izin veren başka dillerdeki istemciler de çalışır.
otpmock hangi Sinch API'lerini destekliyor?
POST /xms/v1/{service_plan_id}/batches (Bir SMS grubu (batch) gönderir (mt_text)); POST /verification/v1/verifications (Verification: SMS doğrulaması başlatır (otpmock 4 haneli kod üretir)); PUT /verification/v1/verifications/id/{id} (Verification: kodu kimlikle bildirir (200, durum SUCCESSFUL ya da FAIL)); PUT /verification/v1/verifications/number/{number} (Verification: kodu telefon numarasıyla bildirir); GET /verification/v1/verifications/id/{id} (Verification: durum).
Ücretsiz plan ayda 300 mesaj içerir, kart gerekmez. Yapay zeka kodlama asistanı mı kullanıyorsunuz? otpmock.com/llms-full.txt adresini verin.
Ücretsiz API anahtarı al