diff --git a/management/views.py b/management/views.py index 6fdbf7f..ee3da95 100644 --- a/management/views.py +++ b/management/views.py @@ -1,4 +1,5 @@ import json +from polls.utils import send_tnps from polls.models import Notice from django.contrib import messages @@ -1717,12 +1718,14 @@ def news_management_create(request): news = News(type=t, title=title, author=author, date=date, content=content, source=source, image=image) news.save() - if t== 5: - profiles = Userprofile.objects.filter(id=15) + if t == '5': + profiles = Userprofile.objects.filter(status=1) + content = '管理员发布了通知,请查收消息' + phones = [] for p in profiles: - content = '%s发布了通知,请查收消息' % (p, ) + phones.append(p.user.username) Notice.create_news_notice(p.user_id, content, news.id) - + send_tnps(phones, content) messages.success(request, '添加成功!!!') return HttpResponseRedirect('/management/news/management/create/') type = News.NEWMEDIA_NEWS_CHOICES diff --git a/polls/models.py b/polls/models.py index 25efd81..1284ea7 100644 --- a/polls/models.py +++ b/polls/models.py @@ -77,7 +77,7 @@ class Notice(models.Model): @classmethod def create_news_notice(cls, user_id, content, news_id): - return Notice.objects.create(user_id=user_id, content=content, news_id=news_id) + return Notice.objects.create(type=2, user_id=user_id, content=content, news_id=news_id) @classmethod def create_reply_notice(cls, user_id, content, app, model, field, record_id, record_pass_value, record_reject_value): diff --git a/polls/utils.py b/polls/utils.py index 07864f6..487dcbf 100644 --- a/polls/utils.py +++ b/polls/utils.py @@ -14,7 +14,6 @@ from aliyunsdkcore.profile import region_provider def send_tnps(phones, content): - url = 'https://api.tpns.tencent.com//v3/push/app' r = requests.post(url, auth=HTTPBasicAuth( @@ -23,11 +22,12 @@ def send_tnps(phones, content): "audience_type": "account_list", "account_list": phones, "message": { - "title": "【新媒体管理】有新消息", - "content": content + "title": content, + "content": '' }, "message_type": "notify" }) + return r def sent_sms_code(phone, code): @@ -166,4 +166,6 @@ if __name__ == '__main__': # 'http://xgs.gansudaily.com.cn/pages/h5/hot/b3297046a53e47f594ed19db90c1183c.html') # print(og_title, og_description, og_url, og_image) - print(send_voice_notify('13993199566')) + # print(send_voice_notify('13993199566')) + r = send_tnps(['13609346975'], '') + print(r.status_code, r.text) diff --git a/polls/views/__pycache__/media.cpython-38.pyc b/polls/views/__pycache__/media.cpython-38.pyc index 8e85cf8..6831a5b 100644 Binary files a/polls/views/__pycache__/media.cpython-38.pyc and b/polls/views/__pycache__/media.cpython-38.pyc differ diff --git a/polls/views/__pycache__/notice.cpython-38.pyc b/polls/views/__pycache__/notice.cpython-38.pyc index 569da4a..4bebd61 100644 Binary files a/polls/views/__pycache__/notice.cpython-38.pyc and b/polls/views/__pycache__/notice.cpython-38.pyc differ diff --git a/polls/views/__pycache__/task.cpython-38.pyc b/polls/views/__pycache__/task.cpython-38.pyc index 5bcf9fe..2ff5b5b 100644 Binary files a/polls/views/__pycache__/task.cpython-38.pyc and b/polls/views/__pycache__/task.cpython-38.pyc differ diff --git a/polls/views/media.py b/polls/views/media.py index b2a7df1..2a75c2a 100644 --- a/polls/views/media.py +++ b/polls/views/media.py @@ -1,3 +1,4 @@ +from polls.utils import send_tnps from django.http import HttpResponse, JsonResponse from django.views.decorators.csrf import csrf_exempt from django.core.paginator import Paginator @@ -80,17 +81,22 @@ def create_media(request): instance.save() if o.is_direct(): admins = Userprofile.level1_admin() + content = '%s创建了新媒体,请审核' % (profile,) + phones = [] for a in admins: - content = '%s创建了新媒体,请审核' % (profile,) + phones.append(a.user.username) Notice.create_reply_notice( a.user.id, content, 'dashboard', model_name, 'status', instance.id, '3', '0') + send_tnps(phones, content) else: admins = Userprofile.level2_admin(instance.organization.cities) + content = '%s创建了新媒体,请审核' % (profile,) + phones = [] for a in admins: - content = '%s创建了新媒体,请审核' % (profile,) + phones.append(a.user.username) Notice.create_reply_notice( a.user.id, content, 'dashboard', model_name, 'status', instance.id, '2', '0') - + send_tnps(phones, content) return JsonResponse({'status': 'success'}) @@ -228,19 +234,24 @@ def delete_media(request): instance.status = 5 instance.save() managers = Userprofile.level1_admin() + content = '%s申请注销新媒体,请审核' % (profile,) + phones = [] for a in managers: - content = '%s申请注销新媒体,请审核' % (profile,) + phones.append(a.user.username) Notice.create_reply_notice( a.user.id, content, 'dashboard', model_name, 'status', instance.id, '0', '3') + send_tnps(phones, content) else: instance.status = 4 instance.save() managers = Userprofile.level2_admin(instance.organization.cities) + content = '%s申请注销新媒体,请审核' % (profile,) + phones = [] for a in managers: - content = '%s申请注销新媒体,请审核' % (profile,) + phones.append(a.user.username) Notice.create_reply_notice( a.user.id, content, 'dashboard', model_name, 'status', instance.id, '5', '3') - + send_tnps(phones, content) admins = [] for admin in instance.organization.userprofile_set.all(): u = dict() @@ -292,10 +303,13 @@ def media_admin_change(request): profile.admin_status = 5 profile.save() managers = Userprofile.level1_admin() + content = '%s申请变更管理员,请审核' % (operator,) + phones = [] for a in managers: - content = '%s申请变更管理员,请审核' % (operator,) + phones.append(a.user.username) Notice.create_reply_notice( a.user.id, content, 'dashboard', 'Userprofile', 'admin_status', o.id, '3', '0') + send_tnps(phones, content) return JsonResponse({'status': 'success', 'message': '变更申请发送成功'}) else: obj, created = UserModel.objects.get_or_create( @@ -309,8 +323,11 @@ def media_admin_change(request): profile.admin_status = 4 profile.save() managers = Userprofile.level2_admin(o.cities) + content = '%s申请变更管理员,请审核' % (operator,) + phones = [] for a in managers: - content = '%s申请变更管理员,请审核' % (operator,) + phones.append(a.user.username) Notice.create_reply_notice( a.user.id, content, 'dashboard', 'Userprofile', 'admin_status', o.id, '2', '0') + send_tnps(phones, content) return JsonResponse({'status': 'success', 'message': '变更申请发送成功'}) diff --git a/polls/views/notice.py b/polls/views/notice.py index 76d0a67..6a9eb7d 100644 --- a/polls/views/notice.py +++ b/polls/views/notice.py @@ -1,3 +1,4 @@ +from polls.utils import send_tnps from django.shortcuts import render from django.http import HttpResponse, JsonResponse from django.views.decorators.csrf import csrf_exempt @@ -152,9 +153,12 @@ def pass_notice(request): n.is_read = True n.save() admins = Userprofile.level1_admin() + phones = [] for a in admins: + phones.append(a.user.username) Notice.create_reply_notice( a.user.id, notice.content, notice.app, notice.model, notice.field, notice.record_id, '3', '0') + send_tnps(phones, notice.content) else: # 省级提交 for p in profiles: if p.admin_status == 5: @@ -181,14 +185,20 @@ def pass_notice(request): pass_value = notice.record_pass_value if pass_value == '2': admins = Userprofile.level1_admin() + phones = [] for a in admins: + phones.append(a.user.username) Notice.create_reply_notice( a.user.id, notice.content, notice.app, notice.model, notice.field, notice.record_id, '3', '0') + send_tnps(phones, notice.content) if pass_value == '5': admins = Userprofile.level1_admin() + phones = [] for a in admins: + phones.append(a.user.username) Notice.create_reply_notice( a.user.id, notice.content, notice.app, notice.model, notice.field, notice.record_id, '0', '3') + send_tnps(phones, notice.content) return JsonResponse({'status': 'success', 'message': '申请已同意'}) except ObjectDoesNotExist: return JsonResponse({'status': 'error', 'message': '通知ID错误'}) diff --git a/polls/views/task.py b/polls/views/task.py index 5c61416..8398ec6 100644 --- a/polls/views/task.py +++ b/polls/views/task.py @@ -6,7 +6,7 @@ import datetime from polls.decorators import polls_login_required from polls.models import Message, Notice, Task, TaskAddition, TaskRecord from django.core.exceptions import ObjectDoesNotExist -from polls.utils import model_to_dict, queryset_to_list, parse +from polls.utils import model_to_dict, queryset_to_list, parse, send_tnps from dashboard.models import Group, Group_user, Userprofile @@ -72,6 +72,7 @@ def create_task(request): if profile and profile.status == 1: content = '%s在群组“%s”发布了任务,请查收消息' % (profile, g.name) Notice.create_normal_notice(u.user_id, content, group) + send_tnps([u.username], content) return JsonResponse({'status': 'success'})