def send_sms(mobile: str, content: str, templateId: str): """发送短信""" values = { 'accesskey': accesskey, 'secret': secret, 'sign': sign, 'templateId': templateId, 'mobile': mobile, 'content': content, }
data = urllib.parse.urlencode(values)
new_url = url + "?" + data
res = urllib.request.urlopen(new_url)
res_json = json.loads(res.read().decode('utf-8'))
return res_json
@celery_app.task(name='task_sms') def task_sms(phone, num): """任务派发短信通知""" result = send_sms(phone, num, task_templateId) print(result) return result
if name == 'main': import time
start = time.time()
send_community_sms.delay("18888888888", '{}##{}'.format('1111111111', '111111111111111'))
res = send_community_sms.delay("18888888888", '{}##{}'.format('1111111111', '111111111111111'))
print(res)
config.py from celery import Celery BROKER = 'redis://127.0.0.1:6379/4' BACKEND = 'redis://127.0.0.1:6379/5'
celery_app = Celery("baoanliezha", broker=BROKER, backend=BACKEND)
celery_app.autodiscover_tasks([ "celery_tasks.sms", ])
最后 res 打印返回 22bd44e2-8eeb-4e6e-aac6-1242b750b602
1
diwuqin OP 我靠怎么没有转行呢....
|
2
zouri 2020-06-09 17:26:21 +08:00
你为啥不舍得排版一下代码呢
|