sms_api.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import requests
  2. from tools.log import logger
  3. class SMS_Client:
  4. def __init__(self, api_key, country_code):
  5. self.api_key = api_key
  6. self.country_code = country_code
  7. def get_phone_number(self):
  8. try:
  9. url = 'https://sms-activate.org/stubs/handler_api.php'
  10. data = {
  11. 'api_key': self.api_key,
  12. 'action': 'getNumberV2',
  13. 'service': 'fb',
  14. 'forward': 'false',
  15. 'operator': 'any',
  16. 'country': self.country_code,
  17. 'verification': 'false'
  18. }
  19. response = requests.get(url, params=data)
  20. print(response.text)
  21. if response.status_code == 200:
  22. return response.json()
  23. return None
  24. except Exception as e:
  25. logger.error(f"Error getting phone number: {e} : {response.text}")
  26. return None
  27. def get_verification_code(self, activation_id):
  28. try:
  29. url = 'https://sms-activate.org/stubs/handler_api.php'
  30. data = {
  31. 'api_key': self.api_key,
  32. 'action': 'getStatus',
  33. 'id': activation_id,
  34. }
  35. response = requests.get(url, params=data)
  36. print(response.text)
  37. if response.status_code == 200:
  38. if 'OK' in response.text:
  39. return response.text.split(':')[1]
  40. return None
  41. except Exception as e:
  42. logger.error(f"Error getting phone number: {e} : {response.text}")
  43. return None
  44. def set_status(self, activation_id, status):
  45. # Implement the logic to set the status of the verification code
  46. pass