您的位置:首页 > 编程语言 > Python开发

python 发送soap消息

2013-07-22 16:10 183 查看
从网上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()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: