You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
40 lines
1.1 KiB
# -*- coding: utf-8 -*-
|
|
from urllib import request,parse
|
|
import time,datetime
|
|
|
|
def sendSMS(txtBody,phone):
|
|
url = 'http://sms.api.ums86.com:8899/sms/Api/Send.do'
|
|
data = {
|
|
'SpCode': 'xxxxxx',
|
|
'LoginName': 'cz_xxxxx',
|
|
'Password': 'xxxxxxxx',
|
|
'MessageContent': txtBody,
|
|
'UserNumber': phone,
|
|
'SerialNumber': getSerial(),
|
|
'f': '1'
|
|
}
|
|
res = False
|
|
try:
|
|
data = parse.urlencode(data).encode('gb2312')
|
|
print(data)
|
|
req = request.Request(url, data=data)
|
|
page = request.urlopen(req).read()
|
|
page = page.decode('gb2312')
|
|
if 'result=0' in page:
|
|
res = True
|
|
except:
|
|
page = ''
|
|
print(page)
|
|
return res
|
|
|
|
def getSerial():
|
|
t = time.localtime()
|
|
h = '888018'
|
|
s = h + time.strftime('%Y%m%d%H%M%S', t)
|
|
return s
|
|
|
|
if __name__ == '__main__':
|
|
pn = 18951210000
|
|
txt = u'机房设备离线报警,请及时处理。报警代码:7,报警参数:0。'
|
|
r = sendSMS(txt.encode('gb2312'), pn)
|
|
print(r)
|
|
|