Пример #1
0
def local_pass_pdu(pdu):

    return client.send_message(
        service_type=pdu.service_type,
        source_addr_ton=int(pdu.source_addr_ton),
        source_addr_npi=int(pdu.source_addr_npi),
        source_addr=pdu.source_addr,
        dest_addr_ton=int(pdu.dest_addr_ton),
        dest_addr_npi=int(pdu.dest_addr_npi),
        destination_addr=pdu.destination_addr,
        data_coding=int(pdu.data_coding),
        esm_class=int(pdu.esm_class),
        short_message=pdu.short_message,
        registered_delivery=int(pdu.registered_delivery),
        user_message_reference=int(pdu.user_message_reference)
    )
def send_message(src,dest, string):
    parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(string)

    logging.info('Sending SMS "%s" to %s' % (string, dest))
    for part in parts:
        pdu = client.send_message(
            source_addr_ton=smpplib.consts.SMPP_TON_INTL,
            source_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
            source_addr=src,
            dest_addr_ton=smpplib.consts.SMPP_TON_INTL,
            dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
            destination_addr=dest,
            short_message=part,
            data_coding=encoding_flag,
            esm_class=msg_type_flag,
            registered_delivery=False,
    )
Пример #3
0
def send_message(message: str, sender: str, receiver: str):
    # Two parts, UCS2, SMS with UDH
    parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(message)

    for part in parts:
        pdu = client.send_message(
            source_addr_ton=smpplib.consts.SMPP_TON_INTL,
            # source_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
            # Make sure it is a byte string, not unicode:
            source_addr=sender,
            dest_addr_ton=smpplib.consts.SMPP_TON_INTL,
            # dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
            # Make sure thease two params are byte strings, not unicode:
            destination_addr=receiver,
            short_message=part,
            data_coding=encoding_flag,
            esm_class=msg_type_flag,
            registered_delivery=True,
        )
Пример #4
0
def submit(client, msisdn, src_addr, ussd_service_op, user_message_reference=None,  text=""):
    try:
        if text is not None:
            log.info('text length {} to submit: {}'.format(len(text), text))
            if len(text) > 160:
                text = text[:160]
        else:
            log.info('text length {} to submit: {}'.format('text is None', text))
        parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(text)
    except Exception as err:
        log.info('text to submit in exception: {}'.format(err.message))
        text = 'Unknown error. Try later!'
        parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(text)
    msisdn = str(msisdn)

    def hex_val(number):
        x = format(number, '04x')
        y = x[-2:] + x[:2]
        return int(y, base=16)

    if user_message_reference:
        user_message_reference = hex_val(user_message_reference)

    for part in parts:
        pdu = client.send_message(
            service_type='USSD',
            source_addr_ton=smpplib.consts.SMPP_TON_UNK,
            source_addr_npi=smpplib.consts.SMPP_NPI_UNK,
            source_addr=src_addr,
            dest_addr_ton=smpplib.consts.SMPP_TON_INTL,
            dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
            esm_class=smpplib.consts.SMPP_MSGMODE_FORWARD,
            destination_addr=msisdn,
            short_message=part,
            data_coding=encoding_flag,
            registered_delivery=False,
            priority_flag=1,
            ussd_service_op=ussd_service_op,
            user_message_reference=user_message_reference,
        )
    log.info('text was sent: {}: {}'.format(pdu.destination_addr, pdu.short_message))
    return 1
Пример #5
0
def send_message(source, dest, string):
	client = smpplib.client.Client('127.0.0.1', 2775)

	# Print when obtain message_id
	client.set_message_sent_handler(
		lambda pdu: sys.stdout.write('sent {} {}\n'.format(pdu.sequence, pdu.message_id)))
	client.set_message_received_handler(
		lambda pdu: sys.stdout.write('delivered {}\n'.format(pdu.receipted_message_id)))

	client.connect()
	client.bind_transceiver(system_id='OSMO-SMPP', password='******')

	parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(string)
	#part = b"".join(parts)

	try:
		string.encode("ascii")
		coding = encoding_flag
	except:
		coding = smpplib.consts.SMPP_ENCODING_ISO10646
		
	logging.info('Sending SMS "%s" to %s' % (string, dest))
	for part in parts:
		pdu = client.send_message(
			msg_type=smpplib.consts.SMPP_MSGTYPE_USERACK,
			source_addr_ton=smpplib.consts.SMPP_TON_ALNUM,
			source_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
			source_addr=source,
			dest_addr_ton=smpplib.consts.SMPP_TON_INTL,
			dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
			destination_addr=dest,
			short_message=part,
			data_coding=coding,
			esm_class=msg_type_flag,
			#esm_class=smpplib.consts.SMPP_MSGMODE_FORWARD,
			registered_delivery=True,
		)
		#print(pdu.generate())
	logging.debug(pdu.sequence)
def send_mssg(message, sender, reciver):
    parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(message * 10)

    for part in parts:
        pdu = client.send_message(
            source_addr_ton=smpplib.consts.SMPP_TON_INTL,
            # source_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
            # Make sure it is a byte string, not unicode:
            source_addr=sender,

            dest_addr_ton=smpplib.consts.SMPP_TON_INTL,
            # dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
            # Make sure thease two params are byte strings, not unicode:
            destination_addr=reciver,
            short_message=part,

            data_coding=encoding_flag,
            esm_class=msg_type_flag,
            registered_delivery=True,
        )

# send_to_jasmin_smpp_server("+23434", "+#43434","")
def send_to_jasmin_smpp_server(sender, reciver, message):
    logging.basicConfig(level='DEBUG')

    parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(message * 10)

    client = smpplib.client.Client('10.99.101.246', 2775)

    client.set_message_sent_handler(
        lambda pdu: sys.stdout.write('sent {} {}\n'.format(pdu.sequence, pdu.message_id)))

    client.set_message_received_handler(
        lambda pdu: sys.stdout.write('delivered {}\n'.format(pdu.receipted_message_id)))

    client.connect()
    client.bind_transceiver(system_id='rekik', password='******')

    for part in parts:
        pdu = client.send_message(
            source_addr_ton=smpplib.consts.SMPP_TON_INTL,
            # source_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
            # Make sure it is a byte string, not unicode:
            source_addr=sender,

            dest_addr_ton=smpplib.consts.SMPP_TON_INTL,
            # dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
            # Make sure thease two params are byte strings, not unicode:
            destination_addr=reciver,
            short_message=part,

            data_coding=encoding_flag,
            esm_class=msg_type_flag,
            registered_delivery=True,
        )
        print(pdu.sequence)
        t = Thread(target=client.listen())
        t.start()
Пример #8
0
    def sendShortMessage(self, client, data={}):
        dest_range = int(data["destinationAddressRange"].encode('utf-8'))
        dest_src = int(data["destinationAddress"].encode('utf-8'))
        src_range = int(data["sourceAddressRange"].encode('utf-8'))
        src_start = int(data["sourceAddress"].encode('utf-8'))
        key_pause = str(data["timeStamp"]) + "_pause"
        key_stop = str(data["timeStamp"]) + "_stop"
        global totMsg
        totMsg = dest_range * src_range
        print(totMsg)
        for src_add in range(src_start, src_range + src_start):
            for dest_add in range(dest_src, dest_range + dest_src):

                if (str(data["messageMethod"]) == "randomMessage"):
                    data["shortMessage"] = workerClass().randomMsg(10)

                print(data["messageMethod"])
                print(data["shortMessage"])
                while workerClass().red.get(key_pause) == "1":
                    #print(workerClass().red.get(key),key)
                    print("pause")
                    time.sleep(10)
                while workerClass().red.get(key_stop) == "1":
                    return
                try:
                    pdu = client.send_message(
                        source_addr_ton=int(
                            data["sourceAddressTon"].encode('utf-8')),
                        source_addr_npi=int(
                            data["sourceAddressNpi"].encode('utf-8')),
                        source_addr=str(src_add),
                        dest_addr_ton=int(
                            data["destinationAddressTon"].encode('utf-8')),
                        dest_addr_npi=int(
                            data["destinationAddressNpi"].encode('utf-8')),
                        destination_addr=str(dest_add),
                        short_message=data["shortMessage"].encode('utf-8'),
                        registered_delivery=int(
                            data["registeredDelivery"].encode('utf-8')),
                        data_coding=int(data["dataCoding"].encode('utf-8')))

                    print("inside send msg ", str(src_add), str(dest_add))
                    data["msgSend"] = int(data["msgSend"]) + 1

                    print(data["msgSend"])
                    key = str(data["timeStamp"]) + "_send"
                    print("key=====" + key)
                    self.red.set(key, data["msgSend"])

                except:
                    raise
                    print("SendShortMessage exception occured")

            print(data["msgSend"])
            print("SendShortMessage database")
            print(data["msgSend"])
            key = str(data["timeStamp"]) + "_send"

            sql = "UPDATE smpptrafficmonitor SET msgSend = %s where timeStamp= %s"
            val = (self.red.get(key), str(data["timeStamp"]))
            workerClass().mycursor.execute(sql, val)
            workerClass().database.commit()
Пример #9
0
client.set_message_received_handler(lambda pdu: handle_deliver_sm(pdu))

client.connect()
client.bind_transceiver(system_id='DYNAMO',
                        password='******',
                        system_type='dyn')

for part in parts:
    pdu = client.send_message(
        source_addr_ton=smpplib.consts.SMPP_TON_NWSPEC,
        #source_addr_ton=smpplib.consts.SMPP_TON_ALNUM,
        source_addr_npi=smpplib.consts.SMPP_NPI_UNK,
        # Make sure it is a byte string, not unicode:
        source_addr='5838',
        #source_addr='UPSTREAM',
        #smpplib.consts.SMPP_TON_UNK
        #smpplib.consts.SMPP_TON_ALNUM
        dest_addr_ton=smpplib.consts.SMPP_TON_INTL,
        dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
        # Make sure thease two params are byte strings, not unicode:
        destination_addr='5524988398508',
        short_message=part,
        data_coding=encoding_flag,
        esm_class=msg_type_flag,
        registered_delivery=True,
    )
    print(pdu.sequence)

# Enters a loop, waiting for incoming PDUs
client.listen()
Пример #10
0
def received_handler(pdu):
    """
    """
    print("Received pdu %s" % pdu)


client = smpplib.client.Client(host="smpp1.mymobileapi.com", port=4075)

client.set_message_sent_handler(sent_handler)
client.set_message_received_handler(received_handler)

client.connect()
client.bind_transceiver(system_id="EUROCOM", password="******")

Thread(target=client.listen).start()

parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts("Testing this.")

for part in parts:
    pdu = client.send_message(
        source_addr_ton=smpplib.consts.SMPP_TON_INTL,
        source_addr="",
        dest_addr_ton=smpplib.consts.SMPP_TON_INTL,
        destination_addr="27813821298",
        short_message=part,
        data_coding=encoding_flag,
        esm_class=msg_type_flag,
        registered_delivery=True,
    )
Пример #11
0
import smpplib
import settings

client = None
try:
    client = smpplib.client.Client(settings.SMS_SYSTEM_HOSTNAME,
                                   settings.SMS_SYSTEM_PORT)
    client.connect()
    try:
        client.bind_transmitter(system_id=settings.SMS_SYSTEM_ID,
                                password=settings.SMS_SYSTEM_PASSWORD)

        client.send_message(source_addr_ton=smpplib.consts.SMPP_TON_INTL,
                            source_addr='9535134654',
                            dest_addr_ton=smpplib.consts.SMPP_TON_INTL,
                            destination_addr='9535134654',
                            short_message='hola sms'.encode())
    finally:
        #print "==client.state====", client.state
        if client.state in [smpplib.consts.SMPP_CLIENT_STATE_BOUND_TX]:
            #if bound to transmitter
            try:
                client.unbind()
            except smpplib.exceptions.UnknownCommandError as ex:
                #https://github.com/podshumok/python-smpplib/issues/2
                try:
                    client.unbind()
                except smpplib.exceptions.PDUError as ex:
                    pass
finally:
Пример #12
0
# BODY
status = 0

parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(MESSAGE)
client = smpplib.client.Client(SERVER_ADDRESS, PORT)
client.set_message_sent_handler(lambda pdu: sys.stdout.write(
    'sent {} {}\n'.format(pdu.sequence, pdu.message_id)))
status += 1
client.set_message_received_handler(lambda pdu: sys.stdout.write(
    'delivered {}\n'.format(pdu.receipted_message_id)))

try:
    client.connect()
    client.bind_transceiver(system_id=SYSTEM_ID, password=PASSWORD)

    for part in parts:
        pdu = client.send_message(
            source_addr_ton=smpplib.consts.SMPP_TON_INTL,
            source_addr=SOURCE_ADDR,
            dest_addr_ton=smpplib.consts.SMPP_TON_INTL,
            destination_addr=DESTINATION_ADDR,
            short_message=part,
            data_coding=encoding_flag,
            esm_class=msg_type_flag,
        )
except Exception:
    status = 0
finally:
    sys.stdout.write(str(status) + '\n')
Пример #13
0
client.connect()
client.bind_transceiver(system_id='id', password='******')
#getting our database table as pandas dataframe
getDF()
for row in df.itterrow():
    text = row[1].SMSText
    parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(
        u'{}'.format(text))
    for part in parts:
        pdu = client.send_message(
            source_addr_ton=0,
            source_addr_npi=0,
            # Make sure it is a byte string, not unicode:
            source_addr='0000',
            dest_addr_ton=1,
            dest_addr_npi=1,
            # Make sure thease two params are byte strings, not unicode:
            #putting destination numbers from each row of the dataframe
            destination_addr=row[1].MSISDN,
            short_message=part,
            data_coding=encoding_flag,
            esm_class=msg_type_flag,
            registered_delivery=False,
        )
    updateRecord(row[1].ProcessNumber, row[1].MSISDN)
    print(row[1].MSISDN)
    print(pdu.sequence)

client.unbind()
client.disconnect()
Пример #14
0
client.set_message_sent_handler(lambda pdu: sys.stdout.write(
    'sent {} {}\n'.format(pdu.sequence, pdu.message_id)))
client.set_message_received_handler(lambda pdu: sys.stdout.write(
    'delivered {}\n'.format(pdu.receipted_message_id)))

client.connect()
client.bind_transceiver(system_id=SYSTEM_ID, password=PASSWORD)

for part in parts:
    pdu = client.send_message(
        source_addr_ton=smpplib.consts.SMPP_TON_INTL,
        #source_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
        # Make sure it is a byte string, not unicode:
        source_addr=FROM_PHONE_NUM,
        dest_addr_ton=smpplib.consts.SMPP_TON_INTL,
        #dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
        # Make sure thease two params are byte strings, not unicode:
        destination_addr=TO_PHONE_NUM,
        short_message=part,
        data_coding=encoding_flag,
        esm_class=msg_type_flag,
        registered_delivery=True,
    )
    print(pdu.sequence)

# Enters a loop, waiting for incoming PDUs
client.listen()

# You also may want to listen in a thread:

# from threading import Thread