添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

如何使用Python的smpplib向多个号码同时发送短信?

0 人关注

我已经能够使用以下代码向一个电话号码发送短信了

import smpplib
import settings
import sys
client = smpplib.client.Client(settings.SMS_SYSTEM_HOSTNAME, settings.SMS_SYSTEM_PORT)
# 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=settings.SMS_SYSTEM_ID, password=settings.SMS_SYSTEM_PASSWORD)
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='90474xxxxx',
    short_message=b'Test message')
print(pdu.sequence)
client.listen()

但这个项目的主要目的是一次向大量的数字(至少一百万)发送。我怎样才能做到这一点呢?

The obvious solution might be to put

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='904xxxxxxxx',
    short_message=b'Test message')

在一个循环中,但我怀疑这样做的效率。有没有一种更好的、更有效的方法来使用Python和SMPP批量发送短信?