From 42bab0739beaccc17241efd34dd12dcce5bcb114 Mon Sep 17 00:00:00 2001 From: nineven Date: Mon, 14 Feb 2022 21:24:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fir_ser/admin/utils/serializer.py | 2 +- fir_ser/admin/views/app.py | 4 +- fir_ser/admin/views/celery_flower.py | 2 +- fir_ser/admin/views/domain.py | 4 +- fir_ser/admin/views/login.py | 8 +-- fir_ser/admin/views/order.py | 4 +- fir_ser/admin/views/report.py | 2 +- fir_ser/admin/views/storage.py | 2 +- fir_ser/admin/views/supersign.py | 2 +- fir_ser/admin/views/user.py | 6 +- fir_ser/api/base_views.py | 6 +- .../api/migrations/0020_auto_20211104_1118.py | 6 +- .../api/migrations/0035_auto_20220214_2042.py | 27 ++++++++ fir_ser/api/models.py | 9 +-- fir_ser/api/tasks.py | 8 +-- fir_ser/api/utils/app/apputils.py | 4 +- fir_ser/api/utils/app/iossignapi.py | 7 +- fir_ser/api/utils/app/supersignutils.py | 12 ++-- fir_ser/api/utils/crontab/ctasks.py | 9 +-- fir_ser/api/utils/crontab/iproxy.py | 2 +- fir_ser/api/utils/pay/__init__.py | 5 -- fir_ser/api/utils/serializer.py | 12 ++-- fir_ser/api/utils/utils.py | 16 ++--- fir_ser/api/views/advert.py | 6 +- fir_ser/api/views/apps.py | 12 ++-- fir_ser/api/views/domain.py | 4 +- fir_ser/api/views/download.py | 10 +-- fir_ser/api/views/login.py | 14 ++-- fir_ser/api/views/logout.py | 2 +- fir_ser/api/views/order.py | 6 +- fir_ser/api/views/receiveudids.py | 6 +- fir_ser/api/views/report.py | 6 +- fir_ser/api/views/storage.py | 2 +- fir_ser/api/views/supersign.py | 18 +++--- fir_ser/api/views/thirdlogin.py | 8 +-- fir_ser/api/views/uploads.py | 8 +-- fir_ser/cli/views/apps.py | 2 +- fir_ser/cli/views/login.py | 2 +- fir_ser/cli/views/uploads.py | 2 +- fir_ser/{api/utils => common/base}/daobase.py | 0 fir_ser/{api/utils => common/core}/auth.py | 0 fir_ser/common/core/dbrouter.py | 16 +++++ .../{api/utils => common/core}/decorators.py | 0 .../{admin/utils => common/core}/exception.py | 0 .../{api/utils => common/core}/sysconfig.py | 64 ++++++++++++++++--- .../{api/utils => common/core}/throttle.py | 0 .../utils => common/libs}/apple/appleapiv3.py | 2 +- .../libs}/geetest/geetest_lib.py | 0 .../libs}/geetest/geetest_lib_result.py | 0 .../libs}/geetest/geetest_utils.py | 4 +- .../{api/utils => common/libs}/mp/__init__.py | 0 .../utils => common/libs}/mp/chat/__init__.py | 0 .../utils => common/libs}/mp/chat/receive.py | 0 .../utils => common/libs}/mp/chat/reply.py | 0 .../{api/utils => common/libs}/mp/ierror.py | 0 .../{api/utils => common/libs}/mp/utils.py | 0 .../{api/utils => common/libs}/mp/wechat.py | 4 +- fir_ser/{api/utils => common/libs}/pay/ali.py | 4 +- .../libs}/pay/alipay/__init__.py | 0 .../libs}/pay/alipay/exceptions.py | 0 .../libs}/pay/alipay/loggers.py | 0 .../{api/utils => common/libs}/pay/util.py | 11 ++-- fir_ser/{api/utils => common/libs}/pay/wx.py | 4 +- .../libs}/pay/wxpay/__init__.py | 0 .../utils => common/libs}/pay/wxpay/core.py | 0 .../libs}/sendmsg/aliyunApi.py | 0 .../utils => common/libs}/sendmsg/emailApi.py | 0 .../libs}/sendmsg/jiguangApi.py | 0 .../libs}/storage/aliyunApi.py | 0 .../utils => common/libs}/storage/localApi.py | 2 +- .../utils => common/libs}/storage/qiniuApi.py | 0 .../utils/storage => common/utils}/caches.py | 8 +-- .../utils/sendmsg => common/utils}/sendmsg.py | 11 ++-- .../utils/storage => common/utils}/storage.py | 14 ++-- fir_ser/config.py | 20 ++++-- fir_ser/fir_ser/settings.py | 41 +++++++----- 76 files changed, 287 insertions(+), 185 deletions(-) create mode 100644 fir_ser/api/migrations/0035_auto_20220214_2042.py delete mode 100644 fir_ser/api/utils/pay/__init__.py rename fir_ser/{api/utils => common/base}/daobase.py (100%) rename fir_ser/{api/utils => common/core}/auth.py (100%) create mode 100644 fir_ser/common/core/dbrouter.py rename fir_ser/{api/utils => common/core}/decorators.py (100%) rename fir_ser/{admin/utils => common/core}/exception.py (100%) rename fir_ser/{api/utils => common/core}/sysconfig.py (82%) rename fir_ser/{api/utils => common/core}/throttle.py (100%) rename fir_ser/{api/utils => common/libs}/apple/appleapiv3.py (99%) rename fir_ser/{api/utils => common/libs}/geetest/geetest_lib.py (100%) rename fir_ser/{api/utils => common/libs}/geetest/geetest_lib_result.py (100%) rename fir_ser/{api/utils => common/libs}/geetest/geetest_utils.py (97%) rename fir_ser/{api/utils => common/libs}/mp/__init__.py (100%) rename fir_ser/{api/utils => common/libs}/mp/chat/__init__.py (100%) rename fir_ser/{api/utils => common/libs}/mp/chat/receive.py (100%) rename fir_ser/{api/utils => common/libs}/mp/chat/reply.py (100%) rename fir_ser/{api/utils => common/libs}/mp/ierror.py (100%) rename fir_ser/{api/utils => common/libs}/mp/utils.py (100%) rename fir_ser/{api/utils => common/libs}/mp/wechat.py (99%) rename fir_ser/{api/utils => common/libs}/pay/ali.py (96%) rename fir_ser/{api/utils => common/libs}/pay/alipay/__init__.py (100%) rename fir_ser/{api/utils => common/libs}/pay/alipay/exceptions.py (100%) rename fir_ser/{api/utils => common/libs}/pay/alipay/loggers.py (100%) rename fir_ser/{api/utils => common/libs}/pay/util.py (80%) rename fir_ser/{api/utils => common/libs}/pay/wx.py (96%) rename fir_ser/{api/utils => common/libs}/pay/wxpay/__init__.py (100%) rename fir_ser/{api/utils => common/libs}/pay/wxpay/core.py (100%) rename fir_ser/{api/utils => common/libs}/sendmsg/aliyunApi.py (100%) rename fir_ser/{api/utils => common/libs}/sendmsg/emailApi.py (100%) rename fir_ser/{api/utils => common/libs}/sendmsg/jiguangApi.py (100%) rename fir_ser/{api/utils => common/libs}/storage/aliyunApi.py (100%) rename fir_ser/{api/utils => common/libs}/storage/localApi.py (97%) rename fir_ser/{api/utils => common/libs}/storage/qiniuApi.py (100%) rename fir_ser/{api/utils/storage => common/utils}/caches.py (99%) rename fir_ser/{api/utils/sendmsg => common/utils}/sendmsg.py (87%) rename fir_ser/{api/utils/storage => common/utils}/storage.py (95%) diff --git a/fir_ser/admin/utils/serializer.py b/fir_ser/admin/utils/serializer.py index fc471d1..4d6324e 100644 --- a/fir_ser/admin/utils/serializer.py +++ b/fir_ser/admin/utils/serializer.py @@ -7,8 +7,8 @@ from api import models from api.utils.serializer import AppReleaseSerializer, UserInfoSerializer, AppsSerializer, StorageSerializer, \ DeveloperSerializer, SuperSignUsedSerializer, ThirdWxSerializer, DomainNameSerializer, BillInfoSerializer, \ AppReportSerializer -from api.utils.storage.storage import Storage from common.base.baseutils import get_choices_dict, get_choices_name_from_key +from common.utils.storage import Storage logger = logging.getLogger(__name__) diff --git a/fir_ser/admin/views/app.py b/fir_ser/admin/views/app.py index dcd824f..238924d 100644 --- a/fir_ser/admin/views/app.py +++ b/fir_ser/admin/views/app.py @@ -15,8 +15,8 @@ from admin.utils.utils import AppsPageNumber, ApiResponse, BaseModelSet from api.base_views import app_delete from api.models import AppReleaseInfo, Apps from api.utils.TokenManager import verify_token -from api.utils.auth import AdminTokenAuthentication -from api.utils.storage.caches import del_cache_response_by_short, get_download_url_by_cache +from common.core.auth import AdminTokenAuthentication +from common.utils.caches import del_cache_response_by_short, get_download_url_by_cache logger = logging.getLogger(__name__) diff --git a/fir_ser/admin/views/celery_flower.py b/fir_ser/admin/views/celery_flower.py index 4d3e092..fc60d6a 100644 --- a/fir_ser/admin/views/celery_flower.py +++ b/fir_ser/admin/views/celery_flower.py @@ -6,7 +6,7 @@ from django.utils.translation import ugettext as _ from proxy.views import proxy_view from rest_framework.views import APIView -from api.utils.auth import AdminTokenAuthentication +from common.core.auth import AdminTokenAuthentication flower_url = f'{settings.CELERY_FLOWER_HOST}:{settings.CELERY_FLOWER_PORT}' diff --git a/fir_ser/admin/views/domain.py b/fir_ser/admin/views/domain.py index f1cb292..657f2e0 100644 --- a/fir_ser/admin/views/domain.py +++ b/fir_ser/admin/views/domain.py @@ -13,8 +13,8 @@ from rest_framework.filters import OrderingFilter from admin.utils.serializer import AdminDomainNameSerializer from admin.utils.utils import BaseModelSet, AppsPageNumber, ApiResponse from api.models import UserDomainInfo -from api.utils.auth import AdminTokenAuthentication -from api.utils.storage.caches import reset_app_wx_easy_type +from common.core.auth import AdminTokenAuthentication +from common.utils.caches import reset_app_wx_easy_type logger = logging.getLogger(__name__) diff --git a/fir_ser/admin/views/login.py b/fir_ser/admin/views/login.py index fcfd9b3..897fdc2 100644 --- a/fir_ser/admin/views/login.py +++ b/fir_ser/admin/views/login.py @@ -10,12 +10,12 @@ from django.contrib import auth from rest_framework.views import APIView from admin.utils.utils import ApiResponse -from api.utils.auth import ExpiringTokenAuthentication from api.utils.serializer import UserInfoSerializer -from api.utils.storage.caches import login_auth_failed -from api.utils.sysconfig import Config -from api.utils.throttle import VisitRegister1Throttle, VisitRegister2Throttle from api.utils.utils import get_captcha, valid_captcha, set_user_token +from common.core.auth import ExpiringTokenAuthentication +from common.core.sysconfig import Config +from common.core.throttle import VisitRegister1Throttle, VisitRegister2Throttle +from common.utils.caches import login_auth_failed logger = logging.getLogger(__name__) diff --git a/fir_ser/admin/views/order.py b/fir_ser/admin/views/order.py index a588807..25dafa3 100644 --- a/fir_ser/admin/views/order.py +++ b/fir_ser/admin/views/order.py @@ -13,8 +13,8 @@ from rest_framework.filters import OrderingFilter from admin.utils.serializer import AdminOrdersSerializer from admin.utils.utils import BaseModelSet, AppsPageNumber, ApiResponse from api.models import UserInfo, Order -from api.utils.auth import AdminTokenAuthentication -from api.utils.storage.caches import update_order_info, admin_change_user_download_times +from common.core.auth import AdminTokenAuthentication +from common.utils.caches import update_order_info, admin_change_user_download_times logger = logging.getLogger(__name__) diff --git a/fir_ser/admin/views/report.py b/fir_ser/admin/views/report.py index 1b2dbc9..b372c1e 100644 --- a/fir_ser/admin/views/report.py +++ b/fir_ser/admin/views/report.py @@ -13,7 +13,7 @@ from rest_framework.filters import OrderingFilter from admin.utils.serializer import AdminAppReportSerializer from admin.utils.utils import AppsPageNumber, BaseModelSet from api.models import AppReportInfo -from api.utils.auth import AdminTokenAuthentication +from common.core.auth import AdminTokenAuthentication logger = logging.getLogger(__name__) diff --git a/fir_ser/admin/views/storage.py b/fir_ser/admin/views/storage.py index 12c2bd7..20d0f57 100644 --- a/fir_ser/admin/views/storage.py +++ b/fir_ser/admin/views/storage.py @@ -16,8 +16,8 @@ from admin.utils.serializer import AdminStorageSerializer from admin.utils.utils import AppsPageNumber, BaseModelSet, ApiResponse from api.base_views import storage_change from api.models import UserInfo, AppStorage -from api.utils.auth import AdminTokenAuthentication from common.base.baseutils import format_storage_selection +from common.core.auth import AdminTokenAuthentication logger = logging.getLogger(__name__) diff --git a/fir_ser/admin/views/supersign.py b/fir_ser/admin/views/supersign.py index ebe3fc9..18035f4 100644 --- a/fir_ser/admin/views/supersign.py +++ b/fir_ser/admin/views/supersign.py @@ -14,10 +14,10 @@ from rest_framework.views import APIView from admin.utils.serializer import AdminDeveloperSerializer, AdminSuperSignUsedSerializer, AdminBillInfoSerializer from admin.utils.utils import AppsPageNumber, BaseModelSet, ApiResponse from api.models import APPSuperSignUsedInfo, AppIOSDeveloperInfo, IosDeveloperPublicPoolBill, IosDeveloperBill -from api.utils.auth import AdminTokenAuthentication from api.utils.modelutils import get_user_public_used_sign_num, get_user_public_sign_num, get_user_obj_from_epu from api.utils.utils import get_developer_devices from common.base.baseutils import get_real_ip_address +from common.core.auth import AdminTokenAuthentication logger = logging.getLogger(__name__) diff --git a/fir_ser/admin/views/user.py b/fir_ser/admin/views/user.py index 5cc9890..6299e46 100644 --- a/fir_ser/admin/views/user.py +++ b/fir_ser/admin/views/user.py @@ -14,10 +14,10 @@ from rest_framework.views import APIView from admin.utils.serializer import AdminUserInfoSerializer, AdminUserCertificationSerializer, AdminThirdWxSerializer from admin.utils.utils import AppsPageNumber, BaseModelSet, ApiResponse from api.models import UserInfo, UserCertificationInfo, ThirdWeChatUserInfo -from api.utils.auth import AdminTokenAuthentication -from api.utils.storage.caches import auth_user_download_times_gift -from api.utils.sysconfig import Config from common.base.baseutils import get_dict_from_filter_fields +from common.core.auth import AdminTokenAuthentication +from common.core.sysconfig import Config +from common.utils.caches import auth_user_download_times_gift logger = logging.getLogger(__name__) diff --git a/fir_ser/api/base_views.py b/fir_ser/api/base_views.py index 7d1a2d0..3440aef 100644 --- a/fir_ser/api/base_views.py +++ b/fir_ser/api/base_views.py @@ -9,12 +9,12 @@ import logging from api.models import AppReleaseInfo, APPToDeveloper, UserInfo, AppScreenShot, AppStorage from api.utils.app.supersignutils import IosUtils from api.utils.response import BaseResponse -from api.utils.storage.caches import del_cache_response_by_short, del_cache_by_delete_app, \ - del_cache_storage -from api.utils.storage.storage import Storage from api.utils.utils import delete_local_files, delete_app_screenshots_files, change_storage_and_change_head_img, \ migrating_storage_data, clean_storage_data, check_storage_is_new_storage from common.cache.state import MigrateStorageState +from common.utils.caches import del_cache_response_by_short, del_cache_by_delete_app, \ + del_cache_storage +from common.utils.storage import Storage logger = logging.getLogger(__name__) diff --git a/fir_ser/api/migrations/0020_auto_20211104_1118.py b/fir_ser/api/migrations/0020_auto_20211104_1118.py index a2d0b6a..bef44ef 100644 --- a/fir_ser/api/migrations/0020_auto_20211104_1118.py +++ b/fir_ser/api/migrations/0020_auto_20211104_1118.py @@ -2,7 +2,7 @@ from django.db import migrations, models -import api.utils.daobase +import common.base.daobase class Migration(migrations.Migration): @@ -28,11 +28,11 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='appiosdeveloperinfo', name='p8key', - field=api.utils.daobase.AESCharField(max_length=512, verbose_name='p8key'), + field=common.base.daobase.AESCharField(max_length=512, verbose_name='p8key'), ), migrations.AlterField( model_name='appstorage', name='secret_key', - field=api.utils.daobase.AESCharField(blank=True, max_length=128, null=True, verbose_name='存储访问secret'), + field=common.base.daobase.AESCharField(blank=True, max_length=128, null=True, verbose_name='存储访问secret'), ), ] diff --git a/fir_ser/api/migrations/0035_auto_20220214_2042.py b/fir_ser/api/migrations/0035_auto_20220214_2042.py new file mode 100644 index 0000000..f8c7eab --- /dev/null +++ b/fir_ser/api/migrations/0035_auto_20220214_2042.py @@ -0,0 +1,27 @@ +# Generated by Django 3.2.3 on 2022-02-14 20:42 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ('api', '0034_auto_20220208_0941'), + ] + + operations = [ + migrations.AddField( + model_name='systemconfig', + name='enable', + field=models.BooleanField(default=True, verbose_name='是否启用该配置项'), + ), + migrations.AlterField( + model_name='systemconfig', + name='key', + field=models.CharField(max_length=128, unique=True, verbose_name='配置名称'), + ), + migrations.AlterField( + model_name='systemconfig', + name='value', + field=models.TextField(max_length=10240, verbose_name='配置值'), + ), + ] diff --git a/fir_ser/api/models.py b/fir_ser/api/models.py index de432ec..5bf518b 100644 --- a/fir_ser/api/models.py +++ b/fir_ser/api/models.py @@ -4,9 +4,9 @@ from django.db import models from django.db.models import Count from api.utils.TokenManager import generate_alphanumeric_token_of_length, generate_numeric_token_of_length -######################################## 用户表 ######################################## -from api.utils.daobase import AESCharField from common.base.baseutils import make_random_uuid +######################################## 用户表 ######################################## +from common.base.daobase import AESCharField # Create your models here. @@ -651,8 +651,9 @@ class AppleDeveloperToAppUse(models.Model): class SystemConfig(models.Model): - key = models.CharField(max_length=256, unique=True, verbose_name="配置名称") - value = models.CharField(max_length=512, verbose_name="配置值") + key = models.CharField(max_length=128, unique=True, verbose_name="配置名称") + value = models.TextField(max_length=10240, verbose_name="配置值") + enable = models.BooleanField(default=True, verbose_name="是否启用该配置项") description = models.CharField(verbose_name="备注", max_length=256, default='', blank=True) updated_time = models.DateTimeField(auto_now=True, verbose_name="更新时间") diff --git a/fir_ser/api/tasks.py b/fir_ser/api/tasks.py index 016afda..9520f39 100644 --- a/fir_ser/api/tasks.py +++ b/fir_ser/api/tasks.py @@ -14,12 +14,12 @@ from api.utils.app.supersignutils import IosUtils, resign_by_app_id_and_develope from api.utils.crontab.ctasks import sync_download_times, auto_clean_upload_tmp_file, auto_delete_ios_mobile_tmp_file, \ auto_check_ios_developer_active from api.utils.crontab.iproxy import get_best_proxy_ips, clean_ip_proxy_infos -from api.utils.geetest.geetest_utils import check_bypass_status -from api.utils.mp.wechat import sync_wx_access_token -from api.utils.storage.storage import get_local_storage -from api.utils.sysconfig import Config, invalid_config_cache from api.views.login import get_login_type from common.cache.state import MigrateStorageState +from common.core.sysconfig import Config, invalid_config_cache +from common.libs.geetest.geetest_utils import check_bypass_status +from common.libs.mp.wechat import sync_wx_access_token +from common.utils.storage import get_local_storage from fir_ser.celery import app logger = logging.getLogger(__name__) diff --git a/fir_ser/api/utils/app/apputils.py b/fir_ser/api/utils/app/apputils.py index 4d13c1c..5f87786 100644 --- a/fir_ser/api/utils/app/apputils.py +++ b/fir_ser/api/utils/app/apputils.py @@ -8,10 +8,10 @@ import random from api.models import AppReleaseInfo, Apps from api.utils.modelutils import get_user_domain_name -from api.utils.storage.caches import del_cache_response_by_short -from api.utils.storage.storage import Storage from common.base.baseutils import make_app_uuid from common.cache.state import MigrateStorageState +from common.utils.caches import del_cache_response_by_short +from common.utils.storage import Storage logger = logging.getLogger(__name__) diff --git a/fir_ser/api/utils/app/iossignapi.py b/fir_ser/api/utils/app/iossignapi.py index bc888d6..885aa2d 100644 --- a/fir_ser/api/utils/app/iossignapi.py +++ b/fir_ser/api/utils/app/iossignapi.py @@ -15,10 +15,11 @@ from OpenSSL.crypto import (load_pkcs12, dump_certificate_request, dump_privatek from api.models import AppIOSDeveloperInfo from api.utils.app.shellcmds import shell_command, use_user_pass -from api.utils.apple.appleapiv3 import AppStoreConnectApi from common.base.baseutils import get_format_time, format_apple_date, make_app_uuid from common.cache.state import CleanErrorBundleIdSignDataState -from fir_ser.settings import SUPER_SIGN_ROOT, DEVELOPER_WRITE_STATUS +from common.core.sysconfig import Config +from common.libs.apple.appleapiv3 import AppStoreConnectApi +from fir_ser.settings import SUPER_SIGN_ROOT logger = logging.getLogger(__name__) @@ -238,7 +239,7 @@ class AppDeveloperApiV2(object): return attr(*args, **kwargs) else: if AppIOSDeveloperInfo.objects.filter(pk=self.developer_pk, - status__in=DEVELOPER_WRITE_STATUS).first(): + status__in=Config.DEVELOPER_WRITE_STATUS).first(): start_time = time.time() logger.info(f'{self.issuer_id} calling {attr.__name__} time:{start_time}') result = attr(*args, **kwargs) diff --git a/fir_ser/api/utils/app/supersignutils.py b/fir_ser/api/utils/app/supersignutils.py index a807f61..5c8565d 100644 --- a/fir_ser/api/utils/app/supersignutils.py +++ b/fir_ser/api/utils/app/supersignutils.py @@ -23,17 +23,17 @@ from api.utils.modelutils import get_ios_developer_public_num, check_ipa_is_late update_or_create_developer_udid_info, check_uid_has_relevant from api.utils.response import BaseResponse from api.utils.serializer import BillAppInfoSerializer, BillDeveloperInfoSerializer -from api.utils.storage.caches import del_cache_response_by_short, send_msg_over_limit, check_app_permission, \ - consume_user_download_times_by_app_obj, add_udid_cache_queue, get_and_clean_udid_cache_queue -from api.utils.storage.storage import Storage -from api.utils.sysconfig import Config from api.utils.utils import delete_app_to_dev_and_file, send_ios_developer_active_status, delete_local_files, \ download_files_form_oss, get_developer_udided from common.base.baseutils import file_format_path, delete_app_profile_file, get_profile_full_path, format_apple_date, \ get_format_time, make_app_uuid, make_from_user_uuid from common.base.magic import run_function_by_locker, call_function_try_attempts from common.cache.state import CleanErrorBundleIdSignDataState -from fir_ser.settings import SUPER_SIGN_ROOT, MEDIA_ROOT, DEVELOPER_USE_STATUS +from common.core.sysconfig import Config +from common.utils.caches import del_cache_response_by_short, send_msg_over_limit, check_app_permission, \ + consume_user_download_times_by_app_obj, add_udid_cache_queue, get_and_clean_udid_cache_queue +from common.utils.storage import Storage +from fir_ser.settings import SUPER_SIGN_ROOT, MEDIA_ROOT logger = logging.getLogger(__name__) @@ -286,7 +286,7 @@ def get_developer_user_by_app_udid(user_objs, udid, app_obj, private_first=True, """ if read_only: - status_choice = DEVELOPER_USE_STATUS + status_choice = Config.DEVELOPER_USE_STATUS else: status_choice = [1] status_filter = {'developerid__certid__isnull': False, 'developerid__status__in': status_choice} diff --git a/fir_ser/api/utils/crontab/ctasks.py b/fir_ser/api/utils/crontab/ctasks.py index 261bbde..1a26bd2 100644 --- a/fir_ser/api/utils/crontab/ctasks.py +++ b/fir_ser/api/utils/crontab/ctasks.py @@ -12,10 +12,10 @@ from django.core.cache import cache from api.models import Apps, UserInfo, AppIOSDeveloperInfo from api.utils.app.supersignutils import IosUtils -from api.utils.storage.storage import Storage -from api.utils.sysconfig import Config from api.utils.utils import send_ios_developer_active_status -from fir_ser.settings import CACHE_KEY_TEMPLATE, SYNC_CACHE_TO_DATABASE, SUPER_SIGN_ROOT, DEVELOPER_AUTO_CHECK_STATUS +from common.core.sysconfig import Config +from common.utils.storage import Storage +from fir_ser.settings import CACHE_KEY_TEMPLATE, SYNC_CACHE_TO_DATABASE, SUPER_SIGN_ROOT logger = logging.getLogger(__name__) @@ -66,7 +66,8 @@ def auto_delete_ios_mobile_tmp_file(): def auto_check_ios_developer_active(): - all_ios_developer = AppIOSDeveloperInfo.objects.filter(status__in=DEVELOPER_AUTO_CHECK_STATUS, auto_check=True) + all_ios_developer = AppIOSDeveloperInfo.objects.filter(status__in=Config.DEVELOPER_AUTO_CHECK_STATUS, + auto_check=True) error_issuer_id = {} for ios_developer in all_ios_developer: userinfo = ios_developer.user_id diff --git a/fir_ser/api/utils/crontab/iproxy.py b/fir_ser/api/utils/crontab/iproxy.py index 8fc9b1c..1d73d9f 100644 --- a/fir_ser/api/utils/crontab/iproxy.py +++ b/fir_ser/api/utils/crontab/iproxy.py @@ -10,8 +10,8 @@ from concurrent.futures import ThreadPoolExecutor import requests -from api.utils.sysconfig import Config from common.cache.storage import IpProxyListCache, IpProxyActiveCache +from common.core.sysconfig import Config logger = logging.getLogger(__name__) diff --git a/fir_ser/api/utils/pay/__init__.py b/fir_ser/api/utils/pay/__init__.py deleted file mode 100644 index d01b98c..0000000 --- a/fir_ser/api/utils/pay/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env python -# -*- coding:utf-8 -*- -# project: 5月 -# author: NinEveN -# date: 2021/5/27 diff --git a/fir_ser/api/utils/serializer.py b/fir_ser/api/utils/serializer.py index c4a2983..0832b4f 100644 --- a/fir_ser/api/utils/serializer.py +++ b/fir_ser/api/utils/serializer.py @@ -8,12 +8,12 @@ from api import models from api.utils.TokenManager import make_token from api.utils.app.apputils import bytes2human from api.utils.modelutils import get_user_domain_name, get_app_domain_name, get_app_download_uri -from api.utils.storage.caches import get_user_free_download_times, get_user_cert_auth_status -from api.utils.storage.storage import Storage from api.utils.utils import get_developer_udided from common.base.baseutils import get_choices_dict, AppleDeveloperUid from common.cache.storage import AdPicShowCache -from fir_ser.settings import DEVELOPER_USE_STATUS, DEVELOPER_UID_KEY +from common.core.sysconfig import Config +from common.utils.caches import get_user_free_download_times, get_user_cert_auth_status +from common.utils.storage import Storage logger = logging.getLogger(__name__) @@ -422,7 +422,7 @@ class DeveloperSerializer(serializers.ModelSerializer): app_id = self.context.get('app_id', '') if app_id: developer_app_obj = models.DeveloperAppID.objects.filter(developerid=obj, - developerid__status__in=DEVELOPER_USE_STATUS, + developerid__status__in=Config.DEVELOPER_USE_STATUS, developerid__certid__isnull=False) if developer_app_obj.filter(app_id__app_id=app_id).distinct().count(): return False @@ -477,7 +477,7 @@ class SuperSignUsedSerializer(serializers.ModelSerializer): if self.context.get('mine'): return issuer_id else: - return f"{DEVELOPER_UID_KEY}{AppleDeveloperUid().get_encrypt_uid(issuer_id)}" + return f"{Config.DEVELOPER_UID_KEY}{AppleDeveloperUid().get_encrypt_uid(issuer_id)}" def get_developer_description(self, obj): if self.context.get('mine'): @@ -528,7 +528,7 @@ class DeviceUDIDSerializer(serializers.ModelSerializer): if self.context.get('mine'): return issuer_id else: - return f"{DEVELOPER_UID_KEY}{AppleDeveloperUid().get_encrypt_uid(issuer_id)}" + return f"{Config.DEVELOPER_UID_KEY}{AppleDeveloperUid().get_encrypt_uid(issuer_id)}" def get_developer_status(self, obj): return obj.udid.developerid.get_status_display() diff --git a/fir_ser/api/utils/utils.py b/fir_ser/api/utils/utils.py index 741e5a7..e68cef3 100644 --- a/fir_ser/api/utils/utils.py +++ b/fir_ser/api/utils/utils.py @@ -17,14 +17,14 @@ from api.models import APPSuperSignUsedInfo, APPToDeveloper, \ from api.utils.TokenManager import generate_numeric_token_of_length, generate_alphanumeric_token_of_length, make_token, \ verify_token from api.utils.modelutils import get_app_d_count_by_app_id -from api.utils.sendmsg.sendmsg import SendMessage -from api.utils.storage.caches import consume_user_download_times -from api.utils.storage.localApi import LocalStorage -from api.utils.storage.storage import Storage -from api.utils.sysconfig import Config from common.base.baseutils import get_real_ip_address from common.cache.storage import UserTokenCache, TempCache -from fir_ser.settings import CAPTCHA_LENGTH, MEDIA_ROOT, DEVELOPER_USE_STATUS +from common.core.sysconfig import Config +from common.libs.storage.localApi import LocalStorage +from common.utils.caches import consume_user_download_times +from common.utils.sendmsg import SendMessage +from common.utils.storage import Storage +from fir_ser.settings import CAPTCHA_LENGTH, MEDIA_ROOT logger = logging.getLogger(__name__) @@ -62,13 +62,13 @@ def get_developer_devices(developer_obj_lists): other_used_sum = 0 flyapp_used_sum = 0 max_total = 0 - for dev_obj in developer_obj_lists.filter(status__in=DEVELOPER_USE_STATUS): + for dev_obj in developer_obj_lists.filter(status__in=Config.DEVELOPER_USE_STATUS): other_used, flyapp_used, _ = get_developer_udided(dev_obj) other_used_sum += other_used flyapp_used_sum += flyapp_used max_total += 100 - use_number_obj_list = developer_obj_lists.filter(status__in=DEVELOPER_USE_STATUS) + use_number_obj_list = developer_obj_lists.filter(status__in=Config.DEVELOPER_USE_STATUS) all_use_number = 0 all_usable_number = 0 for use_number_obj in use_number_obj_list: diff --git a/fir_ser/api/views/advert.py b/fir_ser/api/views/advert.py index d7a5714..0b30231 100644 --- a/fir_ser/api/views/advert.py +++ b/fir_ser/api/views/advert.py @@ -9,12 +9,12 @@ from rest_framework.response import Response from rest_framework.views import APIView from api.models import UserAdDisplayInfo -from api.utils.auth import ExpiringTokenAuthentication, UserAdInfoPermission from api.utils.modelutils import PageNumber from api.utils.response import BaseResponse from api.utils.serializer import UserAdInfoSerializer -from api.utils.storage.caches import reset_short_response_cache -from api.utils.storage.storage import Storage +from common.core.auth import ExpiringTokenAuthentication, UserAdInfoPermission +from common.utils.caches import reset_short_response_cache +from common.utils.storage import Storage logger = logging.getLogger(__name__) diff --git a/fir_ser/api/views/apps.py b/fir_ser/api/views/apps.py index d9ec80f..56e6ce0 100644 --- a/fir_ser/api/views/apps.py +++ b/fir_ser/api/views/apps.py @@ -15,15 +15,15 @@ from api.base_views import app_delete from api.models import Apps, AppReleaseInfo, APPToDeveloper, UserInfo, AppScreenShot, AppUDID from api.tasks import run_resign_task from api.utils.app.supersignutils import IosUtils -from api.utils.auth import ExpiringTokenAuthentication from api.utils.modelutils import get_user_domain_name, get_app_domain_name, check_super_sign_permission from api.utils.response import BaseResponse from api.utils.serializer import AppsSerializer, AppReleaseSerializer, AppsListSerializer, AppsQrListSerializer -from api.utils.storage.caches import del_cache_response_by_short, get_app_today_download_times, del_cache_by_delete_app -from api.utils.storage.storage import Storage from api.utils.utils import delete_local_files, delete_app_screenshots_files from common.cache.state import MigrateStorageState, CleanAppSignDataState -from fir_ser.settings import DEVELOPER_WRITE_STATUS +from common.core.auth import ExpiringTokenAuthentication +from common.core.sysconfig import Config +from common.utils.caches import del_cache_response_by_short, get_app_today_download_times, del_cache_by_delete_app +from common.utils.storage import Storage logger = logging.getLogger(__name__) @@ -258,7 +258,7 @@ class AppInfoView(APIView): if app_obj.change_auto_sign: flag = False if AppUDID.objects.filter(app_id=app_obj, sign_status=2, - udid__developerid__status__in=DEVELOPER_WRITE_STATUS).first(): + udid__developerid__status__in=Config.DEVELOPER_WRITE_STATUS).first(): flag = True c_task = run_resign_task(app_obj.pk, flag) @@ -266,7 +266,7 @@ class AppInfoView(APIView): if app_obj.change_auto_sign: flag = False if AppUDID.objects.filter(app_id=app_obj, sign_status=2, - udid__developerid__status__in=DEVELOPER_WRITE_STATUS).first(): + udid__developerid__status__in=Config.DEVELOPER_WRITE_STATUS).first(): flag = True c_task = run_resign_task(app_obj.pk, flag, False) diff --git a/fir_ser/api/views/domain.py b/fir_ser/api/views/domain.py index 814eb54..cd4c2b1 100644 --- a/fir_ser/api/views/domain.py +++ b/fir_ser/api/views/domain.py @@ -9,12 +9,12 @@ from rest_framework.response import Response from rest_framework.views import APIView from api.models import UserDomainInfo, Apps -from api.utils.auth import ExpiringTokenAuthentication from api.utils.modelutils import get_user_domain_name, get_min_default_domain_cname_obj, PageNumber from api.utils.response import BaseResponse from api.utils.serializer import DomainNameSerializer -from api.utils.storage.caches import del_cache_response_by_short, reset_app_wx_easy_type from common.base.baseutils import is_valid_domain, get_cname_from_domain, get_choices_dict +from common.core.auth import ExpiringTokenAuthentication +from common.utils.caches import del_cache_response_by_short, reset_app_wx_easy_type logger = logging.getLogger(__name__) diff --git a/fir_ser/api/views/download.py b/fir_ser/api/views/download.py index 4fca06e..fb2c5b2 100644 --- a/fir_ser/api/views/download.py +++ b/fir_ser/api/views/download.py @@ -15,17 +15,17 @@ from api.models import Apps, AppReleaseInfo, APPToDeveloper, APPSuperSignUsedInf from api.utils.TokenManager import verify_token from api.utils.app.apputils import make_resigned from api.utils.app.supersignutils import make_sign_udid_mobile_config -from api.utils.decorators import cache_response # 本来使用的是 drf-extensions==0.7.0 但是还未支持该版本Django from api.utils.modelutils import get_filename_form_file, check_app_domain_name_access, \ ad_random_weight, get_app_download_uri from api.utils.response import BaseResponse from api.utils.serializer import AppsShortSerializer, AppAdInfoSerializer -from api.utils.storage.caches import check_app_permission, get_app_download_url -from api.utils.storage.storage import Storage, get_local_storage -from api.utils.sysconfig import Config -from api.utils.throttle import VisitShortThrottle, InstallShortThrottle, InstallThrottle1, InstallThrottle2 from common.base.baseutils import get_profile_full_path, make_random_uuid, get_origin_domain_name, \ format_get_uri, get_server_domain_from_request +from common.core.decorators import cache_response # 本来使用的是 drf-extensions==0.7.0 但是还未支持该版本Django +from common.core.sysconfig import Config +from common.core.throttle import VisitShortThrottle, InstallShortThrottle, InstallThrottle1, InstallThrottle2 +from common.utils.caches import check_app_permission, get_app_download_url +from common.utils.storage import Storage, get_local_storage from fir_ser import settings logger = logging.getLogger(__name__) diff --git a/fir_ser/api/views/login.py b/fir_ser/api/views/login.py index ccee80a..11e5dcc 100644 --- a/fir_ser/api/views/login.py +++ b/fir_ser/api/views/login.py @@ -5,20 +5,20 @@ from rest_framework.response import Response from rest_framework.views import APIView from api.models import UserInfo, UserCertificationInfo, CertificationInfo, Apps -from api.utils.auth import ExpiringTokenAuthentication -from api.utils.geetest.geetest_utils import first_register, second_validate from api.utils.modelutils import get_min_default_domain_cname_obj, add_remote_info_from_request -from api.utils.mp.wechat import make_wx_login_qrcode, show_qrcode_url from api.utils.response import BaseResponse from api.utils.serializer import UserInfoSerializer, CertificationSerializer, UserCertificationSerializer -from api.utils.storage.caches import login_auth_failed, set_wx_ticket_login_info_cache, get_wx_ticket_login_info_cache, \ - new_user_download_times_gift -from api.utils.sysconfig import Config -from api.utils.throttle import VisitRegister1Throttle, VisitRegister2Throttle, GetAuthC1Throttle, GetAuthC2Throttle from api.utils.utils import get_captcha, valid_captcha, \ get_sender_sms_token, is_valid_sender_code, get_sender_email_token, get_random_username, \ check_username_exists, set_user_token, clean_user_token_and_cache from common.base.baseutils import is_valid_phone, is_valid_email, get_real_ip_address +from common.core.auth import ExpiringTokenAuthentication +from common.core.sysconfig import Config +from common.core.throttle import VisitRegister1Throttle, VisitRegister2Throttle, GetAuthC1Throttle, GetAuthC2Throttle +from common.libs.geetest.geetest_utils import first_register, second_validate +from common.libs.mp.wechat import make_wx_login_qrcode, show_qrcode_url +from common.utils.caches import login_auth_failed, set_wx_ticket_login_info_cache, get_wx_ticket_login_info_cache, \ + new_user_download_times_gift logger = logging.getLogger(__name__) diff --git a/fir_ser/api/views/logout.py b/fir_ser/api/views/logout.py index 7311776..c91c9fa 100644 --- a/fir_ser/api/views/logout.py +++ b/fir_ser/api/views/logout.py @@ -5,8 +5,8 @@ from rest_framework.response import Response from rest_framework.views import APIView from api.models import Token -from api.utils.auth import ExpiringTokenAuthentication from common.cache.storage import RedisCacheBase +from common.core.auth import ExpiringTokenAuthentication logger = logging.getLogger(__name__) diff --git a/fir_ser/api/views/order.py b/fir_ser/api/views/order.py index 8f53dc1..e52793e 100644 --- a/fir_ser/api/views/order.py +++ b/fir_ser/api/views/order.py @@ -10,13 +10,13 @@ from rest_framework.response import Response from rest_framework.views import APIView from api.models import Price, Order -from api.utils.auth import ExpiringTokenAuthentication from api.utils.modelutils import PageNumber -from api.utils.pay.util import get_pay_obj_form_name, get_enable_pay_choices, get_payment_type from api.utils.response import BaseResponse from api.utils.serializer import PriceSerializer, OrdersSerializer -from api.utils.storage.caches import update_order_status from common.base.baseutils import get_order_num, get_choices_dict +from common.core.auth import ExpiringTokenAuthentication +from common.libs.pay.util import get_pay_obj_form_name, get_enable_pay_choices, get_payment_type +from common.utils.caches import update_order_status logger = logging.getLogger(__name__) diff --git a/fir_ser/api/views/receiveudids.py b/fir_ser/api/views/receiveudids.py index ec5b62a..4a00345 100644 --- a/fir_ser/api/views/receiveudids.py +++ b/fir_ser/api/views/receiveudids.py @@ -17,10 +17,10 @@ from api.utils.app.supersignutils import udid_bytes_to_dict, make_sign_udid_mobi from api.utils.modelutils import get_redirect_server_domain, add_remote_info_from_request, \ get_app_download_uri from api.utils.response import BaseResponse -from api.utils.storage.caches import check_app_permission -from api.utils.sysconfig import Config -from api.utils.throttle import ReceiveUdidThrottle1, ReceiveUdidThrottle2 from common.base.baseutils import get_real_ip_address, make_random_uuid, get_server_domain_from_request +from common.core.sysconfig import Config +from common.core.throttle import ReceiveUdidThrottle1, ReceiveUdidThrottle2 +from common.utils.caches import check_app_permission from fir_ser.celery import app logger = logging.getLogger(__name__) diff --git a/fir_ser/api/views/report.py b/fir_ser/api/views/report.py index 73cbd34..705a031 100644 --- a/fir_ser/api/views/report.py +++ b/fir_ser/api/views/report.py @@ -12,11 +12,11 @@ from api.models import Apps, AppReportInfo from api.utils.modelutils import add_remote_info_from_request from api.utils.response import BaseResponse from api.utils.serializer import AppReportSerializer -from api.utils.storage.caches import login_auth_failed -from api.utils.sysconfig import Config -from api.utils.throttle import InstallThrottle2 from api.utils.utils import is_valid_sender_code, get_captcha from common.base.baseutils import get_real_ip_address, get_choices_dict +from common.core.sysconfig import Config +from common.core.throttle import InstallThrottle2 +from common.utils.caches import login_auth_failed logger = logging.getLogger(__name__) diff --git a/fir_ser/api/views/storage.py b/fir_ser/api/views/storage.py index ec3733c..0083c34 100644 --- a/fir_ser/api/views/storage.py +++ b/fir_ser/api/views/storage.py @@ -12,12 +12,12 @@ from rest_framework.views import APIView from api.base_views import storage_change, app_delete from api.models import AppStorage, Apps from api.utils.app.apputils import clean_history_apps -from api.utils.auth import ExpiringTokenAuthentication, StoragePermission from api.utils.response import BaseResponse from api.utils.serializer import StorageSerializer from api.utils.utils import upload_oss_default_head_img from common.base.baseutils import get_choices_dict from common.cache.state import MigrateStorageState +from common.core.auth import ExpiringTokenAuthentication, StoragePermission logger = logging.getLogger(__name__) diff --git a/fir_ser/api/views/supersign.py b/fir_ser/api/views/supersign.py index f495887..00eb042 100644 --- a/fir_ser/api/views/supersign.py +++ b/fir_ser/api/views/supersign.py @@ -16,18 +16,18 @@ from api.models import AppIOSDeveloperInfo, APPSuperSignUsedInfo, AppUDID, IosDe UDIDsyncDeveloper, AppleDeveloperToAppUse, Apps, DeveloperAppID, APPToDeveloper, DeveloperDevicesID, \ IosDeveloperBill, UserInfo from api.utils.app.supersignutils import IosUtils -from api.utils.auth import ExpiringTokenAuthentication, SuperSignPermission from api.utils.modelutils import get_user_public_used_sign_num, get_user_public_sign_num, PageNumber, \ check_uid_has_relevant from api.utils.response import BaseResponse from api.utils.serializer import DeveloperSerializer, SuperSignUsedSerializer, DeviceUDIDSerializer, BillInfoSerializer, \ DeveloperDeviceSerializer, AppleDeveloperToAppUseSerializer, AppleDeveloperToAppUseAppsSerializer, \ BillTransferSerializer -from api.utils.storage.caches import get_app_download_url from api.utils.utils import get_developer_devices from common.base.baseutils import get_choices_dict, get_choices_name_from_key, AppleDeveloperUid, get_real_ip_address from common.cache.state import CleanSignDataState, MigrateStorageState -from fir_ser.settings import DEVELOPER_USE_STATUS, DEVELOPER_DISABLED_STATUS, DEVELOPER_UID_KEY +from common.core.auth import ExpiringTokenAuthentication, SuperSignPermission +from common.core.sysconfig import Config +from common.utils.caches import get_app_download_url logger = logging.getLogger(__name__) @@ -77,7 +77,7 @@ class DeveloperView(APIView): res.data = developer_serializer.data res.count = developer_obj.count() - res.status_choices = get_choices_dict(AppIOSDeveloperInfo.status_choices, DEVELOPER_DISABLED_STATUS) + res.status_choices = get_choices_dict(AppIOSDeveloperInfo.status_choices, Config.DEVELOPER_DISABLED_STATUS) res.apple_auth_list = get_choices_dict(AppIOSDeveloperInfo.auth_type_choices) return Response(res.dict) @@ -93,7 +93,7 @@ class DeveloperView(APIView): res = BaseResponse() result_list = [] for developer_s_obj in AppIOSDeveloperInfo.objects.filter(user_id=request.user, - status__in=DEVELOPER_USE_STATUS).all(): + status__in=Config.DEVELOPER_USE_STATUS).all(): status, result = IosUtils.get_device_from_developer(developer_s_obj) if not status: result_list.append(result.get("err_info")) @@ -111,7 +111,7 @@ class DeveloperView(APIView): elif act == "setstatus": issuer_ids = data.get("issuer_ids", []) status = data.get("status", None) - if issuer_ids and status is not None: + if issuer_ids and status is not None and status not in Config.DEVELOPER_DISABLED_STATUS: status_text = get_choices_name_from_key(AppIOSDeveloperInfo.status_choices, status) if status_text: AppIOSDeveloperInfo.objects.filter(user_id=request.user, issuer_id__in=issuer_ids).update( @@ -323,12 +323,12 @@ class SuperSignUsedView(APIView): other_uid_info = data.get('other_uid', '') if device_udid and developer_id and bundle_id: app_obj = Apps.objects.filter(user_id=request.user, bundle_id=bundle_id).first() - if app_obj is None and not developer_id.startswith(DEVELOPER_UID_KEY): + if app_obj is None and not developer_id.startswith(Config.DEVELOPER_UID_KEY): if other_uid_info: other_uid = other_uid_info.get('uid') if other_uid and check_uid_has_relevant(request.user.uid, other_uid): app_obj = Apps.objects.filter(bundle_id=bundle_id).first() - if developer_id.startswith(DEVELOPER_UID_KEY): + if developer_id.startswith(Config.DEVELOPER_UID_KEY): developer_id = AppleDeveloperUid().get_decrypt_uid(developer_id.lstrip('T:')) app_to_dev_obj = APPToDeveloper.objects.filter(app_id=app_obj, developerid__issuer_id=developer_id).first() @@ -744,7 +744,7 @@ class AppleDeveloperBindAppsView(APIView): for item in add_issuer_ids: developer_obj = AppIOSDeveloperInfo.objects.filter(issuer_id=item, user_id=request.user, - status__in=DEVELOPER_USE_STATUS, + status__in=Config.DEVELOPER_USE_STATUS, certid__isnull=False).first() developer_aid_obj = DeveloperAppID.objects.filter(developerid=developer_obj) is_exist = developer_aid_obj.filter(app_id=app_obj).count() diff --git a/fir_ser/api/views/thirdlogin.py b/fir_ser/api/views/thirdlogin.py index 22e34f8..1381a7e 100644 --- a/fir_ser/api/views/thirdlogin.py +++ b/fir_ser/api/views/thirdlogin.py @@ -12,14 +12,14 @@ from rest_framework.views import APIView from rest_framework_xml.parsers import XMLParser from api.models import ThirdWeChatUserInfo, UserInfo, UserCertificationInfo -from api.utils.auth import ExpiringTokenAuthentication from api.utils.modelutils import PageNumber -from api.utils.mp.chat import reply, receive -from api.utils.mp.wechat import check_signature, WxMsgCrypt, get_userinfo_from_openid, WxTemplateMsg from api.utils.response import BaseResponse from api.utils.serializer import ThirdWxSerializer -from api.utils.storage.caches import set_wx_ticket_login_info_cache, get_wx_ticket_login_info_cache from api.views.login import get_login_type +from common.core.auth import ExpiringTokenAuthentication +from common.libs.mp.chat import reply, receive +from common.libs.mp.wechat import check_signature, WxMsgCrypt, get_userinfo_from_openid, WxTemplateMsg +from common.utils.caches import set_wx_ticket_login_info_cache, get_wx_ticket_login_info_cache from config import WEB_DOMAIN logger = logging.getLogger(__name__) diff --git a/fir_ser/api/views/uploads.py b/fir_ser/api/views/uploads.py index 1ba4909..f670465 100644 --- a/fir_ser/api/views/uploads.py +++ b/fir_ser/api/views/uploads.py @@ -14,14 +14,14 @@ from api.models import Apps, AppReleaseInfo, UserInfo, AppScreenShot, Certificat from api.tasks import run_resign_task from api.utils.TokenManager import verify_token from api.utils.app.apputils import get_random_short, save_app_infos -from api.utils.auth import ExpiringTokenAuthentication from api.utils.modelutils import check_super_sign_permission, get_app_download_uri from api.utils.response import BaseResponse -from api.utils.storage.caches import upload_file_tmp_name, del_cache_response_by_short -from api.utils.storage.storage import Storage -from api.utils.sysconfig import Config from common.base.baseutils import make_app_uuid, make_from_user_uuid from common.cache.state import MigrateStorageState +from common.core.auth import ExpiringTokenAuthentication +from common.core.sysconfig import Config +from common.utils.caches import upload_file_tmp_name, del_cache_response_by_short +from common.utils.storage import Storage from fir_ser import settings logger = logging.getLogger(__name__) diff --git a/fir_ser/cli/views/apps.py b/fir_ser/cli/views/apps.py index d5ef45f..421a99c 100644 --- a/fir_ser/cli/views/apps.py +++ b/fir_ser/cli/views/apps.py @@ -6,8 +6,8 @@ import logging -from api.utils.auth import ApiTokenAuthentication from api.views.apps import AppsView, AppInfoView, AppReleaseInfoView +from common.core.auth import ApiTokenAuthentication logger = logging.getLogger(__name__) diff --git a/fir_ser/cli/views/login.py b/fir_ser/cli/views/login.py index df2ff4c..055cd20 100644 --- a/fir_ser/cli/views/login.py +++ b/fir_ser/cli/views/login.py @@ -1,7 +1,7 @@ import logging -from api.utils.auth import ApiTokenAuthentication from api.views.login import UserInfoView +from common.core.auth import ApiTokenAuthentication logger = logging.getLogger(__name__) diff --git a/fir_ser/cli/views/uploads.py b/fir_ser/cli/views/uploads.py index a154aa8..37c19c9 100644 --- a/fir_ser/cli/views/uploads.py +++ b/fir_ser/cli/views/uploads.py @@ -5,8 +5,8 @@ # date: 2020/3/6 -from api.utils.auth import ApiTokenAuthentication from api.views.uploads import AppAnalyseView, UploadView +from common.core.auth import ApiTokenAuthentication class CliAppAnalyseView(AppAnalyseView): diff --git a/fir_ser/api/utils/daobase.py b/fir_ser/common/base/daobase.py similarity index 100% rename from fir_ser/api/utils/daobase.py rename to fir_ser/common/base/daobase.py diff --git a/fir_ser/api/utils/auth.py b/fir_ser/common/core/auth.py similarity index 100% rename from fir_ser/api/utils/auth.py rename to fir_ser/common/core/auth.py diff --git a/fir_ser/common/core/dbrouter.py b/fir_ser/common/core/dbrouter.py new file mode 100644 index 0000000..c36974a --- /dev/null +++ b/fir_ser/common/core/dbrouter.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python +# -*- coding:utf-8 -*- +# author: NinEveN +# date: 2022/2/14 + +class DBRouter(object): + def db_for_read(self, model, **hints): + # + # if model._meta.model_name == 'Price': + # return 'db1' + # else: + # return 'default' + return 'slave' + + def db_for_write(self, model, **hints): + return 'default' diff --git a/fir_ser/api/utils/decorators.py b/fir_ser/common/core/decorators.py similarity index 100% rename from fir_ser/api/utils/decorators.py rename to fir_ser/common/core/decorators.py diff --git a/fir_ser/admin/utils/exception.py b/fir_ser/common/core/exception.py similarity index 100% rename from fir_ser/admin/utils/exception.py rename to fir_ser/common/core/exception.py diff --git a/fir_ser/api/utils/sysconfig.py b/fir_ser/common/core/sysconfig.py similarity index 82% rename from fir_ser/api/utils/sysconfig.py rename to fir_ser/common/core/sysconfig.py index c3f9e0f..4a99d2d 100644 --- a/fir_ser/api/utils/sysconfig.py +++ b/fir_ser/common/core/sysconfig.py @@ -15,7 +15,7 @@ from rest_framework import serializers from api.models import SystemConfig from common.cache.storage import SystemConfigCache from config import BASECONF, API_DOMAIN, MOBILEPROVISION, WEB_DOMAIN, THIRDLOGINCONF, AUTHCONF, IPACONF, MSGCONF, \ - DOWNLOADTIMESCONF + DOWNLOADTIMESCONF, PAYCONF, STORAGEKEYCONF, SENDERCONF, APPLEDEVELOPERCONF logger = logging.getLogger(__name__) @@ -45,7 +45,7 @@ def get_render_value(value): if value: try: context_dict = {} - for sys_obj_dict in SystemConfig.objects.values().all(): + for sys_obj_dict in SystemConfig.objects.filter(enable=True).values().all(): if re.findall('{{.*%s.*}}' % sys_obj_dict['key'], sys_obj_dict['value']): logger.warning(f"get same render key. so continue") continue @@ -62,7 +62,7 @@ class ConfigCacheBase(object): self.px = px def get_value_from_db(self, key): - data = SystemConfigSerializer(SystemConfig.objects.filter(key=key).first()).data + data = SystemConfigSerializer(SystemConfig.objects.filter(enable=True, key=key).first()).data if re.findall('{{.*%s.*}}' % data['key'], data['value']): logger.warning(f"get same render key. so get default value") data['key'] = '' @@ -121,10 +121,6 @@ class ConfigCacheBase(object): def FILE_UPLOAD_DOMAIN(self): return self.get_value('FILE_UPLOAD_DOMAIN', self.API_DOMAIN) - @property - def CAN_RENDER_KEY(self): - return self.get_value('CAN_RENDER_KEY', []) - class BaseConfCache(ConfigCacheBase): def __init__(self): @@ -277,7 +273,59 @@ class EmailMsgCache(ConfigCacheBase): return super().get_value('MSG_AUTO_CHECK_DEVELOPER', MSGCONF.MSG_AUTO_CHECK_DEVELOPER) -class ConfigCache(BaseConfCache, IpaConfCache, AuthConfCache, EmailMsgCache, UserDownloadTimesCache, GeeTestConfCache): +class PayConfCache(ConfigCacheBase): + def __init__(self): + super(PayConfCache, self).__init__() + + @property + def PAY_SUCCESS_URL(self): + return super().get_value('PAY_SUCCESS_URL', PAYCONF.PAY_SUCCESS_URL) + + @property + def APP_NOTIFY_URL(self): + return super().get_value('APP_NOTIFY_URL', PAYCONF.APP_NOTIFY_URL) + + @property + def PAY_CONFIG_KEY_INFO(self): + return super().get_value('PAY_CONFIG_KEY_INFO', PAYCONF.PAY_CONFIG_KEY_INFO) + + +class ThirdPartConfCache(ConfigCacheBase): + def __init__(self): + super(ThirdPartConfCache, self).__init__() + + @property + def STORAGE(self): + return super().get_value('STORAGE', STORAGEKEYCONF.STORAGE) + + @property + def SENDER(self): + return super().get_value('SENDER', SENDERCONF.SENDER) + + +class AppleDeveloperConfCache(ConfigCacheBase): + def __init__(self): + super(AppleDeveloperConfCache, self).__init__() + + @property + def DEVELOPER_USE_STATUS(self): + return super().get_value('DEVELOPER_USE_STATUS', APPLEDEVELOPERCONF.DEVELOPER_USE_STATUS) + + @property + def DEVELOPER_AUTO_CHECK_STATUS(self): + return super().get_value('SENDER', APPLEDEVELOPERCONF.DEVELOPER_AUTO_CHECK_STATUS) + + @property + def DEVELOPER_WRITE_STATUS(self): + return super().get_value('SENDER', APPLEDEVELOPERCONF.DEVELOPER_WRITE_STATUS) + + @property + def DEVELOPER_DISABLED_STATUS(self): + return super().get_value('SENDER', APPLEDEVELOPERCONF.DEVELOPER_DISABLED_STATUS) + + +class ConfigCache(BaseConfCache, IpaConfCache, AuthConfCache, EmailMsgCache, UserDownloadTimesCache, GeeTestConfCache, + PayConfCache, ThirdPartConfCache, AppleDeveloperConfCache): def __init__(self): super(ConfigCache, self).__init__() diff --git a/fir_ser/api/utils/throttle.py b/fir_ser/common/core/throttle.py similarity index 100% rename from fir_ser/api/utils/throttle.py rename to fir_ser/common/core/throttle.py diff --git a/fir_ser/api/utils/apple/appleapiv3.py b/fir_ser/common/libs/apple/appleapiv3.py similarity index 99% rename from fir_ser/api/utils/apple/appleapiv3.py rename to fir_ser/common/libs/apple/appleapiv3.py index fda1165..5f0709f 100644 --- a/fir_ser/api/utils/apple/appleapiv3.py +++ b/fir_ser/common/libs/apple/appleapiv3.py @@ -16,7 +16,7 @@ import jwt import requests from api.utils.crontab.iproxy import get_proxy_ip_from_cache -from api.utils.sysconfig import Config +from common.core.sysconfig import Config logger = logging.getLogger(__name__) diff --git a/fir_ser/api/utils/geetest/geetest_lib.py b/fir_ser/common/libs/geetest/geetest_lib.py similarity index 100% rename from fir_ser/api/utils/geetest/geetest_lib.py rename to fir_ser/common/libs/geetest/geetest_lib.py diff --git a/fir_ser/api/utils/geetest/geetest_lib_result.py b/fir_ser/common/libs/geetest/geetest_lib_result.py similarity index 100% rename from fir_ser/api/utils/geetest/geetest_lib_result.py rename to fir_ser/common/libs/geetest/geetest_lib_result.py diff --git a/fir_ser/api/utils/geetest/geetest_utils.py b/fir_ser/common/libs/geetest/geetest_utils.py similarity index 97% rename from fir_ser/api/utils/geetest/geetest_utils.py rename to fir_ser/common/libs/geetest/geetest_utils.py index c335be1..817690d 100644 --- a/fir_ser/api/utils/geetest/geetest_utils.py +++ b/fir_ser/common/libs/geetest/geetest_utils.py @@ -10,8 +10,8 @@ import logging import requests from django.core.cache import cache as redis_connect -from api.utils.geetest.geetest_lib import GeetestLib -from api.utils.sysconfig import Config +from common.core.sysconfig import Config +from common.libs.geetest.geetest_lib import GeetestLib logger = logging.getLogger(__name__) diff --git a/fir_ser/api/utils/mp/__init__.py b/fir_ser/common/libs/mp/__init__.py similarity index 100% rename from fir_ser/api/utils/mp/__init__.py rename to fir_ser/common/libs/mp/__init__.py diff --git a/fir_ser/api/utils/mp/chat/__init__.py b/fir_ser/common/libs/mp/chat/__init__.py similarity index 100% rename from fir_ser/api/utils/mp/chat/__init__.py rename to fir_ser/common/libs/mp/chat/__init__.py diff --git a/fir_ser/api/utils/mp/chat/receive.py b/fir_ser/common/libs/mp/chat/receive.py similarity index 100% rename from fir_ser/api/utils/mp/chat/receive.py rename to fir_ser/common/libs/mp/chat/receive.py diff --git a/fir_ser/api/utils/mp/chat/reply.py b/fir_ser/common/libs/mp/chat/reply.py similarity index 100% rename from fir_ser/api/utils/mp/chat/reply.py rename to fir_ser/common/libs/mp/chat/reply.py diff --git a/fir_ser/api/utils/mp/ierror.py b/fir_ser/common/libs/mp/ierror.py similarity index 100% rename from fir_ser/api/utils/mp/ierror.py rename to fir_ser/common/libs/mp/ierror.py diff --git a/fir_ser/api/utils/mp/utils.py b/fir_ser/common/libs/mp/utils.py similarity index 100% rename from fir_ser/api/utils/mp/utils.py rename to fir_ser/common/libs/mp/utils.py diff --git a/fir_ser/api/utils/mp/wechat.py b/fir_ser/common/libs/mp/wechat.py similarity index 99% rename from fir_ser/api/utils/mp/wechat.py rename to fir_ser/common/libs/mp/wechat.py index ccdf9e1..4764fc0 100644 --- a/fir_ser/api/utils/mp/wechat.py +++ b/fir_ser/common/libs/mp/wechat.py @@ -9,10 +9,10 @@ from hashlib import sha1 import requests -from api.utils.mp.utils import WxMsgCryptBase -from api.utils.sysconfig import Config from common.base.baseutils import get_format_time from common.cache.storage import WxTokenCache +from common.core.sysconfig import Config +from common.libs.mp.utils import WxMsgCryptBase logger = logging.getLogger(__name__) diff --git a/fir_ser/api/utils/pay/ali.py b/fir_ser/common/libs/pay/ali.py similarity index 96% rename from fir_ser/api/utils/pay/ali.py rename to fir_ser/common/libs/pay/ali.py index f928579..d2403ba 100644 --- a/fir_ser/api/utils/pay/ali.py +++ b/fir_ser/common/libs/pay/ali.py @@ -10,8 +10,8 @@ import json import logging from datetime import datetime, timedelta -from api.utils.pay.alipay import AliPay, AliPayConfig -from api.utils.storage.caches import update_order_info, update_order_status +from common.libs.pay.alipay import AliPay, AliPayConfig +from common.utils.caches import update_order_info, update_order_status logger = logging.getLogger('pay') diff --git a/fir_ser/api/utils/pay/alipay/__init__.py b/fir_ser/common/libs/pay/alipay/__init__.py similarity index 100% rename from fir_ser/api/utils/pay/alipay/__init__.py rename to fir_ser/common/libs/pay/alipay/__init__.py diff --git a/fir_ser/api/utils/pay/alipay/exceptions.py b/fir_ser/common/libs/pay/alipay/exceptions.py similarity index 100% rename from fir_ser/api/utils/pay/alipay/exceptions.py rename to fir_ser/common/libs/pay/alipay/exceptions.py diff --git a/fir_ser/api/utils/pay/alipay/loggers.py b/fir_ser/common/libs/pay/alipay/loggers.py similarity index 100% rename from fir_ser/api/utils/pay/alipay/loggers.py rename to fir_ser/common/libs/pay/alipay/loggers.py diff --git a/fir_ser/api/utils/pay/util.py b/fir_ser/common/libs/pay/util.py similarity index 80% rename from fir_ser/api/utils/pay/util.py rename to fir_ser/common/libs/pay/util.py index e800b06..c67503a 100644 --- a/fir_ser/api/utils/pay/util.py +++ b/fir_ser/common/libs/pay/util.py @@ -3,14 +3,13 @@ # project: 4月 # author: NinEveN # date: 2021/4/18 - -from api.utils.pay.ali import Alipay -from api.utils.pay.wx import Weixinpay -from fir_ser.settings import PAY_CONFIG_KEY_INFO +from common.core.sysconfig import Config +from common.libs.pay.ali import Alipay +from common.libs.pay.wx import Weixinpay def get_pay_obj_form_name(pay_name): - for pay_info in PAY_CONFIG_KEY_INFO: + for pay_info in Config.PAY_CONFIG_KEY_INFO: if pay_name == pay_info.get('NAME', '') and pay_info.get('ENABLED', False): auth_info = pay_info.get('AUTH', None) p_type = pay_info.get('TYPE', '') @@ -25,7 +24,7 @@ def get_pay_obj_form_name(pay_name): def get_enable_pay_choices(): pay_choices = [] - for pay_info in PAY_CONFIG_KEY_INFO: + for pay_info in Config.PAY_CONFIG_KEY_INFO: if pay_info.get('ENABLED', False): pay_choices.append({'type': pay_info.get('TYPE'), 'name': pay_info.get('NAME', '')}) return pay_choices diff --git a/fir_ser/api/utils/pay/wx.py b/fir_ser/common/libs/pay/wx.py similarity index 96% rename from fir_ser/api/utils/pay/wx.py rename to fir_ser/common/libs/pay/wx.py index 761a029..5bb961c 100644 --- a/fir_ser/api/utils/pay/wx.py +++ b/fir_ser/common/libs/pay/wx.py @@ -8,8 +8,8 @@ import json import logging from datetime import datetime, timedelta -from api.utils.pay.wxpay import WeChatPay, WeChatPayType -from api.utils.storage.caches import update_order_info, update_order_status +from common.libs.pay.wxpay import WeChatPay, WeChatPayType +from common.utils.caches import update_order_info, update_order_status logger = logging.getLogger('pay') diff --git a/fir_ser/api/utils/pay/wxpay/__init__.py b/fir_ser/common/libs/pay/wxpay/__init__.py similarity index 100% rename from fir_ser/api/utils/pay/wxpay/__init__.py rename to fir_ser/common/libs/pay/wxpay/__init__.py diff --git a/fir_ser/api/utils/pay/wxpay/core.py b/fir_ser/common/libs/pay/wxpay/core.py similarity index 100% rename from fir_ser/api/utils/pay/wxpay/core.py rename to fir_ser/common/libs/pay/wxpay/core.py diff --git a/fir_ser/api/utils/sendmsg/aliyunApi.py b/fir_ser/common/libs/sendmsg/aliyunApi.py similarity index 100% rename from fir_ser/api/utils/sendmsg/aliyunApi.py rename to fir_ser/common/libs/sendmsg/aliyunApi.py diff --git a/fir_ser/api/utils/sendmsg/emailApi.py b/fir_ser/common/libs/sendmsg/emailApi.py similarity index 100% rename from fir_ser/api/utils/sendmsg/emailApi.py rename to fir_ser/common/libs/sendmsg/emailApi.py diff --git a/fir_ser/api/utils/sendmsg/jiguangApi.py b/fir_ser/common/libs/sendmsg/jiguangApi.py similarity index 100% rename from fir_ser/api/utils/sendmsg/jiguangApi.py rename to fir_ser/common/libs/sendmsg/jiguangApi.py diff --git a/fir_ser/api/utils/storage/aliyunApi.py b/fir_ser/common/libs/storage/aliyunApi.py similarity index 100% rename from fir_ser/api/utils/storage/aliyunApi.py rename to fir_ser/common/libs/storage/aliyunApi.py diff --git a/fir_ser/api/utils/storage/localApi.py b/fir_ser/common/libs/storage/localApi.py similarity index 97% rename from fir_ser/api/utils/storage/localApi.py rename to fir_ser/common/libs/storage/localApi.py index 5f3db4a..20f7199 100644 --- a/fir_ser/api/utils/storage/localApi.py +++ b/fir_ser/common/libs/storage/localApi.py @@ -10,7 +10,7 @@ import logging import os from api.utils.TokenManager import make_token -from api.utils.storage.aliyunApi import AliYunCdn +from common.libs.storage.aliyunApi import AliYunCdn from fir_ser import settings logger = logging.getLogger(__name__) diff --git a/fir_ser/api/utils/storage/qiniuApi.py b/fir_ser/common/libs/storage/qiniuApi.py similarity index 100% rename from fir_ser/api/utils/storage/qiniuApi.py rename to fir_ser/common/libs/storage/qiniuApi.py diff --git a/fir_ser/api/utils/storage/caches.py b/fir_ser/common/utils/caches.py similarity index 99% rename from fir_ser/api/utils/storage/caches.py rename to fir_ser/common/utils/caches.py index 26b1038..7acec8a 100644 --- a/fir_ser/api/utils/storage/caches.py +++ b/fir_ser/common/utils/caches.py @@ -16,15 +16,15 @@ from api.models import Apps, UserInfo, AppReleaseInfo, AppUDID, APPToDeveloper, UserCertificationInfo, Order from api.utils.modelutils import get_app_d_count_by_app_id, get_app_domain_name, get_user_domain_name, \ add_remote_info_from_request -from api.utils.storage.storage import Storage, LocalStorage -from api.utils.sysconfig import Config from common.base.baseutils import check_app_password, get_order_num, get_real_ip_address from common.cache.invalid import invalid_app_cache, invalid_short_cache, invalid_app_download_times_cache, \ invalid_head_img_cache from common.cache.storage import AppDownloadTodayTimesCache, AppDownloadTimesCache, DownloadUrlCache, AppInstanceCache, \ UploadTmpFileNameCache, RedisCacheBase, UserCanDownloadCache, UserFreeDownloadTimesCache, WxTicketCache, \ SignUdidQueueCache, CloudStorageCache -from fir_ser.settings import CACHE_KEY_TEMPLATE, SYNC_CACHE_TO_DATABASE, DEVELOPER_USE_STATUS +from common.core.sysconfig import Config +from common.utils.storage import Storage, LocalStorage +from fir_ser.settings import CACHE_KEY_TEMPLATE, SYNC_CACHE_TO_DATABASE logger = logging.getLogger(__name__) @@ -49,7 +49,7 @@ def get_download_url_by_cache(app_obj, filename, limit, isdownload=True, key='', if appudid_obj: super_sign_obj = APPSuperSignUsedInfo.objects.filter(udid__udid__udid=udid, app_id_id=app_obj.get("pk"), - developerid__status__in=DEVELOPER_USE_STATUS).last() + developerid__status__in=Config.DEVELOPER_USE_STATUS).last() if super_sign_obj and super_sign_obj.user_id.supersign_active: app_to_developer_obj = APPToDeveloper.objects.filter(app_id_id=app_obj.get("pk"), developerid=super_sign_obj.developerid).last() diff --git a/fir_ser/api/utils/sendmsg/sendmsg.py b/fir_ser/common/utils/sendmsg.py similarity index 87% rename from fir_ser/api/utils/sendmsg/sendmsg.py rename to fir_ser/common/utils/sendmsg.py index 059b4e9..27587f6 100644 --- a/fir_ser/api/utils/sendmsg/sendmsg.py +++ b/fir_ser/common/utils/sendmsg.py @@ -6,10 +6,10 @@ import logging -from fir_ser.settings import THIRD_PART_CONFIG_KEY_INFO -from .aliyunApi import AliMsgSender -from .emailApi import EmailMsgSender -from .jiguangApi import JiGuangMsgSender +from common.core.sysconfig import Config +from common.libs.sendmsg.aliyunApi import AliMsgSender +from common.libs.sendmsg.emailApi import EmailMsgSender +from common.libs.sendmsg.jiguangApi import JiGuangMsgSender logger = logging.getLogger(__name__) @@ -21,8 +21,7 @@ def get_default_sender(send_type): 1: 阿里云 2: 极光 """ - sender_lists = THIRD_PART_CONFIG_KEY_INFO.get('sender_key') - for sender in sender_lists: + for sender in Config.SENDER: if sender.get("active", None): sender_type = sender.get('type', None) auth = sender.get('auth', {}) diff --git a/fir_ser/api/utils/storage/storage.py b/fir_ser/common/utils/storage.py similarity index 95% rename from fir_ser/api/utils/storage/storage.py rename to fir_ser/common/utils/storage.py index 666475d..4dfc6e5 100644 --- a/fir_ser/api/utils/storage/storage.py +++ b/fir_ser/common/utils/storage.py @@ -10,10 +10,10 @@ import time from common.base.baseutils import get_dict_from_filter_fields from common.base.magic import run_function_by_locker from common.cache.storage import CloudStorageCache, LocalStorageCache, DownloadUrlCache -from fir_ser.settings import THIRD_PART_CONFIG_KEY_INFO -from .aliyunApi import AliYunOss, AliYunCdn -from .localApi import LocalStorage -from .qiniuApi import QiNiuOss +from common.core.sysconfig import Config +from common.libs.storage.aliyunApi import AliYunOss, AliYunCdn +from common.libs.storage.localApi import LocalStorage +from common.libs.storage.qiniuApi import QiNiuOss logger = logging.getLogger(__name__) @@ -140,8 +140,7 @@ class Storage(object): def get_local_storage(clean_cache=False): - storage_lists = THIRD_PART_CONFIG_KEY_INFO.get('storage_key') - for storage in storage_lists: + for storage in Config.STORAGE: storage_type = storage.get('type', None) if storage_type == 0: auth = storage.get('auth', {}) @@ -162,8 +161,7 @@ def get_local_storage(clean_cache=False): def get_storage_form_conf(user): - storage_lists = THIRD_PART_CONFIG_KEY_INFO.get('storage_key', []) - for storage in storage_lists: + for storage in Config.STORAGE: if storage.get("active", None): storage_type = storage.get('type', None) auth = storage.get('auth', {}) diff --git a/fir_ser/config.py b/fir_ser/config.py index 64c0566..5093bf9 100644 --- a/fir_ser/config.py +++ b/fir_ser/config.py @@ -271,7 +271,8 @@ class IPACONF(object): class PAYCONF(object): - PAY_SUCCESS_URL = '%s/user/orders' % WEB_DOMAIN # 前端页面,支付成功跳转页面 + PAY_SUCCESS_URL = '{{WEB_DOMAIN}}/user/orders' # 前端页面,支付成功跳转页面 + APP_NOTIFY_URL = '{{API_DOMAIN}}/api/v1/fir/server/pay_success' # 支付支付回调URL PAY_CONFIG_KEY_INFO = [ { 'NAME': 'alipay', @@ -285,8 +286,8 @@ MIIEowIBAAKCAQEAhqf2mwftoxZDNpl4eWsQ6mEfXgMlNPr6jv72ecA4hbKWqChXQmGS1T+0VsRTSoOX 'ALI_PUBLIC_KEY': '''-----BEGIN CERTIFICATE----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkru1ulQV1v4q+q38nyzgkdd3evf7C1/Ipu6K+ZFb5FiuxJ7mildkBSuKz/8+TRd+tjgk2lfc2ehK5pja3cxDO/nb25sBoWiU09rtxgXLehLsgRRhatbICrlOnYxg5aiB5odAp3NMRqore4lnVYwfIyL9M49I0G/NbQzYjUQvAQJsnHwc6a6Kuqi1CwR1WXI0sDF9w7KXC4vRFFIUTwI4bVq4HQWI7NhbgEajHM/j6D6Bh/OMcTYnJJzCja0WmZRe5flfCsELlPESOCWUMbYoaNfBzpNvvyOpmRgs9jgy2WY9SeaB9hxwkpr8tOd2Sc7j3221JKCyDaFAX+4zPy7/fQIDAQAB -----END CERTIFICATE-----''', - 'APP_NOTIFY_URL': '%s/api/v1/fir/server/pay_success' % API_DOMAIN, # 支付支付回调URL - 'RETURN_URL': PAY_SUCCESS_URL, # 支付前端页面回调URL + 'APP_NOTIFY_URL': '{{APP_NOTIFY_URL}}', # 支付支付回调URL + 'RETURN_URL': '{{PAY_SUCCESS_URL}}', # 支付前端页面回调URL 'SUBJECT': '向 FLY分发平台 充值', } }, @@ -327,8 +328,8 @@ daWIhg++OHN2MBRutj7oL/AFAxyu467YA5+itEJLHNATbOr/s13S66nePNXox/hr bIX1aWjPxirQX9mzaL3oEQI= -----END PRIVATE KEY-----''', 'API_V3_KEY': '60DbP621a9C3162dDd4AB9c2O15a005L', - 'APP_NOTIFY_URL': '%s/api/v1/fir/server/pay_success' % API_DOMAIN, # 支付支付回调URL - 'RETURN_URL': PAY_SUCCESS_URL, # 支付前端页面回调URL + 'APP_NOTIFY_URL': '{{APP_NOTIFY_URL}}', # 支付支付回调URL + 'RETURN_URL': '{{PAY_SUCCESS_URL}}', # 支付前端页面回调URL 'SUBJECT': '向 FLY分发平台 充值', } } @@ -346,3 +347,12 @@ class DOWNLOADTIMESCONF(object): AUTH_USER_FREE_DOWNLOAD_TIMES = 10 NEW_USER_GIVE_DOWNLOAD_TIMES = 100 AUTH_USER_GIVE_DOWNLOAD_TIMES = 200 + + +class APPLEDEVELOPERCONF(object): + # (-1, '疑似被封'), (0, '未激活'), (1, '已激活'), (2, '协议待同意'), (3, '维护中'), (4, '证书过期'), (5, '状态异常') + DEVELOPER_USE_STATUS = [1, 2, 3, 4, 5] # 开发者可用状态,详情查看 model.AppIOSDeveloperInfo + DEVELOPER_AUTO_CHECK_STATUS = [1, 2] # 定时认证自动检测 + DEVELOPER_WRITE_STATUS = [1, 3, 4] # 开发者api写操作查询 + DEVELOPER_DISABLED_STATUS = [2, 4, 5] # 开发者不可 修改为状态,用户前端控制 + DEVELOPER_UID_KEY = "T:" # 开发者共享给其他第三方用户, 中间必须包含 : 前端需要根据 : 进行分割 diff --git a/fir_ser/fir_ser/settings.py b/fir_ser/fir_ser/settings.py index 37b673e..3335ae1 100644 --- a/fir_ser/fir_ser/settings.py +++ b/fir_ser/fir_ser/settings.py @@ -99,7 +99,19 @@ DATABASES = { # 设置MySQL的驱动 # 'OPTIONS': {'init_command': 'SET storage_engine=INNODB'}, 'OPTIONS': {'init_command': 'SET sql_mode="STRICT_TRANS_TABLES"', 'charset': 'utf8mb4'} - } + }, + # 'slave': { + # 'ENGINE': 'django.db.backends.mysql', + # 'NAME': DBCONF.name, + # 'USER': DBCONF.user, + # 'PASSWORD': DBCONF.password, + # 'HOST': DBCONF.host, + # 'PORT': DBCONF.port, + # 'CONN_MAX_AGE': 600, + # # 设置MySQL的驱动 + # # 'OPTIONS': {'init_command': 'SET storage_engine=INNODB'}, + # 'OPTIONS': {'init_command': 'SET sql_mode="STRICT_TRANS_TABLES"', 'charset': 'utf8mb4'} + # } # 'default': { # 'ENGINE': 'django.db.backends.postgresql', # 'NAME': DBCONF.name, @@ -121,6 +133,15 @@ DATABASES = { } +# 读写分离 可能会出现 the current database router prevents this relation. +# 1.项目设置了router读写分离,且在ORM create()方法中,使用了前边filter()方法得到的数据, +# 2.由于django是惰性查询,前边的filter()并没有立即查询,而是在create()中引用了filter()的数据时,执行了filter(), +# 3.此时写操作的db指针指向write_db,filter()的db指针指向read_db,两者发生冲突,导致服务禁止了此次与mysql的交互 +# 解决办法: +# 在前边filter()方法中,使用using()方法,使filter()方法立即与数据库交互,查出数据。 + +# DATABASE_ROUTERS = ['common.core.dbrouter.DBRouter'] + # Password validation # https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators @@ -144,10 +165,10 @@ REST_FRAMEWORK = { # 'rest_framework.renderers.BrowsableAPIRenderer', ), 'DEFAULT_THROTTLE_CLASSES': [ - 'api.utils.throttle.LoginUserThrottle', + 'common.core.throttle.LoginUserThrottle', ], 'DEFAULT_THROTTLE_RATES': BASECONF.DEFAULT_THROTTLE_RATES, - 'EXCEPTION_HANDLER': 'admin.utils.exception.common_exception_handler', + 'EXCEPTION_HANDLER': 'common.core.exception.common_exception_handler', } # Internationalization @@ -236,11 +257,6 @@ CORS_ALLOW_HEADERS = ( "x-token" ) -THIRD_PART_CONFIG_KEY_INFO = { - # APP存储配置 - 'storage_key': STORAGEKEYCONF.STORAGE, - 'sender_key': SENDERCONF.SENDER -} CACHE_KEY_TEMPLATE = { 'sysconfig_key': 'sysconfig', 'user_can_download_key': 'user_can_download', @@ -268,13 +284,6 @@ CACHE_KEY_TEMPLATE = { DATA_DOWNLOAD_KEY = "d_token" FILE_UPLOAD_TMP_KEY = ".tmp" -DEVELOPER_UID_KEY = "T:" - -# (-1, '疑似被封'), (0, '未激活'), (1, '已激活'), (2, '协议待同意'), (3, '维护中'), (4, '证书过期'), (5, '状态异常') -DEVELOPER_USE_STATUS = [1, 2, 3, 4, 5] # 开发者可用状态,详情查看 model.AppIOSDeveloperInfo -DEVELOPER_AUTO_CHECK_STATUS = [1, 2] # 定时认证自动检测 -DEVELOPER_WRITE_STATUS = [1, 3, 4] # 开发者api写操作查询 -DEVELOPER_DISABLED_STATUS = [2, 4, 5] # 开发者不可 修改为状态 SYNC_CACHE_TO_DATABASE = { 'download_times': 10, # 下载次数同步时间 @@ -387,8 +396,6 @@ LOGGING = { }, } -PAY_CONFIG_KEY_INFO = PAYCONF.PAY_CONFIG_KEY_INFO - # 结果存放到Django|redis # CELERY_RESULT_BACKEND = 'django-db' # CELERY_RESULT_BACKEND = 'django-cache'