diff --git a/safesite/tasks.py b/safesite/tasks.py index 58811e89..ef96d27c 100644 --- a/safesite/tasks.py +++ b/safesite/tasks.py @@ -35,16 +35,6 @@ def send_wechatmsgs(postdict,tolist): except: pass -@shared_task -def send_wechatmsgsu(postdict,tousers): - with open(dirname + 'token.txt','r',encoding= 'utf-8') as f: - token=f.read() - try: - for i in tousers: - postdict['touser']= User.object.get(userid=i).openid - requests.post('https://api.weixin.qq.com/cgi-bin/message/template/send?access_token='+token,data=json.dumps(postdict)) - except: - pass @shared_task def send_wechatmsg(postdict): diff --git a/safesite/views.py b/safesite/views.py index 4182a299..bfa5e816 100644 --- a/safesite/views.py +++ b/safesite/views.py @@ -13,7 +13,7 @@ import time from datetime import datetime,date,timedelta from django.db.models import F,Count,Sum import requests -from .tasks import send_wechatmsgs,send_wechatmsg,yjjs,gettime,yjjs_px,yjjs_yl,updateTzzs,updateAqzs,yjjs_gc,yjjs_ws,send_wechatmsgsu +from .tasks import send_wechatmsgs,send_wechatmsg,yjjs,gettime,yjjs_px,yjjs_yl,updateTzzs,updateAqzs,yjjs_gc,yjjs_ws from .export import exportdoc,exportxlsx,exportyjdoc,exportsimplexlsx,exportdoc2 from .daoru import drusers,drequipments,drrisks,drquestions,cal_riskact_level,cal_area_risk_level,makeqr,makeqr_train,makeqr_riskact,makeqr_examtest,makeqr_area from django.forms.models import model_to_dict @@ -4509,7 +4509,7 @@ def apioperation(req): postdict={ 'touser':'', 'template_id':'lOuwSE67vZC3ZVFYPZvz2eb7JdFxqx7ysMFkXrYmYh0', - "miniprogram":{"appid":"wx5c39b569f01c27db"}, + 'miniprogram':{'appid":"wx5c39b569f01c27db'}, 'data':{ 'first':{ 'value':obj.zylx.dickeyname + '作业审批:' @@ -4528,7 +4528,8 @@ def apioperation(req): } } } - send_wechatmsgsu.delay(postdict,sprs) + tolist = list(User.objects.filter(userid__in=sprs).values_list('openid',flat=True)) + send_wechatmsgs.delay(postdict,tolist) return JsonResponse({"code":1}) elif a == 'spzy': userid = req.session['userid'] @@ -4596,7 +4597,8 @@ def apioperation(req): } } } - send_wechatmsgsu.delay(postdict,newsprs) + tolist = list(User.objects.filter(userid__in=newsprs).values_list('openid',flat=True)) + send_wechatmsgs.delay(postdict,tolist) Operspxq.objects.create(oper=Operation.objects.get(zyid=zyid),jdmc=oldjdmc,spr=spruser,checked=2,spbm=spruser.ubelongpart) return JsonResponse({"code":1}) try: @@ -4628,7 +4630,8 @@ def apioperation(req): } } } - send_wechatmsgsu.delay(postdict,nextsplc['sprs']) + tolist = list(User.objects.filter(userid__in=nextsplc['sprs']).values_list('openid',flat=True)) + send_wechatmsgs.delay(postdict,tolist) Operspxq.objects.create(oper=Operation.objects.get(zyid=zyid),jdmc=oldjdmc,spr=spruser,checked=1,spbm=spruser.ubelongpart) except :