|
|
@ -12,13 +12,13 @@ import zipfile |
|
|
|
|
|
|
|
|
|
|
|
import xmltodict |
|
|
|
import xmltodict |
|
|
|
from django.core.cache import cache |
|
|
|
from django.core.cache import cache |
|
|
|
from django.db.models import Sum |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from api.models import APPSuperSignUsedInfo, AppUDID, AppIOSDeveloperInfo, AppReleaseInfo, Apps, APPToDeveloper, \ |
|
|
|
from api.models import APPSuperSignUsedInfo, AppUDID, AppIOSDeveloperInfo, AppReleaseInfo, Apps, APPToDeveloper, \ |
|
|
|
UDIDsyncDeveloper, DeveloperAppID, DeveloperDevicesID, IosDeveloperPublicPoolBill |
|
|
|
UDIDsyncDeveloper, DeveloperAppID, DeveloperDevicesID, IosDeveloperPublicPoolBill |
|
|
|
from api.utils.app.iossignapi import ResignApp, AppDeveloperApiV2 |
|
|
|
from api.utils.app.iossignapi import ResignApp, AppDeveloperApiV2 |
|
|
|
from api.utils.baseutils import file_format_path, delete_app_profile_file, get_profile_full_path, format_apple_date, \ |
|
|
|
from api.utils.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 |
|
|
|
get_format_time, make_app_uuid, make_from_user_uuid |
|
|
|
|
|
|
|
from api.utils.modelutils import get_ios_developer_public_num, check_ipa_is_latest_sign |
|
|
|
from api.utils.response import BaseResponse |
|
|
|
from api.utils.response import BaseResponse |
|
|
|
from api.utils.serializer import BillAppInfoSerializer, BillDeveloperInfoSerializer |
|
|
|
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, \ |
|
|
|
from api.utils.storage.caches import del_cache_response_by_short, send_msg_over_limit, check_app_permission, \ |
|
|
@ -42,12 +42,14 @@ def check_org_file(user_obj, org_file): |
|
|
|
return download_files_form_oss(storage_obj, org_file) |
|
|
|
return download_files_form_oss(storage_obj, org_file) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def resign_by_app_id(app_obj, need_download_profile=True): |
|
|
|
def resign_by_app_id(app_obj, need_download_profile=True, force=True): |
|
|
|
user_obj = app_obj.user_id |
|
|
|
user_obj = app_obj.user_id |
|
|
|
info_list = [] |
|
|
|
info_list = [] |
|
|
|
if app_obj.issupersign and user_obj.supersign_active: |
|
|
|
if app_obj.issupersign and user_obj.supersign_active: |
|
|
|
for developer_app_id_obj in DeveloperAppID.objects.filter(app_id=app_obj).all(): |
|
|
|
for developer_app_id_obj in DeveloperAppID.objects.filter(app_id=app_obj).all(): |
|
|
|
developer_obj = developer_app_id_obj.developerid |
|
|
|
developer_obj = developer_app_id_obj.developerid |
|
|
|
|
|
|
|
if check_ipa_is_latest_sign(app_obj, developer_obj) and not force: |
|
|
|
|
|
|
|
continue |
|
|
|
developer_app_id = developer_app_id_obj.aid |
|
|
|
developer_app_id = developer_app_id_obj.aid |
|
|
|
d_time = time.time() |
|
|
|
d_time = time.time() |
|
|
|
if need_download_profile: |
|
|
|
if need_download_profile: |
|
|
@ -57,8 +59,7 @@ def resign_by_app_id(app_obj, need_download_profile=True): |
|
|
|
else: |
|
|
|
else: |
|
|
|
download_flag = True |
|
|
|
download_flag = True |
|
|
|
with cache.lock("%s_%s_%s" % ('run_sign', app_obj.app_id, developer_obj.issuer_id), timeout=60 * 10): |
|
|
|
with cache.lock("%s_%s_%s" % ('run_sign', app_obj.app_id, developer_obj.issuer_id), timeout=60 * 10): |
|
|
|
status, result = IosUtils.run_sign(user_obj, app_obj, developer_obj, download_flag, None, d_time, {}, |
|
|
|
status, result = IosUtils.run_sign(user_obj, app_obj, developer_obj, download_flag, '', d_time, {}) |
|
|
|
True) |
|
|
|
|
|
|
|
info_list.append({'developer_id': developer_obj.issuer_id, 'result': (status, result)}) |
|
|
|
info_list.append({'developer_id': developer_obj.issuer_id, 'result': (status, result)}) |
|
|
|
return info_list |
|
|
|
return info_list |
|
|
|
|
|
|
|
|
|
|
@ -199,21 +200,6 @@ def err_callback(func, *args, **kwargs): |
|
|
|
return wrapper |
|
|
|
return wrapper |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_ios_developer_public_num(user_obj): |
|
|
|
|
|
|
|
add_number = IosDeveloperPublicPoolBill.objects.filter(to_user_id=user_obj, action__in=[1, 2]).aggregate( |
|
|
|
|
|
|
|
number=Sum('number')) |
|
|
|
|
|
|
|
used_number = IosDeveloperPublicPoolBill.objects.filter(user_id=user_obj, action=0, |
|
|
|
|
|
|
|
udid_sync_info__isnull=False).aggregate( |
|
|
|
|
|
|
|
number=Sum('number')) |
|
|
|
|
|
|
|
add_number = add_number.get("number", 0) |
|
|
|
|
|
|
|
if not add_number: |
|
|
|
|
|
|
|
add_number = -99 |
|
|
|
|
|
|
|
used_number = used_number.get("number", 0) |
|
|
|
|
|
|
|
if not used_number: |
|
|
|
|
|
|
|
used_number = 0 |
|
|
|
|
|
|
|
return add_number - used_number |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_developer_user_by_app_udid(user_obj, udid): |
|
|
|
def get_developer_user_by_app_udid(user_obj, udid): |
|
|
|
use_device_obj = APPSuperSignUsedInfo.objects.filter(udid__udid__udid=udid, |
|
|
|
use_device_obj = APPSuperSignUsedInfo.objects.filter(udid__udid__udid=udid, |
|
|
|
user_id=user_obj, developerid__is_actived=True, |
|
|
|
user_id=user_obj, developerid__is_actived=True, |
|
|
@ -458,7 +444,8 @@ class IosUtils(object): |
|
|
|
self.developer_obj).data, |
|
|
|
self.developer_obj).data, |
|
|
|
action=0, number=1, udid_sync_info=udid_sync_info, |
|
|
|
action=0, number=1, udid_sync_info=udid_sync_info, |
|
|
|
remote_addr=client_ip, product=udid_sync_info.product, |
|
|
|
remote_addr=client_ip, product=udid_sync_info.product, |
|
|
|
udid=self.udid, version=udid_sync_info.version |
|
|
|
udid=self.udid, version=udid_sync_info.version, |
|
|
|
|
|
|
|
app_id=self.app_obj |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
@staticmethod |
|
|
@ -466,18 +453,14 @@ class IosUtils(object): |
|
|
|
# 更新新签名的ipa包 |
|
|
|
# 更新新签名的ipa包 |
|
|
|
if IosUtils.update_sign_file_name(user_obj, app_obj, developer_obj, release_obj, |
|
|
|
if IosUtils.update_sign_file_name(user_obj, app_obj, developer_obj, release_obj, |
|
|
|
random_file_name): |
|
|
|
random_file_name): |
|
|
|
newdata = { |
|
|
|
if udid: |
|
|
|
"is_signed": True, |
|
|
|
udid_obj = UDIDsyncDeveloper.objects.filter(developerid=developer_obj, udid=udid).first() |
|
|
|
"binary_file": random_file_name |
|
|
|
AppUDID.objects.filter(app_id=app_obj, udid=udid_obj).update(**{"is_signed": True}) |
|
|
|
} |
|
|
|
|
|
|
|
# 更新已经完成签名状态,设备消耗记录,和开发者已消耗数量 |
|
|
|
|
|
|
|
udid_obj = UDIDsyncDeveloper.objects.filter(developerid=developer_obj, udid=udid).first() |
|
|
|
|
|
|
|
AppUDID.objects.filter(app_id=app_obj, udid=udid_obj).update(**newdata) |
|
|
|
|
|
|
|
del_cache_response_by_short(app_obj.app_id, udid=udid) |
|
|
|
del_cache_response_by_short(app_obj.app_id, udid=udid) |
|
|
|
return True |
|
|
|
return True |
|
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
@staticmethod |
|
|
|
def run_sign(user_obj, app_obj, developer_obj, download_flag, udid, d_time, result, resign=False): |
|
|
|
def run_sign(user_obj, app_obj, developer_obj, download_flag, udid, d_time, result): |
|
|
|
d_result = {'code': 0, 'msg': 'success'} |
|
|
|
d_result = {'code': 0, 'msg': 'success'} |
|
|
|
start_time = time.time() |
|
|
|
start_time = time.time() |
|
|
|
if download_flag: |
|
|
|
if download_flag: |
|
|
@ -489,18 +472,11 @@ class IosUtils(object): |
|
|
|
if status: |
|
|
|
if status: |
|
|
|
s_time1 = time.time() |
|
|
|
s_time1 = time.time() |
|
|
|
logger.info(f"app_id {app_obj} exec sign ipa success. time:{s_time1 - start_time}") |
|
|
|
logger.info(f"app_id {app_obj} exec sign ipa success. time:{s_time1 - start_time}") |
|
|
|
if resign: |
|
|
|
if not IosUtils.update_sign_data(user_obj, app_obj, developer_obj, random_file_name, release_obj, |
|
|
|
if not IosUtils.update_sign_file_name(user_obj, app_obj, developer_obj, release_obj, |
|
|
|
udid): |
|
|
|
random_file_name): |
|
|
|
d_result['code'] = 1004 |
|
|
|
d_result['code'] = 1004 |
|
|
|
d_result['msg'] = '数据更新失败,请稍后重试' |
|
|
|
d_result['msg'] = '数据更新失败,请稍后重试' |
|
|
|
return status, d_result |
|
|
|
return status, d_result |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
if not IosUtils.update_sign_data(user_obj, app_obj, developer_obj, random_file_name, release_obj, |
|
|
|
|
|
|
|
udid): |
|
|
|
|
|
|
|
d_result['code'] = 1004 |
|
|
|
|
|
|
|
d_result['msg'] = '数据更新失败,请稍后重试' |
|
|
|
|
|
|
|
return status, d_result |
|
|
|
|
|
|
|
else: |
|
|
|
else: |
|
|
|
d_result['code'] = 1004 |
|
|
|
d_result['code'] = 1004 |
|
|
|
d_result['msg'] = '签名失败,请检查包是否正常' |
|
|
|
d_result['msg'] = '签名失败,请检查包是否正常' |
|
|
@ -553,13 +529,16 @@ class IosUtils(object): |
|
|
|
udid__developerid=self.developer_obj).first() |
|
|
|
udid__developerid=self.developer_obj).first() |
|
|
|
if app_udid_obj and app_udid_obj.is_download: |
|
|
|
if app_udid_obj and app_udid_obj.is_download: |
|
|
|
if app_udid_obj.is_signed: |
|
|
|
if app_udid_obj.is_signed: |
|
|
|
release_obj = AppReleaseInfo.objects.filter(app_id=self.app_obj, is_master=True).first() |
|
|
|
# release_obj = AppReleaseInfo.objects.filter(app_id=self.app_obj, is_master=True).first() |
|
|
|
for apptodev_obj in APPToDeveloper.objects.filter(app_id=self.app_obj).all(): |
|
|
|
|
|
|
|
if release_obj.release_id == apptodev_obj.release_file: |
|
|
|
if check_ipa_is_latest_sign(self.app_obj, self.developer_obj): |
|
|
|
msg = "udid %s exists app_id %s" % (self.udid, self.app_obj) |
|
|
|
# |
|
|
|
d_result['msg'] = msg |
|
|
|
# for apptodev_obj in APPToDeveloper.objects.filter(app_id=self.app_obj).all(): |
|
|
|
logger.info(d_result) |
|
|
|
# if release_obj.release_id == apptodev_obj.release_file: |
|
|
|
return True, d_result |
|
|
|
msg = "udid %s exists app_id %s" % (self.udid, self.app_obj) |
|
|
|
|
|
|
|
d_result['msg'] = msg |
|
|
|
|
|
|
|
logger.info(d_result) |
|
|
|
|
|
|
|
return True, d_result |
|
|
|
else: |
|
|
|
else: |
|
|
|
with cache.lock("%s_%s_%s" % ('run_sign', self.app_obj.app_id, self.developer_obj.issuer_id), |
|
|
|
with cache.lock("%s_%s_%s" % ('run_sign', self.app_obj.app_id, self.developer_obj.issuer_id), |
|
|
|
timeout=60 * 10): |
|
|
|
timeout=60 * 10): |
|
|
|