
import requests

def convert_to_unicode(input_str):
    # Convert string to bytes using UTF-16 little-endian encoding
    byte_array = input_str.encode('utf-16le')

    # Swap bytes to convert from little-endian to big-endian
    swapped_bytes = bytearray(len(byte_array))
    for i in range(0, len(byte_array), 2):
        swapped_bytes[i] = byte_array[i + 1]
        swapped_bytes[i + 1] = byte_array[i]

    # Convert bytes to hexadecimal representation
    unicode_string = ''.join(format(byte, '02x') for byte in swapped_bytes)

    return unicode_string.upper()

def SendSms(Phone,Message,Provider) :
    Message = convert_to_unicode(Message)
    print (Message)
    if  Provider == 'icosnet' :
        #Phone =DriverPhone
        IcosnetSmsUrl = "https://smsapi.icosnet.com:8443/bulksms/bulksms?"
        IcosnetSmsUser = "QOOXY"
        IcosnetSmsPassword = "SMS3515"
        IcosnetSmsSource = "QOOXY"
        h = {
            'Host': 'smsapi.icosnet.com:8443',
            'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:127.0) Gecko/20100101 Firefox/127.0',
            'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
            'Accept-Language': 'en-US,en;q=0.5',
            'Accept-Encoding': 'gzip, deflate, br, zstd',
            'Connection': 'keep-alive',
            'Upgrade-Insecure-Requests': '1',
            'Sec-Fetch-Dest': 'document',
            'Sec-Fetch-Mode': 'navigate',
            'Sec-Fetch-Site': 'none',
            'Sec-Fetch-User': '?1',
            'Priority': 'u=1',
            'TE': 'trailers'
        }
        IcosnetSmsParms = {
            "username" : IcosnetSmsUser,
            "password" : IcosnetSmsPassword,
            "type" : 0,
            "dlr" : 1,
            "destination" : str(Phone).strip(),
            "source" : IcosnetSmsSource,
            "message" : Message
                            } 

        resp= requests.get(url = IcosnetSmsUrl,params = IcosnetSmsParms,headers=h,verify=False)
        #async with httpx.AsyncClient(verify=False) as client :
            #resp = await client.get(IcosnetSmsUrl, params =IcosnetSmsParms)
            
        print (resp.text)
        #return resp.text

SendSms ("213775224664","Helloword","icosnet")
