Test ortamında OTPMOCK_URL=https://api.otpmock.com tanımlayın, Infobip istemcisini bu adrese yönlendirin ve Infobip kimlik bilgisi olarak otpmock API anahtarınızı kullanın. Uygulama kodunuz değişmez; canlı ortam Infobip ile göndermeye devam eder.
Kurulum
Infobip her hesaba ayrı bir temel adres verir, bu yüzden baseUrl zaten zorunlu bir seçenek.
import { Infobip, AuthType } from "@infobip-api/sdk";
export const infobip = new Infobip({
baseUrl: process.env.OTPMOCK_URL ?? process.env.INFOBIP_BASE_URL,
apiKey: process.env.INFOBIP_API_KEY, // testte: otpmock API anahtarı
authType: AuthType.ApiKey,
});import os
from infobip_api_client.api.sms_api import SmsApi
from infobip_api_client.api_client import ApiClient, Configuration
config = Configuration(
host=os.environ.get("OTPMOCK_URL") or os.environ["INFOBIP_BASE_URL"],
api_key=os.environ["INFOBIP_API_KEY"], # testte: otpmock API anahtarı
)
sms = SmsApi(ApiClient(config))import com.infobip.*;
import com.infobip.api.SmsApi;
String base = System.getenv().getOrDefault("OTPMOCK_URL", System.getenv("INFOBIP_BASE_URL"));
ApiClient client = ApiClient.forApiKey(ApiKey.from(System.getenv("INFOBIP_API_KEY"))) // testte: otpmock API anahtarı
.withBaseUrl(BaseUrl.from(base))
.build();
SmsApi sms = new SmsApi(client);using Infobip.Api.Client.Api;
using Infobip.Api.Client.Client;
var baseUrl = Environment.GetEnvironmentVariable("OTPMOCK_URL")
?? Environment.GetEnvironmentVariable("INFOBIP_BASE_URL");
var config = new Configuration(
Environment.GetEnvironmentVariable("INFOBIP_API_KEY"), // testte: otpmock API anahtarı
new Uri(baseUrl));
var sms = new SmsApi(config);use Infobip\Api\SmsApi;
use Infobip\Configuration;
$config = new Configuration(
host: getenv('OTPMOCK_URL') ?: getenv('INFOBIP_BASE_URL'),
apiKey: getenv('INFOBIP_API_KEY'), // testte: otpmock API anahtarı
);
$sms = new SmsApi(config: $config);require "net/http"
require "json"
# Infobip has no official Ruby SDK; apps call the REST API, so only the host changes.
INFOBIP_URL = ENV["OTPMOCK_URL"] || ENV["INFOBIP_BASE_URL"]
res = Net::HTTP.post(
URI("#{INFOBIP_URL}/sms/2/text/advanced"),
{ messages: [{ from: "InfoSMS", destinations: [{ to: "15550142" }], text: "Your PIN is #{code}" }] }.to_json,
"Content-Type" => "application/json",
"Authorization" => "App #{ENV["INFOBIP_API_KEY"]}" # testte: otpmock API anahtarı
)cfg := infobip.NewConfiguration()
cfg.Host = os.Getenv("INFOBIP_BASE_URL")
if base := os.Getenv("OTPMOCK_URL"); base != "" {
cfg.Host = base
}
client := api.NewAPIClient(cfg)
auth := context.WithValue(ctx, infobip.ContextAPIKeys, map[string]infobip.APIKey{
"APIKeyHeader": {Key: os.Getenv("INFOBIP_API_KEY")}, // testte: otpmock API anahtarı
})Her 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 Infobip API anahtarı değişkeninizi otpmock API anahtarınıza çevirin. App, Basic ve Bearer yetkilendirmesi kabul edilir.
otpmock neyi taklit ediyor?
| Uç nokta | Ne yapar |
|---|---|
POST /sms/2/text/advanced | SMS gönderir (v2); Node.js SDK'sı bunu kullanır |
POST /sms/3/messages | SMS gönderir (v3) |
POST /2fa/2/applications | 2FA: uygulama oluşturur (pinAttempts dikkate alınır, varsayılan 10) |
POST /2fa/2/applications/{appId}/messages | 2FA: mesaj şablonu oluşturur ({{pin}}, pinLength, yer tutucular) |
POST /2fa/2/pin | 2FA: SMS ile PIN gönderir (otpmock üretir) |
POST /2fa/2/pin/{pinId}/resend | 2FA: aynı PIN'i yeniden gönderir |
POST /2fa/2/pin/{pinId}/verify | 2FA: doğrular (verified, attemptsRemaining, pinError WRONG_PIN / NO_MORE_PIN_ATTEMPTS ile 200) |
Yanıtlar ve hatalar Infobip 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ı
Infobip numaraları başında + olmadan gönderir. otpmock bunları E.164 biçiminde saklar.
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 Infobip 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
- 2FA uygulamaları ve şablonları saklanmaz: ayarları dönen
applicationIdvemessageIdiçine kodlanır. Bu yüzden onları test hazırlığında bir kez (ya da her koşuda) oluşturup kimlikleri yeniden kullanın. Gerçek Infobip hesabınızın kimlikleri otpmock'ta çalışmaz. - SDK 2FA'yı
infobip.service.twoFAolarak sunar (createApplication,createMessageTemplate,sendPINCodeSMS,verifyPhoneNumber).
Sık sorulanlar
otpmock Infobip üzerinden gerçek SMS gönderiyor mu?
Hayır. Test ortamında uygulamanızın Infobip istekleri otpmock'a gider; mesaj 10 dakika saklanır ve Infobip ya da herhangi bir operatör ağına hiç ulaşmaz. Canlı ortamınız Infobip kullanmaya devam eder, çünkü otpmock yalnızca OTPMOCK_URL tanımlıyken devreye girer.
Resmi @infobip-api/sdk SDK'sı destekleniyor mu?
Evet. Infobip uç noktaları, resmi @infobip-api/sdk 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 Infobip API'lerini destekliyor?
POST /sms/2/text/advanced (SMS gönderir (v2); Node.js SDK'sı bunu kullanır); POST /sms/3/messages (SMS gönderir (v3)); POST /2fa/2/applications (2FA: uygulama oluşturur (pinAttempts dikkate alınır, varsayılan 10)); POST /2fa/2/applications/{appId}/messages (2FA: mesaj şablonu oluşturur ({{pin}}, pinLength, yer tutucular)); POST /2fa/2/pin (2FA: SMS ile PIN gönderir (otpmock üretir)); POST /2fa/2/pin/{pinId}/resend (2FA: aynı PIN'i yeniden gönderir); POST /2fa/2/pin/{pinId}/verify (2FA: doğrular (verified, attemptsRemaining, pinError WRONG_PIN / NO_MORE_PIN_ATTEMPTS ile 200)).
Ü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