Overview
أرسل رموز تحقق لمرة واحدة باستخدام نفس نقاط النهاية التي تستخدمها لأي رسالة. أنشئ الرمز في نظامك الخلفي، وأرسله عبر POST /sms/sendSms (أو كنموذج مصادقة WhatsApp عبر POST /whatsapp/message/sendbulk)، ثم تحقق مما يُدخله المستخدم مقابل الرمز الذي خزّنته. للاطلاع على كيفية إنشاء الرمز والتحقق منه كخدمة مُدارة، راجع صفحة منتج OTP.
مثال
انسخ والصق واستبدل القيم النائبة — هذه الأمثلة تستدعي واجهة API لبيئة الإنتاج كما هي مكتوبة.
import { randomInt } from "node:crypto";
import { Configuration, SMSSMSApi } from "@broadnet/cpaas-sdk";
const sms = new SMSSMSApi(
new Configuration({
basePath: "https://api.broadnet.me",
accessToken: process.env.BROADNET_TOKEN!,
}),
);
// 1. Generate and store the code (hash it, with an expiry).
const code = String(randomInt(100000, 1000000));
await otpStore.save("447700900123", code, { ttlSeconds: 300 });
// 2. Send it as a normal SMS.
await sms.smsSendsmsPost({
sMSSmsRequest: {
senderId: "BroadNet",
destinationNumber: "447700900123",
message: `Your verification code is ${code}`,
messageType: "TEXT",
},
});
// 3. Later: compare the code the user typed with the stored one.