一年前,由于工作需要,给以色列的同事解释一下国都短信平台的短信发送格式,本来不懂python的我硬着头皮写了一个sample,比较粗,能用,但不优美,希望以后学会python能改得像我同事写的那么优雅
#!/usr/bin/python #coding:utf8 import sys,httplib,urllib,urllib2 import xml.etree.ElementTree as ET sms=u‘测试短信内容【签名部分】‘ #input message here with ‘‘ gbk_string=sms.encode("gbk") #encode to GBK params = urllib.urlencode({‘OperID‘:‘国都平台账号‘, ‘OperPass‘:‘平台密码‘, ‘SendTime‘:‘发送时间‘, ‘ValidTime‘:‘‘, ‘AppendID‘:‘附加码‘, ‘DesMobile‘:‘接受短信的手机号码‘, ‘Content‘:gbk_string, ‘ContentType‘:‘8‘}) url=‘http://平台接口地址/QxtSms/QxtFirewall‘ send = urllib2.Request(url,params) response = urllib2.urlopen(send) res_page = response.read() xml=res_page.decode(‘gbk‘) xml=xml.replace(‘gbk‘, ‘utf-8‘) root = ET.fromstring(xml) codes=root.getiterator(‘code‘) status=codes[0].text if status == ‘03‘: print "短信发送成功!" else: print "短信发送失败!"
时间: 2024-10-19 11:37:58