如何使用 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 的解决方案,但短信拆分成部分。
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)