简体   繁体   中英

How to send long message using smpp.twisted python library

How to send long message using smpp.twisted python library. I know how to send short message before 160 bytes. For example:

ESME_NUM = '9090'
phone = '123456'
short_message = 'There is not short message.'*15

submit_pdu = SubmitSM(
    source_addr=ESME_NUM,
    destination_addr=phone,
    short_message=short_message,
    source_addr_ton=SOURCE_ADDR_TON,
    dest_addr_ton=DEST_ADDR_TON,
    dest_addr_npi=DEST_ADDR_NPI,
    esm_class=EsmClass(EsmClassMode.DEFAULT, EsmClassType.DEFAULT),
    protocol_id=0,
    registered_delivery=RegisteredDelivery(
        RegisteredDeliveryReceipt.SMSC_DELIVERY_RECEIPT_REQUESTED),
    replace_if_present_flag=ReplaceIfPresentFlag.DO_NOT_REPLACE,
    data_coding=DataCoding(DataCodingScheme.DEFAULT, DataCodingDefault.UCS2),
)
submitSMDeferred = smpp.sendDataRequest(submit_pdu)

If short_message > 160 b I cannot send message.

I found solution with using message_payload, but sms split on parts.

length = len(short_message)
splitat = 160
parts = length/splitat +1
submit_pdu = None
submitSMDeferred = defer.Deferred()
if length > splitat:
    for k in range(parts):
        msgpart =  short_message[k*splitat:k*splitat+splitat]
        self.logger.info('%s - %s - %s' % (msgpart, parts, k))
        submit_pdu = SubmitSM(
            source_addr=self.ESME_NUM,
            destination_addr=source_addr,
            source_addr_ton=self.SOURCE_ADDR_TON,
            dest_addr_ton=self.DEST_ADDR_TON,
            dest_addr_npi=self.DEST_ADDR_NPI,
            esm_class=EsmClass(EsmClassMode.DEFAULT, EsmClassType.DEFAULT),
            protocol_id=0,
            registered_delivery=RegisteredDelivery(
                RegisteredDeliveryReceipt.SMSC_DELIVERY_RECEIPT_REQUESTED),
            replace_if_present_flag=ReplaceIfPresentFlag.DO_NOT_REPLACE,
            data_coding=DataCoding(DataCodingScheme.DEFAULT, DataCodingDefault.UCS2),
            sar_msg_ref_num = 1,
            sar_total_segments = parts,
            sar_segment_seqnum = k+1,
            message_payload=msgpart
        )
        submitSMDeferred = smpp.sendDataRequest(submit_pdu)

I'm sorry. You just can use message_payload instead short_message . Example:

ESME_NUM = '9090'
phone = '123456'
short_message = 'There is not short message.'*15

submit_pdu = SubmitSM(
    source_addr=ESME_NUM,
    destination_addr=phone,
    message_payload=short_message,
    source_addr_ton=SOURCE_ADDR_TON,
    dest_addr_ton=DEST_ADDR_TON,
    dest_addr_npi=DEST_ADDR_NPI,
    esm_class=EsmClass(EsmClassMode.DEFAULT, EsmClassType.DEFAULT),
    protocol_id=0,
    registered_delivery=RegisteredDelivery(
        RegisteredDeliveryReceipt.SMSC_DELIVERY_RECEIPT_REQUESTED),
    replace_if_present_flag=ReplaceIfPresentFlag.DO_NOT_REPLACE,
    data_coding=DataCoding(DataCodingScheme.DEFAULT, DataCodingDefault.UCS2),
)
smpp.sendDataRequest(submit_pdu).addBoth(message_sent)

Stay it here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM