add a new fun

super_signature
nineven 5 years ago
parent de4285a46a
commit 4e60166ecc
  1. 1
      fir_ser/api/models.py
  2. 93
      fir_ser/api/utils/app/supersignutils.py

@ -217,6 +217,7 @@ class APPSuperSignUsedInfo(models.Model):
user_id = models.ForeignKey(to="UserInfo",verbose_name="用户ID",on_delete=models.CASCADE)
app_id = models.ForeignKey(to="Apps", on_delete=models.CASCADE, verbose_name="属于哪个APP")
udid = models.ForeignKey(to="AppUDID",on_delete=models.CASCADE, verbose_name="所消耗的udid")
developerid = models.ForeignKey(to="AppIOSDeveloperInfo",on_delete=models.CASCADE, verbose_name="所使用苹果开发者账户")
created_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
updated_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")
class Meta:

@ -4,13 +4,14 @@
# author: liuyu
# date: 2020/3/6
import uuid, xmltodict,os
from fir_ser.settings import SUPER_SIGN_ROOT,MEDIA_ROOT,SERVER_DOMAIN
from api.utils.app.iossignapi import AppDeveloperApi,ResignApp
from api.models import APPSuperSignUsedInfo,AppUDID,AppIOSDeveloperInfo,AppReleaseInfo
from api.utils.app.randomstrings import make_app_uuid,make_from_user_uuid
import uuid, xmltodict, os, re
from fir_ser.settings import SUPER_SIGN_ROOT, MEDIA_ROOT, SERVER_DOMAIN
from api.utils.app.iossignapi import AppDeveloperApi, ResignApp
from api.models import APPSuperSignUsedInfo, AppUDID, AppIOSDeveloperInfo, AppReleaseInfo
from api.utils.app.randomstrings import make_app_uuid, make_from_user_uuid
from django.db.models import F
def udid_bytes_to_dict(xml_stream):
new_uuid_info = {}
try:
@ -89,6 +90,7 @@ def get_http_server_doamin(request):
server_domain = "%s://%s" % (protocol, HTTP_HOST)
return server_domain
def get_redirect_server_domain(request):
server_domain = SERVER_DOMAIN.get('REDIRECT_UDID_DOMAIN', None)
if not server_domain or not server_domain.startswith("http"):
@ -102,63 +104,86 @@ def get_redirect_server_domain(request):
class IosUtils(object):
def __init__(self,udid_info,app_obj):
self.udid_info=udid_info
def __init__(self, udid_info, app_obj):
self.udid_info = udid_info
self.app_obj = app_obj
self.user_obj = app_obj.user_id
self.get_developer_auth()
def get_developer_auth(self):
developer_obj = AppIOSDeveloperInfo.objects.filter(user_id=self.user_obj,is_actived=True,use_number__lte=F("usable_number")).first()
developer_obj = AppIOSDeveloperInfo.objects.filter(user_id=self.user_obj, is_actived=True,
use_number__lte=F("usable_number")).first()
auth = {
"username":developer_obj.email,
"username": developer_obj.email,
"password": developer_obj.password,
"certid":developer_obj.certid
"certid": developer_obj.certid
}
self.developer_obj = developer_obj
self.auth = auth
def create_cert(self):
app_api_obj = AppDeveloperApi(**self.auth)
app_api_obj.create_cert(self.user_obj)
file_format_path_name = self.file_format_path()
cert_info = None
try:
with open(file_format_path_name + '.info', "r") as f:
cert_info = f.read()
except Exception as e:
print(e)
cert_id = re.findall(r'.*\n\tid=(.*),.*', cert_info)[0].replace('"', '')
AppIOSDeveloperInfo.objects.filter(user_id=self.user_obj, email=self.auth.get("username")).first().update(
is_actived=True, certid=cert_id)
def download_profile(self):
app_api_obj = AppDeveloperApi(** self.auth)
app_api_obj = AppDeveloperApi(**self.auth)
bundleId = self.app_obj.bundle_id
app_id=self.app_obj.app_id
device_udid= self.udid_info.get('udid')
device_name=self.udid_info.get('product')
app_api_obj.get_profile(bundleId,app_id,device_udid,device_name,self.get_profile_full_path())
app_id = self.app_obj.app_id
device_udid = self.udid_info.get('udid')
device_name = self.udid_info.get('product')
app_api_obj.get_profile(bundleId, app_id, device_udid, device_name, self.get_profile_full_path())
def file_format_path(self):
cert_dir_name = make_app_uuid(self.app_obj.user_id, self.auth.get("username"))
cert_dir_path = os.path.join(SUPER_SIGN_ROOT, cert_dir_name)
if not os.path.isdir(cert_dir_path):
os.makedirs(cert_dir_path)
file_format_path_name = os.path.join(cert_dir_path, cert_dir_name)
return file_format_path_name
def get_profile_full_path(self):
cert_dir_name = make_app_uuid(self.user_obj,self.auth.get("username"))
cert_dir_path = os.path.join(SUPER_SIGN_ROOT,cert_dir_name,"profile")
cert_dir_name = make_app_uuid(self.user_obj, self.auth.get("username"))
cert_dir_path = os.path.join(SUPER_SIGN_ROOT, cert_dir_name, "profile")
if not os.path.isdir(cert_dir_path):
os.makedirs(cert_dir_path)
provisionName = os.path.join(cert_dir_path,self.app_obj.app_id)
return provisionName+ '.mobileprovision'
provisionName = os.path.join(cert_dir_path, self.app_obj.app_id)
return provisionName + '.mobileprovision'
def resign(self):
if AppUDID.objects.filter(app_id=self.app_obj, udid=self.udid_info.get('udid')).first().is_signed:
return
self.download_profile()
cert_dir_name = make_app_uuid(self.app_obj.user_id,self.auth.get("username"))
cert_dir_path = os.path.join(SUPER_SIGN_ROOT,cert_dir_name)
if not os.path.isdir(cert_dir_path):
os.makedirs(cert_dir_path)
file_format_path_name = os.path.join(cert_dir_path,cert_dir_name)
my_local_key=file_format_path_name+".key"
app_dev_pem =file_format_path_name+".pem"
ResignAppObj = ResignApp(my_local_key,app_dev_pem)
file_format_path_name = self.file_format_path()
my_local_key = file_format_path_name + ".key"
app_dev_pem = file_format_path_name + ".pem"
ResignAppObj = ResignApp(my_local_key, app_dev_pem)
random_file_name = make_from_user_uuid(self.user_obj)
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()
org_file = os.path.join(MEDIA_ROOT, release_obj.release_id + ".ipa")
new_file = os.path.join(MEDIA_ROOT, random_file_name + ".ipa")
ResignAppObj.sign(self.get_profile_full_path(),org_file,new_file)
ResignAppObj.sign(self.get_profile_full_path(), org_file, new_file)
newdata={
"is_signed":True,
"binary_file":random_file_name + ".ipa"
newdata = {
"is_signed": True,
"binary_file": random_file_name + ".ipa"
}
AppUDID.objects.filter(app_id=self.app_obj,udid=self.udid_info.get('udid')).update(**newdata)
AppUDID.objects.filter(app_id=self.app_obj, udid=self.udid_info.get('udid')).update(**newdata)
APPSuperSignUsedInfo.objects.create(app_id=self.app_obj, user_id=self.user_obj, developerid=self.developer_obj,
udid=self.udid_info.get('udid'))
AppIOSDeveloperInfo.objects.filter(user_id=self.user_obj, is_actived=True,
use_number__lte=F("usable_number")).first().update(
use_number=self.developer_obj.use_number + 1)

Loading…
Cancel
Save