1

smpp.twisted Python ライブラリを使用して長いメッセージを送信する方法。160 バイトより前に短いメッセージを送信する方法を知っています。例えば:

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)

short_message > 160 b の場合、メッセージを送信できません。

message_payload を使用して解決策を見つけましたが、SMS が部分的に分割されました。

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)
4

1 に答える 1

0

ごめんなさい。short_messageの代わりにmessage_payloadを使用できます。例:

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)

ここにいてください。

于 2013-07-28T09:23:27.550 に答える