用于python的smpp库

smpplib的Python项目详细描述


python-smpplib

VersionPython versionsPyPI downloadsLicenseCircleCI

用于python的smpp库。从Google Code分叉。

示例:

importloggingimportsysimportsmpplib.gsmimportsmpplib.clientimportsmpplib.consts# if you want to know what's happeninglogging.basicConfig(level='DEBUG')# Two parts, UCS2, SMS with UDHparts,encoding_flag,msg_type_flag=smpplib.gsm.make_parts(u'Привет мир!\n'*10)client=smpplib.client.Client('example.com',SOMEPORTNUMBER)# Print when obtain message_idclient.set_message_sent_handler(lambdapdu:sys.stdout.write('sent {}{}\n'.format(pdu.sequence,pdu.message_id)))client.set_message_received_handler(lambdapdu:sys.stdout.write('delivered {}\n'.format(pdu.receipted_message_id)))client.connect()client.bind_transceiver(system_id='login',password='secret')forpartinparts: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='SENDERPHONENUM',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='PHONENUMBER',short_message=part,data_coding=encoding_flag,esm_class=msg_type_flag,registered_delivery=True,)print(pdu.sequence)client.listen()

您可能还想在一个线程中收听:

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

客户机支持设置一个自定义生成器,该生成器为pdu包生成序列号。默认情况下,使用一个简单的内存生成器,它在客户端的(重新)实例化时重置,例如通过应用程序重新启动。如果希望在重新启动时保留序列号,可以实现自己的存储支持生成器。

示例:

importsmpplib.clientimportmymodulegenerator=mymodule.PersistentSequenceGenerator()client=smpplib.client.Client('example.com',SOMEPORTNUMBER,sequence_generator=generator)...

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
带truezip的java拆分zip   java Spring,AppEngine:在AppEngine的数据源中添加postgresql url   java Android coverflow   java以编程方式创建复合过滤器,以在log4j 2中定义多个过滤器   java jpa eclipselink异常[eclipselink 4002]   中的java WordNet数据库目录相对路径。罐子   java无法在Spring Boot 2/3中显示登录的用户   java Onetomany:未找到联接表错误   java数据模型演化   java方法在类型列表中添加的(对象)不适用于参数(int)意味着什么?   用java打印两个数组   java SNMP4J发送从不超时   java添加/删除联系人(EditText)+类别(SpinnerBox),可以根据需要动态添加/删除多个联系人   语句和PreparedStatement之间的java差异   java在运行作为JAR归档文件分发的项目时加载图像等资源   来自应用程序或外部服务器的java Cron作业   多线程Java并发:并发添加和清除列表项   java更改单元测试的私有方法行为