newmediamonitoring1/dashboard/test.py

41 lines
1.4 KiB
Python
Raw Normal View History

2020-10-13 13:33:48 +00:00
import http.client
from urllib import parse
import json
#服务地址
sms_host = "sms.yunpian.com"
voice_host = "voice.yunpian.com"
#端口号
port = 443
#版本号
version = "v2"
#模板短信接口的URI
sms_tpl_send_uri = "/" + version + "/sms/tpl_single_send.json"
def tpl_send_sms(apikey, tpl_id, tpl_value, mobile):
"""
模板接口发短信
"""
params = parse.urlencode({
'apikey': apikey,
'tpl_id': tpl_id,
'tpl_value': parse.urlencode(tpl_value),
'mobile': mobile
})
headers = {
"Content-type": "application/x-www-form-urlencoded",
"Accept": "text/plain"
}
conn = http.client.HTTPSConnection(sms_host, port=port, timeout=30)
conn.request("POST", sms_tpl_send_uri, params, headers)
response = conn.getresponse()
response_str = response.read()
conn.close()
return response_str
#【甘肃大未来科技】政务新媒体监测预警:#dateStart#至#dateEnd##type# #name# 无更新,请予以关注提醒。
apikey = "304eb08353f7ebf00596737acfc31f53"
mobile = "18119305139"
tpl_id = 4041392 #【甘肃大未来科技】政务新媒体监测预警:#dateStart#至#dateEnd##type# #name# 无更新,请予以关注提醒。
tpl_value = {'#dateStart#':'10月1日','#dateEnd#':'10日','#type#':'微信公众号','#name#':'武山县人民政府网'}
print (tpl_send_sms(apikey, tpl_id, tpl_value, mobile) )