You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.9 KiB
61 lines
1.9 KiB
import time
|
|
from config.settings import base as settings
|
|
|
|
from celery import shared_task
|
|
import requests
|
|
import json
|
|
|
|
@shared_task
|
|
def send_otp_code(phone_number, code):
|
|
BASE_URL_SERVICE = "https://console.melipayamak.com/api/send/simple/"
|
|
|
|
phone_number = str(phone_number)
|
|
code = str(code)
|
|
print(code)
|
|
data = {'from': '50004001410202', 'to': phone_number, 'text': code}
|
|
response = requests.post(f'{BASE_URL_SERVICE}{settings.OTP_SERIVCE_KEY}',
|
|
json=data)
|
|
|
|
print(response.json())
|
|
|
|
|
|
def send_otp_code_whatsapp(phone_number, code):
|
|
phone = phone_number
|
|
if phone.startswith('0'):
|
|
phone = phone[1:]
|
|
phone = '98' + phone
|
|
|
|
urls = [
|
|
"https://7103.api.greenapi.com/waInstance7103107557/sendMessage/dcc7cc469e274389aa3ea4d6dae9d4d126b8b07a09be41c28e",
|
|
"https://7103.api.greenapi.com/waInstance7103109151/sendMessage/ed9cbea884cc49fd8032862f1bceca2074f373540dca483382",
|
|
"https://7103.api.greenapi.com/waInstance7103109158/sendMessage/92d032caca1541799a4623cfcc86f449ea7f3205b30848eeab",
|
|
"https://7103.api.greenapi.com/waInstance7103109163/sendMessage/d31a08b5816c432daa6e256e181274d1d334e4256d3c4555a7",
|
|
|
|
]
|
|
payload = {
|
|
"chatId": f"{phone}@c.us",
|
|
"message": f"Habib App --aqila-- {code}"
|
|
}
|
|
headers = {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
|
|
for url in urls:
|
|
response = requests.request("POST", url=url, headers=headers, data=json.dumps(payload))
|
|
response.encoding = 'utf-8'
|
|
response_data = response.json()
|
|
|
|
invoke_status = response_data.get('invokeStatus', {})
|
|
status = invoke_status.get('status', '')
|
|
|
|
print(f'>>>>>>>> {response_data}')
|
|
print(f"Response: {status}")
|
|
|
|
if status != "QUOTE_ALLOWED":
|
|
print("OTP sent successfully.")
|
|
break
|
|
else:
|
|
print("QUOTE_ALLOWED error, trying next URL...")
|
|
time.sleep(2)
|
|
|
|
|