message_send.py
1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import zmail
import urllib.request
from urllib import parse
def send_sms(mobile, sms_info):
try:
"""
#python3
#接口类型:互亿无线触发短信接口,支持发送验证码短信、订单通知短信等。
#账户注册:请通过该地址开通账户https://user.ihuyi.com/new/register.html
#注意事项:
#(1)调试期间,请用默认的模板进行测试,默认模板详见接口文档;
#(2)请使用 用户名 及 APIkey来调用接口,APIkey在会员中心可以获取;
#(3)该代码仅供接入互亿无线短信接口参考使用,客户可根据实际需要自行编写;
"""
# 接口地址
url = 'http://106.ihuyi.com/webservice/sms.php?method=Submit'
# 定义请求的数据
values = {
'account': 'C61245995',
'password': 'b018ad136d2005b1b687dd16b119e78f',
'mobile': mobile,
'content': sms_info,
'format': 'json',
}
# 将数据进行编码
data = urllib.parse.urlencode(values).encode(encoding='UTF8')
# 发起请求
req = urllib.request.Request(url, data)
response = urllib.request.urlopen(req)
res = response.read()
return res
except Exception as e:
print(e)
def send_email(recv_email, title, content):
try:
# 设置邮件信息
mail_content = {
'subject': title, # 邮件标题
'content_text': content # 邮件内容
}
# 发件人的用户名和密码
server = zmail.server('yangzaihong@163.com', 'OTGKSKPJIMBXYLUK') # 发件人
# 发送邮件
server.send_mail(recv_email, mail_content) # 收件人
print('邮件已发送完毕')
except Exception as e:
print(e)