标签:username self xxx 接口 webserver client ._ password soap
1、前言
使用soap协议去调用webserver的接口来实现发送短信的功能。
简单的了解了下发现这是基于xml的,发现貌似不会这玩意呀,以为会有点小复杂来开始踩坑。
2、安装包
pip install suds-jurko
# 注意py版本不同的话,这个包可能有差异。我这测试的py版本是3.6.8
3、找webserver接口地址
"http://xxx.xxx.xxx.xxx/msgws/service.asmx?wsdl"
# 找你需要的接口,都是wsdl形式的,或者让第三方提供
4、具体实现
import http.client as client
import time
from suds.transport.https import HttpAuthenticated
from suds.client import Client
class SendMassage(object):
def __init__(self, username, password, mobile, context):
self._username = username
self._password = password
self._mobile = mobile
self._context = context
def get_current_timestamp(self):
return int(round(time.time() * 1000))
def suds_client(self):
sms_url = "http://xxx.xxx.xxx.xxx/msgws/service.asmx?wsdl"
auth = HttpAuthenticated(username=self._username, password=self._password)
try:
client = Client(sms_url, transport=auth)
print(client)
"""
client 里可以查看有什么方法和类型
"""
request = client.factory.create('MsgSend') # 初始化方法
# 传参数
request.YHM = self._username
request.MM = self._password
request.DestMobile= self._mobile
request.MsgContent = self._context
response = client.service.MsgSend(request)
print(response)
except Exception as e:
print(e)
标签:username,self,xxx,接口,webserver,client,._,password,soap 来源: https://www.cnblogs.com/leisunny/p/16249108.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。