Init
0 parents
Showing
38 changed files
with
756 additions
and
0 deletions
.DS_Store
0 → 100644
No preview for this file type
.gitignore
0 → 100644
Dockerfile
0 → 100644
1 | # 使用方 Python 基础镜像作为基础 | ||
2 | FROM python:3.7.4 | ||
3 | |||
4 | # 设置工目录 | ||
5 | WORKDIR / | ||
6 | |||
7 | RUN apt-get update && apt-get install -y libsndfile1 ffmpeg | ||
8 | |||
9 | # 将 requirements.txt 复到容器中 | ||
10 | COPY requirements.txt . | ||
11 | |||
12 | # 安装赖包 | ||
13 | RUN pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ | ||
14 | # 将整个项目复制到容器中 | ||
15 | COPY . . | ||
16 | |||
17 | # 运行 Django 服务器 | ||
18 | CMD python manage.py runserver 0.0.0.0:8000 | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
HisinApi/.DS_Store
0 → 100644
No preview for this file type
HisinApi/__init__.py
0 → 100644
HisinApi/asgi.py
0 → 100644
1 | """ | ||
2 | ASGI config for HisinApi project. | ||
3 | |||
4 | It exposes the ASGI callable as a module-level variable named ``application``. | ||
5 | |||
6 | For more information on this file, see | ||
7 | https://docs.djangoproject.com/en/4.0/howto/deployment/asgi/ | ||
8 | """ | ||
9 | |||
10 | import os | ||
11 | |||
12 | from django.core.asgi import get_asgi_application | ||
13 | |||
14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'HisinApi.settings') | ||
15 | |||
16 | application = get_asgi_application() |
HisinApi/urls.py
0 → 100644
1 | """HisinApi URL Configuration | ||
2 | |||
3 | The `urlpatterns` list routes URLs to views. For more information please see: | ||
4 | https://docs.djangoproject.com/en/4.0/topics/http/urls/ | ||
5 | Examples: | ||
6 | Function views | ||
7 | 1. Add an import: from my_app import views | ||
8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') | ||
9 | Class-based views | ||
10 | 1. Add an import: from other_app.views import Home | ||
11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') | ||
12 | Including another URLconf | ||
13 | 1. Import the include() function: from django.urls import include, path | ||
14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) | ||
15 | """ | ||
16 | from django.contrib import admin | ||
17 | from django.urls import path | ||
18 | from api.ApiList import login,index,audition,my,notifications,appversion,community | ||
19 | |||
20 | urlpatterns = [ | ||
21 | #登录注册模块 | ||
22 | path('admin', admin.site.urls), | ||
23 | path('', index.index), | ||
24 | path('api/sendsms',login.sendsms), | ||
25 | path('api/v2/sendsms', login.v2sendsms), | ||
26 | path('api/login', login.user_login), | ||
27 | path('api/sms_verify/login', login.sms_verify_login), | ||
28 | path('api/wechat/auth', login.wechatAuth), | ||
29 | path('api/register', login.register), | ||
30 | path('api/v2/register', login.v2register), | ||
31 | path('api/v3/register', login.v3register), | ||
32 | path('api/reset', login.restPwd), | ||
33 | path('api/business_list', login.businessList), | ||
34 | #首页模块 | ||
35 | path('api/user', index.user), | ||
36 | path('api/activity/view', index.UserViewActivity), | ||
37 | path('api/examines', index.Examines.as_view()), #注册用户待审核列表 | ||
38 | path('api/activitys', index.GetActivitys.as_view()), | ||
39 | path('api/v2/activitys', index.V2GetActivitys.as_view()), #去掉收藏活动 | ||
40 | path('api/v3/activitys', index.V3GetActivitys.as_view()), #加入收藏活动 | ||
41 | path('api/examine_status', index.examineStatus.as_view()), | ||
42 | path('api/banner', index.banners), | ||
43 | path('api/v2/banner', index.v2banners), | ||
44 | path('api/banner/detail', index.bannerDetail), | ||
45 | path('api/activity/attend_user',index.GetActivityUser.as_view() ), | ||
46 | path('api/activity/unlike', index.Unlike.as_view()), | ||
47 | path('api/activity/completes', index.GetCompleteActivity.as_view()), | ||
48 | path('api/events', index.Events), | ||
49 | path('api/action', index.Action), | ||
50 | path('api/band_list', index.BandList.as_view()), | ||
51 | path('api/band_detail', index.BandDetail.as_view()), | ||
52 | path('api/band_link_activity', index.BandLinkActivity.as_view()), | ||
53 | path('api/activity/recommend', index.RecommenCasedList.as_view()), | ||
54 | |||
55 | #我的模块 | ||
56 | path('api/upload', my.upload), | ||
57 | path('api/user/avatar',my.updateUserAvatar), | ||
58 | path('api/user/activitys',my.MyActivitys.as_view()), | ||
59 | path('api/user/activity_detail', my.SaveOrSubmitList), | ||
60 | path('api/v2/user/activity_detail', my.V2SaveOrSubmitList), | ||
61 | path('api/user/activity_sumbit', my.UpdateSumbit), | ||
62 | path('api/user/submit_examine', my.SubmitExamine), | ||
63 | path('api/v2/user/submit_examine', my.V2SubmitExamine), | ||
64 | path('api/user/set_tag', my.SetUserTags), | ||
65 | path('api/user/tag_list', my.getUserTag), | ||
66 | path('api/user/unbind', my.unbind), | ||
67 | path('api/user/bind', my.bind), | ||
68 | path('api/admin/activitys', my.AdminActivitys.as_view()), | ||
69 | path('api/admin/submit_list', my.AdminSubmitList), | ||
70 | path('api/v2/admin/submit_list', my.V2AdminSubmitList), | ||
71 | path('api/user/singer_list', my.MySinget.as_view()), | ||
72 | path('api/user/singer', my.SingerInfo.as_view()), | ||
73 | path('api/v2/user/singer', my.SingerInfoV2.as_view()), | ||
74 | path('api/user/singer/avtivitys', my.SingerAvtivity.as_view()), | ||
75 | path('api/user/singer/complete', my.SingerComplete.as_view()), #我的歌手-被选中 | ||
76 | path('api/user/singer/avtivity_detail', my.AvtivityDetail.as_view()), | ||
77 | path('api/user/banner', my.banners), | ||
78 | path('api/user/listen', my.Listen.as_view()), | ||
79 | path('api/user/ta_collection', my.TaCollection.as_view()), | ||
80 | path('api/user/ta_audition', my.TaAudition.as_view()), | ||
81 | path('api/user/resume_like', my.ResumeLike.as_view()), | ||
82 | path('api/user/remove_save', my.remove_save), | ||
83 | path('api/user/editor', my.editor), | ||
84 | path('api/user/change_phone', my.change_phone), | ||
85 | path('api/user/sound', my.UserSound.as_view()), | ||
86 | path('api/user/home', my.UserHome.as_view()), | ||
87 | path('api/user/tidings', my.UserTidings.as_view()), | ||
88 | path('api/user/follow', my.UserFollow.as_view()), | ||
89 | path('api/user/following', my.UserFollowing.as_view()), | ||
90 | path('api/user/find_singer', my.FindSinger.as_view()), | ||
91 | path('api/user/visitors', my.Visitors.as_view()), | ||
92 | path('api/user/remove_device', my.RemoveDevice.as_view()), | ||
93 | path('api/user/avtivitys/price', my.AvtivitysPrice.as_view()), | ||
94 | path('api/avtivitys/price_info', my.AvtivitysPriceInfo.as_view()), | ||
95 | |||
96 | |||
97 | #管理员查看试唱确认合作 | ||
98 | path('api/admin/activity/confirm',my.ConfirmSinger), | ||
99 | #注销账号 | ||
100 | path('api/user/delete', my.UserDelete), | ||
101 | |||
102 | #试唱模块 | ||
103 | path('api/audition/materials', audition.AuditionMaterials), #小程序端物料,要升降调文件 | ||
104 | path('api/activity/materials', audition.ActivityMaterials), #app 端物料,无须升降调文件 | ||
105 | path('api/audition/send_materials', audition.SendMaterials), #自主上传方式发送物料 | ||
106 | path('api/audition/split_audio', audition.SplitAudio), | ||
107 | path('api/audition/auto_submit', audition.AotoSubmit), | ||
108 | path('api/audition/online_save', audition.OnlineSave), | ||
109 | path('api/audition/join', audition.JoinActivity), # APP线上保存或提交 | ||
110 | path('api/audition/upload', audition.UploadAudio), | ||
111 | path('api/audition/mixin_preview', audition.MixinPreview), | ||
112 | path('api/audition/part_preview', audition.PartPreview), | ||
113 | path('api/audition/mixin_check', audition.MixinCheck), | ||
114 | path('api/audition/collection', audition.Collection.as_view()), | ||
115 | path('api/audition/remove_collection', audition.cancelcollection), | ||
116 | #活动确定分享人 | ||
117 | path('api/audition/share_users_list', audition.ShareUsersList.as_view()), | ||
118 | path('api/audition/share_users', audition.ShareUsers.as_view()), | ||
119 | |||
120 | #社区模块 | ||
121 | path('api/community/tidings', community.Tidings.as_view()), | ||
122 | path('api/community/tidings/selete_activity', community.SeleteActivity.as_view()), | ||
123 | path('api/community/tidings_list', community.TidingsList.as_view()), | ||
124 | path('api/community/tidings/show', community.TidingsShow.as_view()), | ||
125 | path('api/community/tidings/limiting', community.TidingsLimiting.as_view()), | ||
126 | path('api/community/tidings/report', community.TidingsReport.as_view()), | ||
127 | path('api/community/tidings/record_user', community.RecordUser.as_view()), | ||
128 | path('api/community/tidings/interacts',community.TidingsInteracts.as_view()), | ||
129 | path('api/community/tidings/chat', community.TidingsChat.as_view()), | ||
130 | path('api/community/chat/relation', community.ChatRelation.as_view()), | ||
131 | path('api/community/chat/agent', community.ChatAgent.as_view()), | ||
132 | path('api/community/chat/agent_record', community.ChatAgentRecord.as_view()), | ||
133 | path('api/community/unlike', community.Unlike.as_view()), | ||
134 | path('api/community/tidings/comments', community.TidingsComments.as_view()), #动态评论 | ||
135 | |||
136 | #消息通知模块 | ||
137 | path('api/notifica/read_message', notifications.read), | ||
138 | path('api/notifica/system_message', notifications.SystemMessage.as_view()), | ||
139 | |||
140 | #极光推送 | ||
141 | path('api/notifica/push', notifications.push_notifications), | ||
142 | |||
143 | #积分接口 | ||
144 | path('api/user/point', my.UserPoint.as_view()), | ||
145 | |||
146 | # 用户协议 | ||
147 | path('h5/user_agreement', index.useragreement), | ||
148 | #分享活动页面 | ||
149 | path('h5/share/<id>/', index.songshare), | ||
150 | |||
151 | # 分享动态页面 | ||
152 | # path('h5/sharetidings/<id>/', index.tidingsshare), | ||
153 | # app分享页面 | ||
154 | path('h5/shareapp/', index.appshare), | ||
155 | #版本更新 | ||
156 | path('api/app/version', appversion.versioninfo), | ||
157 | |||
158 | #获取app分享内容 | ||
159 | path('api/share/dictionary_list', my.sharechildlist), | ||
160 | path('api/share/dictionary', my.sharechild), | ||
161 | |||
162 | |||
163 | #客服列表 | ||
164 | path('api/customer_service', my.CustomerService.as_view()), | ||
165 | ] | ||
166 |
HisinApi/wsgi.py
0 → 100644
1 | """ | ||
2 | WSGI config for HisinApi project. | ||
3 | |||
4 | It exposes the WSGI callable as a module-level variable named ``application``. | ||
5 | |||
6 | For more information on this file, see | ||
7 | https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/ | ||
8 | """ | ||
9 | |||
10 | import os | ||
11 | |||
12 | from django.core.wsgi import get_wsgi_application | ||
13 | |||
14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'HisinApi.settings') | ||
15 | |||
16 | application = get_wsgi_application() |
README.md
0 → 100644
1 | #### Python版本 | ||
2 | - Python 3.7.0 | ||
3 | |||
4 | #### 依赖安装 | ||
5 | - pip install -r requirements.txt | ||
6 | |||
7 | #### 本地项目启动命令 | ||
8 | - python manage.py runserver | ||
9 | |||
10 | |||
11 | #### 线上项目进程管理,启动/更新 | ||
12 | - 服务已经配置supervisor进程管理 | ||
13 | - git pull拉取代码后会更新服务 | ||
14 | |||
15 | #### 主要目录结构说明 | ||
16 | > HisinApi 文件主目录 | ||
17 | >> api 接口编写主目录 | ||
18 | > > > ApiList 接口模块列表 | ||
19 | > > > | ||
20 | > > > jobs 定时任务脚本 | ||
21 | > > > | ||
22 | > > > templates 页面文件 | ||
23 | > > > | ||
24 | > > > admin.py | ||
25 | > > > | ||
26 | > > > apps.py | ||
27 | > > > | ||
28 | > > > loggin.py 日志模块 | ||
29 | > > > | ||
30 | > > > models.py 数据表模型文件 | ||
31 | > > > | ||
32 | > > > serializers.py 接口返回数据序列化,定义返回字段和结构 | ||
33 | > > > | ||
34 | > > > tests.py | ||
35 | > > > | ||
36 | > > > verification.py 接口接受参数校验文件 | ||
37 | > > > | ||
38 | > > > views.py 接口通用方法都写在这里 | ||
39 | >> | ||
40 | >> HisinApi 项目环境配置 | ||
41 | > > > settings.py 环境配置文件 | ||
42 | > > > | ||
43 | > > > urls.py 接口路由定义文件 | ||
44 | > > | ||
45 | > > manage.py 项目启动文件 | ||
46 | > > | ||
47 | > > requirements.txt 项目依赖文件 | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
api/.DS_Store
0 → 100644
No preview for this file type
api/ApiList/appversion.py
0 → 100644
1 | from api import models | ||
2 | from api.views import ResponseFactory | ||
3 | from django.http import JsonResponse | ||
4 | from api import serializers | ||
5 | |||
6 | def versioninfo(requests): | ||
7 | """ | ||
8 | 版本更新信息 | ||
9 | :param requests: | ||
10 | :return: | ||
11 | """ | ||
12 | if requests.method != 'GET': | ||
13 | return JsonResponse(ResponseFactory(code=400, message="不支持的请求方法", data=None, status='fail')) | ||
14 | os = requests.GET['os'] | ||
15 | app_version = requests.GET['app_version'] | ||
16 | # verobject = models.AppVersion.objects.filter(os=os,app_ver__gt=app_version,deleted_at=None).first() | ||
17 | # if verobject:data = serializers.AppVersionSerializer(models.AppVersion.objects.filter(os=os,deleted_at=None).last(),many=False,context={"app_version":app_version,"os":os}).data | ||
18 | # else:data = serializers.AppVersionSerializer(models.AppVersion.objects.filter(os=os,deleted_at=None).last(),many=False,context={"app_version":app_version,"os":os}).data | ||
19 | data = serializers.AppVersionSerializer(models.AppVersion.objects.filter(os=os, deleted_at=None).last(), many=False,context={"app_version": app_version, "os": os}).data | ||
20 | return JsonResponse(ResponseFactory(code=200, message="获取成功", data=data, status='success')) | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
api/ApiList/audition.py
0 → 100644
This diff is collapsed.
Click to expand it.
api/ApiList/community.py
0 → 100644
This diff is collapsed.
Click to expand it.
api/ApiList/index.py
0 → 100644
This diff is collapsed.
Click to expand it.
api/ApiList/login.py
0 → 100644
This diff is collapsed.
Click to expand it.
api/ApiList/my.py
0 → 100644
This diff is collapsed.
Click to expand it.
api/ApiList/notifications.py
0 → 100644
1 | from api.views import AuthPermissionRequired,get_user_info | ||
2 | from django.http import JsonResponse | ||
3 | from api.views import ResponseFactory,PageNumberPagination,GetWxToken,pushSubscribeMessage,WeChatApi,JPush | ||
4 | from rest_framework.decorators import api_view | ||
5 | from api import models,verification,serializers | ||
6 | import json | ||
7 | from django.utils.decorators import method_decorator | ||
8 | from rest_framework.views import APIView | ||
9 | |||
10 | |||
11 | def push_notifications(request): | ||
12 | if request.method != "POST": | ||
13 | return JsonResponse(ResponseFactory(code=400, message="不支持的请求方法", data=None, status='fail')) | ||
14 | post_data = json.loads(request.body) | ||
15 | obj = verification.PushNotifications(post_data) | ||
16 | if not obj.is_valid(): | ||
17 | return JsonResponse(ResponseFactory(code=400, message=verification.error_message(obj), data=None, status='fail')) | ||
18 | obj = obj.clean() | ||
19 | jdata = {"title": obj.get('title'), "content": obj.get('content'), "content_type": "text", | ||
20 | "receiver_value": obj.get('receivers'), | ||
21 | "extras": {"type": post_data.get('type',""), "value": post_data.get('value',"")}} | ||
22 | result = JPush().jpush_v3(jdata) | ||
23 | return JsonResponse(result) | ||
24 | |||
25 | @AuthPermissionRequired() | ||
26 | def read(request): | ||
27 | put_data = json.loads(request.body) | ||
28 | user_id = get_user_info(request)['id'] | ||
29 | if request.method == "PUT": | ||
30 | type = put_data.get('type') | ||
31 | #我的歌手审核消息已读 | ||
32 | if type == 1: | ||
33 | models.UserMessages.objects.filter(type=type,receiver_id=user_id,sender_id=put_data['sender_id'],deleted_at=None).update(is_read=1) | ||
34 | return JsonResponse(ResponseFactory(code=200, message="已阅读", data=None, status='success')) | ||
35 | # 我的歌手收藏消息已读 | ||
36 | elif type == 2: | ||
37 | models.UserMessages.objects.filter(type=type,receiver_id=user_id,deleted_at=None).update(is_read=1) | ||
38 | return JsonResponse(ResponseFactory(code=200, message="已阅读", data=None, status='success')) | ||
39 | # 我的歌手或平台用户试唱消息已读(注意区分是绑定用户,还是平台用户) | ||
40 | elif type == 3: | ||
41 | models.UserMessages.objects.filter(type=type,sender_id=put_data['sender_id'],receiver_id=user_id,activity_id=put_data['activity_id'],is_bind=put_data['is_bind'],deleted_at=None).update(is_read=1) | ||
42 | return JsonResponse(ResponseFactory(code=200, message="已阅读", data=None, status='success')) | ||
43 | #系统消息已读 | ||
44 | elif type == 4: | ||
45 | models.UserMessages.objects.filter(type__in=[4,5,6,7,8,9,10,11,12,13,14], receiver_id=user_id, deleted_at=None).update(is_read=1) | ||
46 | return JsonResponse(ResponseFactory(code=200, message="已阅读", data=None, status='success')) | ||
47 | else: | ||
48 | return JsonResponse(ResponseFactory(code=400, message="不支持的请求方法", data=None, status='fail')) | ||
49 | |||
50 | |||
51 | class SystemMessage(APIView): | ||
52 | @method_decorator(AuthPermissionRequired()) | ||
53 | def get(self,request): | ||
54 | user_id = get_user_info(request)['id'] | ||
55 | queryset = models.UserMessages.objects.filter(type__in=[4,5,6,7,8,9,10,11,12,13,14],receiver_id=user_id,deleted_at=None).order_by('-created_at') | ||
56 | page_obj = PageNumberPagination() | ||
57 | page_data = page_obj.paginate_queryset(queryset, request) | ||
58 | ser_obj = serializers.SystemMessageSerializer(page_data, many=True) | ||
59 | data = {"message": ser_obj.data, "count": queryset.count()} | ||
60 | return JsonResponse(ResponseFactory(code=200, message="获取成功", data=data, status='success')) | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
api/TLSSigAPIv2.py
0 → 100644
This diff is collapsed.
Click to expand it.
api/__init__.py
0 → 100644
File mode changed
api/admin.py
0 → 100644
1 | from django.contrib import admin |
api/apps.py
0 → 100644
api/jobs/__init__.py
0 → 100644
File mode changed
api/jobs/job.py
0 → 100644
File mode changed
api/loggin.py
0 → 100644
api/middleware/ApiLoggingMiddleware.py
0 → 100644
1 | import jwt | ||
2 | import json | ||
3 | from HisinApi import settings | ||
4 | from api.models import SystemHttpLogs | ||
5 | from django.utils import timezone | ||
6 | from api.views import object_to_json | ||
7 | import time | ||
8 | from api.loggin import logger | ||
9 | |||
10 | |||
11 | |||
12 | class ApiLogs(object): | ||
13 | |||
14 | def __init__(self, get_response): | ||
15 | self.get_response = get_response | ||
16 | |||
17 | def __call__(self, request): | ||
18 | response = self.get_response(request) | ||
19 | try: | ||
20 | body = json.loads(request.body.decode('utf-8')) | ||
21 | except: | ||
22 | body = {} | ||
23 | header = object_to_json(request.headers)['_store'] | ||
24 | if request.method == 'GET': | ||
25 | query = request.GET | ||
26 | else: | ||
27 | query = request.POST | ||
28 | request_data = {"body":body,"header":header,"query":query} | ||
29 | try:body = json.loads( response._container[0].decode('utf-8')) | ||
30 | except: body = None | ||
31 | response_data = {"body":body, "header": object_to_json(response.headers)['_store'],"code":response.status_code} | ||
32 | try: | ||
33 | try: | ||
34 | auth = request.META.get('HTTP_AUTHORIZATION').split() | ||
35 | dict = jwt.decode(auth[1], settings.SECRET_KEY, algorithms=['HS256']) | ||
36 | user_id = dict.get('data').get('id') | ||
37 | except: | ||
38 | user_id = 0 | ||
39 | SystemHttpLogs( | ||
40 | guard='App', | ||
41 | user_id=user_id, | ||
42 | method=request.method, | ||
43 | uri=request.path, | ||
44 | ip=request.META['REMOTE_ADDR'], | ||
45 | request=request_data, | ||
46 | response=response_data, | ||
47 | consume =response.headers['time'], | ||
48 | created_at=timezone.now().strftime("%Y-%m-%d %H:%M:%S")).save() | ||
49 | except Exception as e: | ||
50 | logger.info('API Log Error:{}'.format(e)) | ||
51 | return response | ||
52 | |||
53 | |||
54 | class ResponseTime: | ||
55 | def __init__(self, get_response): | ||
56 | self.get_response = get_response | ||
57 | |||
58 | def __call__(self, request): | ||
59 | start_time = time.time() | ||
60 | response = self.get_response(request) | ||
61 | duration = time.time() - start_time | ||
62 | response["time"] = int(duration * 1000) | ||
63 | return response | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
api/models.py
0 → 100644
This diff is collapsed.
Click to expand it.
api/schedules.py
0 → 100644
1 | |||
2 | import time | ||
3 | import schedule | ||
4 | import threading | ||
5 | from api import models | ||
6 | from django.utils import timezone | ||
7 | from django.db.models import F, Func | ||
8 | from django.db.models.functions import Now | ||
9 | |||
10 | def project_confirmation_times(): | ||
11 | projects = models.Projects.objects.filter(status=1,deleted_at=None) | ||
12 | for project in projects: | ||
13 | #匹配的活动均值 | ||
14 | l1 = list() | ||
15 | days_diff = Func(F('match_at') - F('publish_at'), function='ABS') | ||
16 | results = models.Activitys.objects.filter(status__in=[3,5],project_id=project.id).annotate(days_diff=days_diff) | ||
17 | for result in results: | ||
18 | try:l1.append(result.days_diff.days) | ||
19 | except:l1.append(0) | ||
20 | # 未匹配的活动均值 | ||
21 | days_diff = Func(Now() - F('publish_at'),function='ABS') | ||
22 | deltas = models.Activitys.objects.filter(status=1,project_id=project.id).annotate(days_diff=days_diff) | ||
23 | for delta in deltas: | ||
24 | try:l1.append(delta.days_diff.days) | ||
25 | except:pass | ||
26 | try:mean = sum(l1) / len(l1) | ||
27 | except: mean = 0 | ||
28 | models.ProjectConfirmationTime.objects.update_or_create( | ||
29 | project_id=project.id, | ||
30 | defaults={'average_day': mean,'created_at':timezone.now().strftime("%Y-%m-%d %H:%M:%S"),'updated_at':timezone.now().strftime("%Y-%m-%d %H:%M:%S")} | ||
31 | ) | ||
32 | |||
33 | def job1(): | ||
34 | threading.Thread(target=project_confirmation_times).start() | ||
35 | |||
36 | schedule.every().day.at("02:00").do(job1) | ||
37 | # schedule.every(1).minutes.do(job1) | ||
38 | |||
39 | def run(): | ||
40 | while True: | ||
41 | schedule.run_pending() | ||
42 | time.sleep(1) | ||
43 | |||
44 | |||
45 |
api/serializers.py
0 → 100644
This diff is collapsed.
Click to expand it.
api/templates/appshare.html
0 → 100644
This diff is collapsed.
Click to expand it.
api/templates/index.html
0 → 100644
File mode changed
api/templates/share.html
0 → 100644
This diff could not be displayed because it is too large.
api/templates/user_agreement.html
0 → 100644
This diff is collapsed.
Click to expand it.
api/tests.py
0 → 100644
1 | # -*-coding:utf-8 -*- | ||
2 | import os | ||
3 | import requests | ||
4 | from pydub import AudioSegment | ||
5 | from django.core.cache import caches | ||
6 | import time, random, json | ||
7 | import base64 | ||
8 | import hashlib | ||
9 | from Crypto.Cipher import AES | ||
10 | from Crypto import Random | ||
11 | |||
12 | appid = "wx0f3844b1458ccfb9" | ||
13 | secret = "f9fa09c6cf3b4db19906d876d9c64755" | ||
14 | |||
15 | def split_mp3(): | ||
16 | |||
17 | new_name = './static/out444.mp3' | ||
18 | use_name = './static/12345.mp3' | ||
19 | input_music = AudioSegment.from_mp3(use_name) | ||
20 | # 截取音频后31000毫秒 = 31秒 | ||
21 | output_music = input_music[31000:] | ||
22 | # 保存音频,指定音频比特率为64k | ||
23 | output_music.export(new_name, bitrate="64k") | ||
24 | print(new_name + '完成!') | ||
25 | |||
26 | |||
27 | def WeChatApi(code): | ||
28 | appid = "wx0f3844b1458ccfb9" | ||
29 | secret = "f9fa09c6cf3b4db19906d876d9c64755" | ||
30 | parmas = { | ||
31 | 'appid': appid, | ||
32 | 'secret': secret, | ||
33 | 'js_code': code, | ||
34 | 'grant_type': 'authorization_code' | ||
35 | } | ||
36 | url = 'https://api.weixin.qq.com/sns/jscode2session' | ||
37 | r = requests.get(url, params=parmas).json() | ||
38 | print (r) | ||
39 | try: | ||
40 | return r['openid'],r['unionid'] | ||
41 | except: | ||
42 | return None,None | ||
43 | |||
44 | def get_access_toke(): | ||
45 | url = 'https://api.weixin.qq.com/cgi-bin/token' | ||
46 | parmas = { | ||
47 | "grant_type":"client_credential", | ||
48 | "appid":appid, | ||
49 | "secret":secret | ||
50 | } | ||
51 | r = requests.get(url,params=parmas).json() | ||
52 | print (r) | ||
53 | |||
54 | |||
55 | def WxPushInfo(data): | ||
56 | nickname = data['nickname'] | ||
57 | result = data['result'] | ||
58 | remarks = data['remarks'] | ||
59 | touser = data['touser'] | ||
60 | access_token = data['access_token'] | ||
61 | url = 'https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token={}'.format(access_token) | ||
62 | postdata = { | ||
63 | "touser":touser, | ||
64 | "template_id":"B0s4RIurXwoegzK4tLWNU_H-xB2kUIE_E_ft5Ur6Auk", | ||
65 | "data":{ | ||
66 | "name10":{"value":nickname}, | ||
67 | "phrase5":{"value":result}, | ||
68 | "thing11":{"value":remarks} | ||
69 | } | ||
70 | } | ||
71 | r = requests.post(url, json=postdata).json() | ||
72 | print(r) | ||
73 | |||
74 | def GetWxToken(): | ||
75 | token = caches['default'].get('wx_access_token') | ||
76 | if not token: | ||
77 | appid = "wx0f3844b1458ccfb9" | ||
78 | secret = "f9fa09c6cf3b4db19906d876d9c64755" | ||
79 | url = 'https://api.weixin.qq.com/cgi-bin/token' | ||
80 | parmas = { | ||
81 | "grant_type":"client_credential", | ||
82 | "appid":appid, | ||
83 | "secret":secret | ||
84 | } | ||
85 | r = requests.get(url,params=parmas).json() | ||
86 | caches['default'].add('wx_access_token', r['access_token'] , r['expires_in']) #expires_in | ||
87 | return r['access_token'] | ||
88 | else: | ||
89 | return token | ||
90 | |||
91 | def Test(data): | ||
92 | import hashlib | ||
93 | channel = 'register_audit_channel' | ||
94 | open_id = data['open_id'] | ||
95 | url = 'http://hi-sing-admin-dev.hikoon.com/api/provider/wechat/pushSubscribeMessage' | ||
96 | md5_str = channel + open_id + 'tb0iwb7TE9TIbkG8iFsxldrHJRFdeP1g' | ||
97 | hl = hashlib.md5() | ||
98 | hl.update(md5_str.encode(encoding='utf8')) | ||
99 | secret = hl.hexdigest() | ||
100 | data = { | ||
101 | 'secret': secret, | ||
102 | 'channel': channel, | ||
103 | 'open_id': open_id, | ||
104 | 'data': data['data'] | ||
105 | } | ||
106 | r = requests.post(url,json=data).json() | ||
107 | print (r) | ||
108 | |||
109 | def test(): | ||
110 | import requests | ||
111 | url = "127.0.0.1:8000/api/register" | ||
112 | payload = { | ||
113 | "nick_name": "🍹🐼💑", | ||
114 | "real_name": "魏晗13457", | ||
115 | "phone": "17780983939", | ||
116 | "email": "17qwe111@qq.com", | ||
117 | "origin_type": "Other", | ||
118 | "remarks": "黄辉浩", | ||
119 | "role": "SystemUser", | ||
120 | "password": "112358ys", | ||
121 | "confirm_password": "112358ys", | ||
122 | "sms_code": 123456, | ||
123 | "vx_code":"051vPN000xA8EN1rW2100URGiX3vPN0t" | ||
124 | } | ||
125 | headers = { | ||
126 | 'Content-Type': 'application/json' | ||
127 | } | ||
128 | response = requests.request("POST", url, headers=headers, json=payload) | ||
129 | |||
130 | print(response.text) | ||
131 | |||
132 | |||
133 | def toMp3(): | ||
134 | import os | ||
135 | path = './static/' | ||
136 | file = '1234.m4a' | ||
137 | os.system("ffmpeg -i "+ path+file+ " " + path+ ".mp3" ) | ||
138 | |||
139 | |||
140 | |||
141 | class JPush(): | ||
142 | |||
143 | def __init__(self): | ||
144 | self.app_key = '860a3d4ecfaf3c38eb539c4e' | ||
145 | self.master_secret = 'df208c0eb485ed3ab3b18ff2' | ||
146 | |||
147 | def https_request(self, body, url, content_type=None, version=None, params=None): | ||
148 | https = requests.Session() | ||
149 | https.auth = (self.app_key,self.master_secret) | ||
150 | headers = {} | ||
151 | headers['user-agent'] = 'jpush-api-python-client' | ||
152 | headers['connection'] = 'keep-alive' | ||
153 | headers['content-type'] = 'application/json;charset:utf-8' | ||
154 | response = https.request('POST', url, data=body, params=params, headers=headers) | ||
155 | print (response.text) | ||
156 | print (dict(json.loads(response.content), **{'status_code': response.status_code})) | ||
157 | return dict(json.loads(response.content), **{'status_code': response.status_code}) | ||
158 | |||
159 | |||
160 | def push_params_v3(self,title,content, receiver_value=None,content_type=None, extras=None, platform="ios,android"): | ||
161 | sendno = int(random.randint(1, 999)) | ||
162 | payload = dict() | ||
163 | payload['platform'] = platform | ||
164 | payload['audience'] = { | ||
165 | "alias": receiver_value | ||
166 | } | ||
167 | payload["inapp_message"] = {"inapp_message": False} | ||
168 | payload['notification'] = { | ||
169 | "android": {"alert": content,"badge_add_num": 1,"alternate_alert": "","style": 0,"category": "","priority": 0,"title": title,"intent": {"url": ""},"alert_type": 7, "alternate_title": "", "extras": extras }, | ||
170 | "ios": {"alert": content, "sound": "default", "extras": extras}, | ||
171 | } | ||
172 | payload['options'] = {"apns_production": False, "time_to_live": 86400, 'sendno': sendno, | ||
173 | "third_party_channel":{ | ||
174 | "xiaomi": {"importance":"NORMAL","distribution":"secondary_push","distribution_fcm":"secondary_fcm_push"}, | ||
175 | "huawei": {"importance": "NORMAL"}, | ||
176 | # "honor": {"importance": "NORMAL"}, | ||
177 | # "meizu": {"importance": "NORMAL"}, | ||
178 | "oppo": {"importance": "NORMAL"}, | ||
179 | "vivo": {"importance": "NORMAL"}, | ||
180 | } | ||
181 | } | ||
182 | return payload | ||
183 | |||
184 | |||
185 | def jpush_v3(self, data): | ||
186 | payload = self.push_params_v3(title=data['title'],content=data['content'],content_type=data['content_type'],receiver_value=data['receiver_value'],extras=data['extras']) | ||
187 | body = json.dumps(payload) | ||
188 | return self.https_request(body, "https://api.jpush.cn/v3/push", 'application/json', version=1) | ||
189 | |||
190 | def get_alias(): | ||
191 | url = 'https://device.jpush.cn/v3/aliases/test189' | ||
192 | token = str(base64.b64encode(b'860a3d4ecfaf3c38eb539c4e:df208c0eb485ed3ab3b18ff2'),'utf-8') | ||
193 | print (token) | ||
194 | headers = { | ||
195 | 'Authorization': 'Basic {}'.format(token), | ||
196 | 'Accept': 'application / json' | ||
197 | } | ||
198 | resp = requests.get(url,headers=headers).text | ||
199 | print (resp) | ||
200 | |||
201 | def remove_alias(): | ||
202 | url = 'https://device.jpush.cn/v3/aliases/test189' | ||
203 | token = str(base64.b64encode(b'860a3d4ecfaf3c38eb539c4e:df208c0eb485ed3ab3b18ff2'), 'utf-8') | ||
204 | headers = { | ||
205 | 'Authorization': 'Basic {}'.format(token), | ||
206 | 'Accept': 'application / json' | ||
207 | } | ||
208 | data = { | ||
209 | "registration_ids":{"remove": ["121c83f760d835d731c"]} | ||
210 | } | ||
211 | resp = requests.post(url,headers=headers,json=data).text | ||
212 | print (resp) | ||
213 | |||
214 | |||
215 | def Msg_Push_Server(data): | ||
216 | secret = 'hNA32TZVxFGL9xv526Yg74XSNcutM3DiqfktZcHq0084jI6o2VetEjAndY8zlNTP' | ||
217 | p = '{channel}&{data}&{secret}&{time}'.format(channel=data['channel'],data=data['data'],secret=secret,time=data['time']).encode() | ||
218 | p = base64.b64encode(p) | ||
219 | hl = hashlib.md5() | ||
220 | hl.update(p) | ||
221 | sign = hl.hexdigest() | ||
222 | data['sign'] = sign | ||
223 | data['data'] = json.loads(data['data']) | ||
224 | url = "https://hi-sing-admin-dev.hikoon.com/api/provider" | ||
225 | resp = requests.request('POST',url,json=data).text | ||
226 | |||
227 | |||
228 | |||
229 | if __name__ == '__main__': | ||
230 | # data = {"title":"标题","content":"测试推送","content_type":"text","receiver_value":['test189'],"extras":{"type":"","value":""}} | ||
231 | # JPush().jpush_v3(data) | ||
232 | # TLSSigAPIv2.main() | ||
233 | |||
234 | # get_alias() | ||
235 | # remove_alias() | ||
236 | |||
237 | data = {"channel":"ActivityPublish","data":'{"activityId":69}',"time":int(time.time())} | ||
238 | Msg_Push_Server(data) |
api/verification.py
0 → 100644
This diff is collapsed.
Click to expand it.
api/views.py
0 → 100644
This diff is collapsed.
Click to expand it.
db.sqlite3
0 → 100644
File mode changed
manage.py
0 → 100644
1 | #!/usr/bin/env python | ||
2 | """Django's command-line utility for administrative tasks.""" | ||
3 | import os | ||
4 | import sys | ||
5 | |||
6 | |||
7 | def main(): | ||
8 | """Run administrative tasks.""" | ||
9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'HisinApi.settings') | ||
10 | try: | ||
11 | from django.core.management import execute_from_command_line | ||
12 | except ImportError as exc: | ||
13 | raise ImportError( | ||
14 | "Couldn't import Django. Are you sure it's installed and " | ||
15 | "available on your PYTHONPATH environment variable? Did you " | ||
16 | "forget to activate a virtual environment?" | ||
17 | ) from exc | ||
18 | execute_from_command_line(sys.argv) | ||
19 | |||
20 | |||
21 | if __name__ == '__main__': | ||
22 | main() |
requirements.txt
0 → 100644
1 | aliyun-python-sdk-core==2.13.35 | ||
2 | aliyun-python-sdk-kms==2.15.0 | ||
3 | django==3.2.12 | ||
4 | django-redis-cache==3.0.1 | ||
5 | django-rest-jwt==0.1.46 | ||
6 | djangorestframework==3.13.1 | ||
7 | djangorestframework-jwt==1.11.0 | ||
8 | gevent==21.1.2 | ||
9 | mysql-connector-python==8.0.18 | ||
10 | oss2==2.14.0 | ||
11 | PyJWT==2.7.0 | ||
12 | PyMySQL==0.10.1 | ||
13 | redis==3.5.3 | ||
14 | requests==2.25.0 | ||
15 | django-ratelimit==3.0.1 | ||
16 | librosa==0.9.1 | ||
17 | pydub==0.25.1 | ||
18 | pyroomacoustics==0.7.3 | ||
19 | eyed3==0.9.6 | ||
20 | jieba==0.42.1 | ||
21 | twilio==8.2.0 | ||
22 | django_redis | ||
23 | matplotlib | ||
24 | schedule |
-
Please register or sign in to post a comment