python 发送soap消息
2013-07-22 16:10
239 查看
从网上copy 修改的:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys,os
import httplib
import time
def sendSoapDataByHttp(strWsdl,phone):
#global phone
#phone = 13100000002
SoapMessage = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:v2=\"http://www.huawei.com.cn/schema/common/v2_1\" xmlns:loc=\"http://www.csapi.org/schema/parlayx/sms/notification/v2_2/local\">\
<soapenv:Header>\
<v2:NotifySOAPHeader>\
<v2:spId>35000001</v2:spId>\
<v2:subReqID>1234567890</v2:subReqID>\
<v2:traceUniqueID>1231312341234123432</v2:traceUniqueID>\
<v2:timeStamp>1372411301893</v2:timeStamp>\
</v2:NotifySOAPHeader>\
</soapenv:Header>\
<soapenv:Body>\
<loc:notifySmsReception>\
<loc:correlator>0101201306290231500004192168025007000000000000044</loc:correlator>\
<loc:message>\
<message>like</message>\
<senderAddress>tel:" + str(phone) + "</senderAddress>\
<smsServiceActivationNumber>10658099028881</smsServiceActivationNumber>\
<dateTime>2010-08-09T00:00:00.000+08:00</dateTime>\
</loc:message>\
</loc:notifySmsReception>\
</soapenv:Body>\
</soapenv:Envelope>"
##http://192.168.1.100:7654/services/abcMgntService?wsdl
pos = strWsdl.find('/',7)
strHost = strWsdl[7:pos]
strPostval = strWsdl[pos:len(strWsdl)]
#print strHost
#print strPostval
webservice = httplib.HTTP(strHost)
webservice.putrequest("POST", strPostval)
webservice.putheader("Host", strHost)
webservice.putheader("User-Agent", "Python Post")
webservice.putheader("Content-type", "text/xml; charset=\"UTF-8\"")
webservice.putheader("Content-length", "%d" % len(SoapMessage))
webservice.endheaders()
webservice.send(SoapMessage)
# get the response
statuscode, statusmessage, header = webservice.getreply()
msg = ' Response: %d %s\n headers: %s\n %s' % (statuscode,statusmessage,header,webservice.getfile().read() )
if statuscode == 200:
return 0,msg
else:
return 1,msg
def main():
phone = 13100000001
for i in range(0,50):
retCode, msg = sendSoapDataByHttp("http://10.137.73.162:14455/promotion/services/SmsNotificationService",phone)
print phone
phone = phone + 1
time.sleep(0.1)
#print "Return code: ", retCode
#print msg
if __name__ == '__main__':
main()
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys,os
import httplib
import time
def sendSoapDataByHttp(strWsdl,phone):
#global phone
#phone = 13100000002
SoapMessage = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:v2=\"http://www.huawei.com.cn/schema/common/v2_1\" xmlns:loc=\"http://www.csapi.org/schema/parlayx/sms/notification/v2_2/local\">\
<soapenv:Header>\
<v2:NotifySOAPHeader>\
<v2:spId>35000001</v2:spId>\
<v2:subReqID>1234567890</v2:subReqID>\
<v2:traceUniqueID>1231312341234123432</v2:traceUniqueID>\
<v2:timeStamp>1372411301893</v2:timeStamp>\
</v2:NotifySOAPHeader>\
</soapenv:Header>\
<soapenv:Body>\
<loc:notifySmsReception>\
<loc:correlator>0101201306290231500004192168025007000000000000044</loc:correlator>\
<loc:message>\
<message>like</message>\
<senderAddress>tel:" + str(phone) + "</senderAddress>\
<smsServiceActivationNumber>10658099028881</smsServiceActivationNumber>\
<dateTime>2010-08-09T00:00:00.000+08:00</dateTime>\
</loc:message>\
</loc:notifySmsReception>\
</soapenv:Body>\
</soapenv:Envelope>"
##http://192.168.1.100:7654/services/abcMgntService?wsdl
pos = strWsdl.find('/',7)
strHost = strWsdl[7:pos]
strPostval = strWsdl[pos:len(strWsdl)]
#print strHost
#print strPostval
webservice = httplib.HTTP(strHost)
webservice.putrequest("POST", strPostval)
webservice.putheader("Host", strHost)
webservice.putheader("User-Agent", "Python Post")
webservice.putheader("Content-type", "text/xml; charset=\"UTF-8\"")
webservice.putheader("Content-length", "%d" % len(SoapMessage))
webservice.endheaders()
webservice.send(SoapMessage)
# get the response
statuscode, statusmessage, header = webservice.getreply()
msg = ' Response: %d %s\n headers: %s\n %s' % (statuscode,statusmessage,header,webservice.getfile().read() )
if statuscode == 200:
return 0,msg
else:
return 1,msg
def main():
phone = 13100000001
for i in range(0,50):
retCode, msg = sendSoapDataByHttp("http://10.137.73.162:14455/promotion/services/SmsNotificationService",phone)
print phone
phone = phone + 1
time.sleep(0.1)
#print "Return code: ", retCode
#print msg
if __name__ == '__main__':
main()
相关文章推荐
- python win32api win32gui win32con 窗口句柄 发送消息 常用方法 键盘输入
- 微信开发 python django 多客服接口发送到客户端的消息乱码
- HttpURLConnection 直接发送soap消息调用webservice
- (六)发送、接收SOAP消息(1)
- Python 邮件发送消息
- : 使用SAAJ发送和接收SOAP消息
- python实现QQ机器人(自动登录,获取群消息,发送群消息)
- 使用python发送gtalk消息
- 使用Python创建自定义机器人向群组人员发送消息
- python实战系列之RTX发送告警消息(四)
- python,UPD,socket(一) 使用udp 发送消息
- SOAP消息发送(拼装消息体)
- Python UDP协议,冒充飞Q发送消息
- python实现给微信公众号发送消息的方法
- [Python]webservice学习(2) --自己写soap消息请求服务
- python实现QQ机器人(自己主动登录,获取群消息,发送群消息)
- (七)发送、接收SOAP消息(以HttpClient方式)(2)
- Python 微信公众号发送消息
- Python天天美味(27) - 网络编程起步(Socket发送消息)
- WCF笔记(3)发送和接收SOAP(消息)头