Python异步提交短信的模块

SmsHttpChannel的Python项目详细描述


1、SmsHttpChannel介绍

​ SmsHttpChannel模块是用于异步短信接口的发送,主要依赖于Tornado框架中的AsyncHTTPClient模块。

2、接口所属

​ 主要用于无锡线上线下通讯信息技术股份有限公司的短信接口

3、短信接口协议文档

v3 : http://doc.wxxsxx.com/

v4: https://api-wiki.wxxsxx.com/

4、代码示例

4.1、单内容多号码批量发送
importloggingfromtypingimportDictfromxsxx.xsxx_channelimportSmsV3HttpChannel,SmsV4HttpChanneldefsubmit_callback(response:Dict):"""        定义提交短信后的回调的处理函数    """logging.info(response)if__name__=='__main__':logging.basicConfig(level=logging.INFO,format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')logger=logging.getLogger(__name__)url='https://ip:port'userId='xxxx'password='xxxxx'# http_channel = SmsV3HttpChannel(url=url, userId=userId, password=password)  # V3协议http_channel=SmsV4HttpChannel(url=url,userId=userId,password=password)# V4协议request_list=list()request_list.append(http_channel.one_content_phones(content='【线上线下】你的验证码:8888',mobile='1314342139x'))request_list.append(http_channel.one_content_phones(content='【线上线下】你的验证码:8888',mobile='1314342139x'))request_list.append(http_channel.one_content_phones(content='【线上线下】你的验证码:8888',mobile='1314342139x'))http_channel.send_request(http_channel,request_list,callback_func=submit_callback)"""    输出的结果:        2020-11-26 23:26:16,812 - root - INFO - {'status': 0, 'msgid': '-4801649735315642901'}        2020-11-26 23:26:16,829 - root - INFO - {'status': 0, 'msgid': '-4801649735315642900'}        2020-11-26 23:26:16,861 - root - INFO - {'status': 0, 'msgid': '-4801649735315642899'}    """
4.2、 预付费账号余额查询
importloggingfromtypingimportDictfromxsxx.xsxx_channelimportSmsV3HttpChannel,SmsV4HttpChanneldefbalance_callback(response:Dict):"""        查询余额请求后的回调的处理函数    """logging.info(response)if__name__=='__main__':logging.basicConfig(level=logging.INFO,format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')logger=logging.getLogger(__name__)url='https://ip:port'userId='xxxx'password='xxxxx'# http_channel = SmsV3HttpChannel(url=url, userId=userId, password=password)  # V3协议http_channel=SmsV4HttpChannel(url=url,userId=userId,password=password)# V4协议request_list=list()request_list.append(http_channel.get_user_balance())http_channel.send_request(http_channel,request_list,callback_func=balance_callback)
4.3、上行主动获取
importloggingfromtypingimportDictfromxsxx.xsxx_channelimportSmsV3HttpChannel,SmsV4HttpChanneldefmo_callback(response:Dict):"""        查询上行请求后的回调的处理函数    """logging.info(response)if__name__=='__main__':logging.basicConfig(level=logging.INFO,format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')logger=logging.getLogger(__name__)url='https://ip:port'userId='xxxx'password='xxxxx'# http_channel = SmsV3HttpChannel(url=url, userId=userId, password=password)  # V3协议http_channel=SmsV4HttpChannel(url=url,userId=userId,password=password)# V4协议request_list=list()request_list.append(http_channel.get_mo())http_channel.send_request(http_channel,request_list,callback_func=mo_callback)"""    输出的结果:        2020-11-26 23:55:27,590 - root - INFO - {'status': 0, 'result': []}    """
4.4、状态报告主动获取
importloggingfromtypingimportDictfromxsxx.xsxx_channelimportSmsV3HttpChannel,SmsV4HttpChanneldefreport_callback(response:Dict):"""        定义状态请求后的回调的处理函数    """logging.info(response)if__name__=='__main__':logging.basicConfig(level=logging.INFO,format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')logger=logging.getLogger(__name__)url='https://ip:port'userId='xxxx'password='xxxxx'# http_channel = SmsV3HttpChannel(url=url, userId=userId, password=password)  # V3协议http_channel=SmsV4HttpChannel(url=url,userId=userId,password=password)# V4协议request_list=list()request_list.append(http_channel.get_report())http_channel.send_request(http_channel,request_list,callback_func=report_callback)"""    输出的结果:        2020-11-26 23:57:14,371 - root - INFO - {'status': 0, 'result': []}    """
4.5、获取发送账号日统计[V4协议支持]
importloggingfromtypingimportDictfromxsxx.xsxx_channelimportSmsV4HttpChanneldefdaily_stats(response:Dict):"""        日统计报表请求后的回调的处理函数    """logging.info(response)if__name__=='__main__':logging.basicConfig(level=logging.INFO,format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')logger=logging.getLogger(__name__)url='https://ip:port'userId='xxxx'password='xxxxx'#  获取发送账号日统计http_channel=SmsV4HttpChannel(url=url,userId=userId,password=password)request_list=list()request_list.append(http_channel.get_daily_stats())http_channel.send_request(http_channel,request_list,callback_func=daily_stats)

5、多线程多协程提交短信的示例

importthreadingimportloggingfromtypingimportDictfromxsxx.xsxx_channelimportSmsV3HttpChanneldefsubmit_callback(response:Dict):"""        提交短信的回调函数    """logging.info(response)if__name__=='__main__':logging.basicConfig(level=logging.INFO,format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')logger=logging.getLogger(__name__)url='https://ip:port'userId='xxxx'password='xxxxx'# http_channel = SmsV3HttpChannel(url=url, userId=userId, password=password)  # V3协议http_channel=SmsV4HttpChannel(url=url,userId=userId,password=password)# V4协议request_list=list()request_list.append(http_channel.one_content_phones(content='【线上线下】你的验证码:8888',mobile='1314342139x'))request_list.append(http_channel.one_content_phones(content='【线上线下】你的验证码:8888',mobile='1314342139x'))request_list.append(http_channel.one_content_phones(content='【线上线下】你的验证码:8888',mobile='1314342139x'))# 多线程多协程的运行任务task_list=[]fortaskinrange(3):task_start=threading.Thread(target=http_channel.send_request,args=(http_channel,request_list,submit_callback))task_start.start()task_list.append(task_start)fortaskintask_list:task.join()

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

推荐PyPI第三方库


热门话题
java确保我正确地解决了这个问题   对于Java接口中的常量,“publicstaticfinal”是多余的吗?   为什么是java。网SocketException:socket在java之后关闭。网ConnectException:连接被拒绝'?   安卓在Java中将JSON转换为多维数组的最佳方式是什么?   java如何为gradle构建使用lint4j插件,以及如何为Jenkins配置它?   JavaMaven:一个项目如何能够从一个二级依赖引用一个类   使用java的excel Linest函数   java如何完全禁用JTextPane的文本突出显示?   java jBoss概要如何?   java Pi4J类路径错误Intellij在Pi Zero W上远程运行   java如何根据特定条件在JPA/Play中使用EntityManager进行批量更新?   java如何在EJB调度中设置计时器值?   javasocket服务器没有连接   java如何在日期解析后以yyyyMMdd格式获取日期对象   java客户端python服务器发送udp数据   使用ArrayList从java文件中读取文本   框架上的java Selenium测试   java setOnClickListener匿名类?