1.1 容联python基础教程云-短信
from ronglian_sms_sdk import SmsSDK
accountSid = '8a216da8757784cd0175924caccd0b92'
# 说明:主账号,登陆云通讯网站后,可在控制台首页中看到开发者主账号ACCOUNT SID。
accountToken = '4173b5d8e6ae4126acb3211ab9f4c037'
# 说明:主账号Token,登陆云通讯网站后,可在控制台首页中看到开发者主账号AUTH TOKEN。
appId = '8a216da8757784cd0175924cadaa0b98'
# 请使用管理控制台中已创建应用的APPID。
serverIP = 'app.cloopen.com'
# 说明:请求地址,生产环境配置成app.cloopen.com。
serverPort = '8883'
# 说明:请求端口 ,生产环境为8883.
softVersion = '2013-12-26' # 说明:REST API版本号保持不变。
sdk = SmsSDK(accountSid, accountToken, appId)
# tid:模板id 默认为1
res = sdk.sendMessage('1', '18704992144', ['8888','5'])
print(res)
# 可参考demo中的接口调用文件:SendTemplateSMS.py。
# import sys
# sys.path.insert(0,'/root/opwf_project/celery_task')
# from main import send_sms
from celery_task.main import send_sms
# send_sms('1','13355555555',('8888','5'))
# delay的意思就是把后面的数据发到redis上面去 调用这个redis就会多一条消息多一个任务
# 紧接着celery就会收到这个任务
for i in range(0,5):
send_sms.delay('1', '13355555555', ('8888', '5'))
# 注意:celery是怎么导进来的 启动celery就怎么启动
#1、celery -A celery_task.main worker -l info => from celery_task.main import send_sms
#2、celery -A main worker -l info => from main import send_sms
import os
import sys
import time
from celery import Celery
#执行celery命令时,需要进入CELERY_BASE_DIR目录执行
#celery项目中的所有导包地址,都是CELERY_BASE_DIR为基础设定
# CELERY_BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# sys.path.insert(0,CELERY_BASE_DIR) #增加导包路径
#定义celery实例,需要的参数 1,实例名
app = Celery('wbh',broker='redis://192.168.56.100:6379/14',backend='redis://192.168.56.100:6379/15')
@app.task
def send_sms(tid, mobile, datas):
time.sleep(10)
from ronglian_sms_sdk import SmsSDK
accountSid = '8a216da8757784cd0175924caccd0b92'
# 说明:主账号,登陆云通讯网站后,可在控制台首页中看到开发者主账号ACCOUNT SID。
accountToken = '4173b5d8e6ae4126acb3211ab9f4c037'
# 说明:主账号Token,登陆云通讯网站后,可在控制台首页中看到开发者主账号AUTH TOKEN。
appId = '8a216da8757784cd0175924cadaa0b98'
# 请使用管理控制台中已创建应用的APPID。
sdk = SmsSDK(accountSid, accountToken, appId)
# tid:模板id 默认为1
res = sdk.sendMessage(tid, mobile, datas)
print(res)
return res
-
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
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
1.2 @163.com-邮件
import smtplib
mail_host = 'smtp.163.com' #发送邮件服务器
mail_user = 'wbhL0478@163.com' # 登录名
mail_pwd = 'VPAUITGNHJFNRVLN' # 密码
sender = 'wbhL0478@163.com' # 发送人邮箱
receivers = ['wbhL0478@163.com'] # 接收人邮箱
#邮件内容
message = """From: From Person <wbhL0478@163.com>
To: To Person <wbhL0478@163.com>
Subject: test email
This is a test e-mail message.
"""
try:
smtpObj = smtplib.SMTP(mail_host) #生成一个发送邮件服务器地址的对象
smtpObj.login(mail_user,mail_pwd) #连接上服务器登录
smtpObj.sendmail(sender, receivers, message) #发送邮件
print ("Successfully sent email")
except Exception as e:
print ("Error: unable to send email")
from celery_task.main import send_email
send_email.delay("wbhL0478@163.com",["wbhL0478@163.com",],"subject","this is content")
import os
import sys
import time
from celery import Celery
#执行celery命令时,需要进入CELERY_BASE_DIR目录执行
#celery项目中的所有导包地址,都是CELERY_BASE_DIR为基础设定
# CELERY_BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# sys.path.insert(0,CELERY_BASE_DIR) #增加导包路径
#定义celery实例,需要的参数 1,实例名
app = Celery('wbh',broker='redis://192.168.56.100:6379/14',backend='redis://192.168.56.100:6379/15')
@app.task
def send_email(sender,receivers,subject,content):
import smtplib
mail_host = 'smtp.163.com' # 发送邮件服务器
mail_user = 'wbhL0478@163.com' # 登录名
mail_pwd = 'VPAUITGNHJFNRVLN' # 密码
# sender = 'wbhL0478@163.com' # 发送人邮箱
# receivers = ['wbhL0478@163.com'] # 接收人邮箱
# 邮件内容
message = """From: From Person %s
To: To Person %s
Subject: %s
%s
"""%(sender,receivers[0],subject,content)
try:
smtpObj = smtplib.SMTP(mail_host) # 生成一个发送邮件服务器地址的对象
smtpObj.login(mail_user, mail_pwd) # 连接上服务器登录
smtpObj.sendmail(sender, receivers, message) # 发送邮件
return "Successfully sent email"
except Exception as e:
print("Error: unable to send email")
-
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
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
1.3 Celery基本c#教程命令 1、启动 Celery
celery -A celery_task.main worker -l info
2、查看有多少任务在消息队列中
127.0.0.1:6379 > llen celery
3、查看worker状态
celery -A main status
4、查看有多少任务正在运行
celery -A main inspect active
5、查看有多少任务接收了但还未执行
celery -A main inspect reserved
6、使用 flower 在线查vb.net教程 看
pip install flower
celery -A main flower
EOF
本文作者:IT老王同学_? 本文链接:https://www.cnblogs.com/laowang-wbh/p/14295385.html