19 lines
787 B
Python
19 lines
787 B
Python
from abc import ABC, abstractmethod
|
|
from dataclasses import dataclass
|
|
from urllib.parse import urlparse
|
|
from django.conf import settings
|
|
@dataclass(frozen=True, slots=True)
|
|
class SMSResult:
|
|
success: bool
|
|
provider_id: str = ""
|
|
error: str = ""
|
|
def webotp_message(code):
|
|
host=settings.WEBOTP_HOST or urlparse(settings.PUBLIC_BASE_URL).hostname
|
|
if not host: raise ValueError("WEBOTP_HOST یا PUBLIC_BASE_URL معتبر تنظیم نشده است.")
|
|
return f"کد شما: {code}\n@{host} #{code}"
|
|
class SMSProvider(ABC):
|
|
"""Stable application-facing contract for every SMS vendor."""
|
|
def send_otp(self,mobile,code): return self.send_message(mobile,webotp_message(code))
|
|
@abstractmethod
|
|
def send_message(self,mobile,message): raise NotImplementedError
|