Python Flask获取iOS的UDID

摘要:
--文件标题--˃<string>获取UDID˂/string><key>PayloadVersion˂/key><integer>1˂/integer><key<PayloadUUID˂/key>˂string>15113571-2012-654y-4511-f0ra0164cec˂/string>˂key>PayloadIdentifier˂/key>˂string>com。覆盖PayloadDescription此描述文件仅用于获取设备的UDID。请允许安装PayloadTypeProfileService上述配置文件中的URL是接收IOS设备返回的等效ID的接口。您可以填写任何其他信息或直接使用此配置文件。

测试iOS app时候,我们可以安装以下4种类型的包 :

AdHoc                 -- 一般为正式环境验证
AppStore             -- 上传AppStore,只有appstore审核通过发布出来后才能安装
Development       -- 一般为测试环境验证
Enterprise            -- 企业证书打包【仅企业账号使用】

其中AdHoc 、Development只有100个设备,  Enterprise不限用户、不限设备,所以没有Enterprise账号的话,只有把设备的udid加入账号后才能重新打包才能安装ipa包。

但获取udid是一件比较麻烦的事情:

网上有很多种方式:https://www.jianshu.com/p/f0ed370a8bc7

对大众来说,最简单是蒲公英网站提供的方式,扫个码,安装个描述文件就可以获取到,但毕竟是第三方的网站,安全是一方面,udid同时也泄露了。

那么怎样搭建一个和蒲公英一样的获取udid的内部网站呢?

第一步:

新建一个mobileconfig.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"  "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>PayloadContent</key>
        <dict>
            <key>URL</key>
            <!--接收数据的接口地址-->
            <string>https://axx.thxxxer.cn/get_udid</string>
            <key>DeviceAttributes</key>
            <array>
                <string>UDID</string>
                <string>IMEI</string>
                <string>ICCID</string>
                <string>VERSION</string>
                <string>PRODUCT</string>
            </array>
        </dict>
        <key>PayloadOrganization</key>
        <!--组织名称-->
        <string>com.cover.the</string>
        <key>PayloadDisplayName</key>
        <!--文件标题-->
        <string>获取UDID</string>
        <key>PayloadVersion</key>
        <integer>1</integer>
        <key>PayloadUUID</key>
        <!--随机生成的唯一GUID字符串-->
        <string>15113571-2012-654y-4511-f0ra10164cec</string>
        <key>PayloadIdentifier</key>
        <string>com.cover.the</string>
        <key>PayloadDescription</key>
        <!--文件描述-->
        <string>本描述文件仅用来获取设备的UDID,请允许安装!</string>
        <key>PayloadType</key>
        <string>Profile Service</string>
    </dict>
</plist>

上面的配置文件里URl是接收ios设备返回udid等值的接口,其他都可以随便填写,也可以直接用这个配置文件。

第二步:

如果mobileconfig.xml文件不签名的话,安装到手机上会显示红色的“未签名”,我们需要对这个配置文件进行一下签名:

两个命令搞定:

/usr/bin/security find-identity -p codesigning -v

这个命令可以查询到mac上可用的证书,做ios开发的或者经常打包ipa的都知道,若自己电脑上没有的话,找ios开发的同学给你一个证书名称就行:

Python Flask获取iOS的UDID第1张

 这个双引号之间的名称Apple Development: danxxao dang (qweqw4L=P3)就是我们想要的:

接着执行下面的命令,当然,把mobileconfig.xml文件名修改为udid.mobileconfig:

/usr/bin/security cms -S -N "Apple Development: danxxao dang (qweqw4L=P3)" -i /Users/jakey/Desktop/udid.mobileconfig -o /Users/jakey/Desktop/udid_signed.mobileconfig

执行完后会生成udid_signed.mobileconfig文件,我们可以再改回mobileconfig.xml文件名备用。

第三步:

还记得刚开始mobileconfig.xml文件里的接收接口么,这个地址是需要https的,http是不能访问的,怎么配置https呢?

见前一篇文章:Flask、Tornado、Nginx搭建Https服务

Python Flask获取iOS的UDID第2张

 第四步:

搭建flask网站:

1.创建视图:

# -*- coding = utf-8 -*-
# ------------------------------
# @time: 2021/6/29 17:30
# @Author: drew_gg
# @File: get_ios_udid.py
# @Software: cover_app_platform
# ------------------------------

import os
from flask import Blueprint,  request, render_template, redirect, url_for, Response
from app.common.common_ios_type import get_ios_type as ios_type


ios_udid = Blueprint('ios_udid', "__main__")

pl = os.getcwd().split('cover_app_platform')
xml_path = pl[0] + r'cover_app_platform\app\static\xml\'

# 定义全局变量
udid_l = []


@ios_udid.route('/index_udid/', methods=['GET', 'POST'])
def index_udid():
    """
    获取udid首页
    """
    return render_template('/post/get_udid/udid.html')


@ios_udid.route('/show_udid/', methods=['GET', 'POST'])
def show_udid():
    """
    展示获取到的udid页面
    """
    return render_template('/post/get_udid/show_udid.html', data=udid_l)


@ios_udid.route('/down_config/', methods=['GET', 'POST'])
def down_config():
    """
    ios设备访问下载配置文件
    """
    def file_content(f_p):
        with open(f_p, 'rb') as f:
            return f.readlines()
    file_path = xml_path + 'mobileconfig.xml'
    filename = os.path.basename(file_path)
    response = Response(file_content(file_path))
    # 这里的Content-Type一定要设置为application/x-apple-aspen-config
    response.headers['Content-Type'] = 'application/x-apple-aspen-config; chatset=utf-8'
    response.headers['Content-Disposition'] = 'attachment;filename="{}"'.format(filename)
    return response


@ios_udid.route('/get_udid/', methods=['GET', 'POST'])
def get_udid():
    """
    获取设备返回的值
    """
    global udid_l
    b_data = request.data
    data_str = str(b_data).split('<?xml')[-1].split('</plist>')[0].split('dict')[1].replace('\n', '').replace('\t', '')
        .replace('>', '').replace('<', '').replace('/', '').replace('string', '').split('key')
    udid = data_str[4]
    product = ios_type.get_phone(data_str[2])
    version = data_str[6]
    udid_l = [udid, product, version]
    # 这里一定要对301进行重定向
    return redirect(url_for('ios_udid.show_udid'), code=301)

以上需要注意的地方我都注释了,比如Content-Type和301重定向!

当然,直接获取到的手机型号和真实型号是有个对应关系的,比如我们获取到的是iPhone12,3,实际是iPhone 11 Pro,这个对应关系网上可以查到,开发ios的话,xcode插件里也有:

# -*- coding = utf-8 -*-
# ------------------------------
# @time: 2021/7/1 5:18 PM
# @Author: drew_gg
# @File: get_ios_type.py
# @Software: FM_APP_PKG
# ------------------------------


def get_phone(ios_type):
    if ios_type in ["iPhone3,1", "iPhone3,2", "iPhone3,3"]:
        return "iPhone 4"
    if ios_type in ["iPhone4,1"]:
        return "iPhone 4s"
    if ios_type in ["iPhone5,1", "iPhone5,2"]:
        return "iPhone 5"
    if ios_type in ["iPhone5,3", "iPhone5,4"]:
        return "iPhone 5c"
    if ios_type in ["iPhone6,1", "iPhone6,2"]:
        return "iPhone 5s"
    if ios_type in ["iPhone7,2"]:
        return "iPhone 6"
    if ios_type in ["iPhone7,1"]:
        return "iPhone 6 Plus"
    if ios_type in ["iPhone8,1"]:
        return "iPhone 6s"
    if ios_type in ["iPhone8,2"]:
        return "iPhone 6s Plus"
    if ios_type in ["iPhone8,3"]:
        return "iPhone SE (GSM+CDMA)"
    if ios_type in ["iPhone8,4"]:
        return "iPhone SE (GSM)"
    if ios_type in ["iPhone9,1"]:
        return "iPhone 7 (CDMA)"
    if ios_type in ["iPhone9,2"]:
        return "iPhone 7 Plus (CDMA)"
    if ios_type in ["iPhone9,3"]:
        return "iPhone 7 (GSM)"
    if ios_type in ["iPhone9,4"]:
        return "iPhone 7 Plus (GSM)"
    if ios_type in ["iPhone10,1"]:
        return "iPhone 8 (CDMA)"
    if ios_type in ["iPhone10,2"]:
        return "iPhone 8 Plus (CDMA)"
    if ios_type in ["iPhone10,3"]:
        return "iPhone X (CDMA)"
    if ios_type in ["iPhone10,4"]:
        return "iPhone 8 (GSM)"
    if ios_type in ["iPhone10,5"]:
        return "iPhone 8 Plus (GSM)"
    if ios_type in ["iPhone10,6"]:
        return "iPhone X (GSM)"
    if ios_type in ["iPhone11,2"]:
        return "iPhone XS"
    if ios_type in ["iPhone11,4"]:
        return "iPhone XS Max China"
    if ios_type in ["iPhone11,6"]:
        return "iPhone XS Max"
    if ios_type in ["iPhone11,8"]:
        return "iPhone XR"
    if ios_type in ["iPhone12,1"]:
        return "iPhone 11"
    if ios_type in ["iPhone12,3"]:
        return "iPhone 11 Pro"
    if ios_type in ["iPhone12,5"]:
        return "iPhone 11 Pro Max"
    if ios_type in ["iPhone12,8"]:
        return "iPhone SE 2nd Gen"
    if ios_type in ["iPhone13,1"]:
        return "iPhone 12 mini"
    if ios_type in ["iPhone13,2"]:
        return "iPhone 12"
    if ios_type in ["iPhone13,3"]:
        return "iPhone 12 Pro"
    if ios_type in ["iPhone13,4"]:
        return "iPhone 12 Pro Max"
    if ios_type in ["i386", "x86_64"]:
        return "Simulator"
    else:
        return "I do not know !"

2.创建html页面(css文件去掉了,这两个网站随便整都行):

udid.html:

<!DOCTYPE html>
<head>
<title>封面 | 快速获取 iOS 设备的UDID</title>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta property="og:type" content="webpage">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
</head>
<body class="tools-box">
<div class="container-fluid wrapper">
<div class="container content inner-content" style="padding-bottom:40px;">
    <div class="row">
        <div class="col-md-10 col-md-offset-1 col-sm-8 col-sm-offset-2">
            <div class="row text-center">
                <div class="margin-bottom-30">
                    <h2 class="font-36 color-333">一步快速获取  iOS  设备的 UDID</h2>
                </div>
            </div>
            <div class="row text-center">
                <div class="col-md-12">
                    <p class="mb-40 color-8c9497 font-16">请使用 <span class="color-green">iPhone或iPad</span>上的<span class="color-green">Safari</span>浏览器或<span class="color-green">相机</span>扫描下面的二维码,即可快速获取 UDID</p>
                </div>
                <div class="row text-center" id="UDIDQR">
                    <div class="col-md-8 col-xs-12 col-md-offset-2 mt-40">
                        <div class="row" style="  ">
                            <div class="col-md-6 col-xs-12  col-sm-6 mb-40">
                                <img src="https://pkg/fm/1.1.0/cover.png" style="height:220px" />
                            </div>
                            <div class="col-md-6 col-xs-12  col-sm-6 mb-0">
                                <div id="UDIDQRImg" style="">
                                    <img src="https://pkg/fm/1.2.0/iosudid.png?content=https://apxx.the.cn/down_config" class="udid img-responsive center-block"/>
                                    <p class="mt-5">扫描二维码,获取 UDID</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <hr style="border-top:2px solide #e6e6e6;" />
            <div class="col-md-10 col-md-offset-1 input-group margin-bottom-20 mt-60">
                <p class="font-18 color-333 ">扫码后怎么操作呢</p>
                <p class="color-8c9497 mb-35">扫码后会下载一个描述文件,需要安装,步骤如下:<br>
                    <font color="red">
                        1. ios手机打开“设置”; <br>
                        2. 找到“通用”并点击; <br>
                        3. 找到“描述文件与设备管理”或“设备管理”并点击; <br>
                        4. 找到“查询设备UDID”并点击; <br>
                        5. 点击右上角的“安装”按钮即可。<br>
                    </font>
                </p>
                <p class="font-18 color-333">什么是UDID?</p>
                <p class="color-8c9497 mb-35">UDID 是 iOS 设备的一个唯一识别码,每台 iOS 设备都有一个独一无二的编码,这个编码,我们称之为识别码,也叫做UDID( Unique Device Identifier)。</p>
            </div>
        </div>
    </div>
</div>
</div>
</body>
</html>

show_udid.html:

<!DOCTYPE html>
<head>
<title>封面 | 快速获取 iOS 设备的UDID</title>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta property="og:type" content="webpage">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
</head>
<body class="tools-box">
<div class="container-fluid wrapper">
<div class="container content inner-content">
    <div class="row">
    <div class="col-md-10 col-md-offset-1 col-sm-8 col-sm-offset-2">
    <div class="row text-center" style="margin-left: 0; margin-right: 0;">
    <div class="row text-center" id="UDIDQR">
        <div class="col-md-8 col-xs-12 col-md-offset-2 mt-40">
            <div class="row" style="  ">
                <div class="col-md-6 col-xs-12  col-sm-6 mb-40">
                    <img src="https://p1.0/cover.png" style="height:220px" />
                </div>
            </div>
        </div>
    </div>
        <h5 class="color-878f92 font-16 mb-15" style="text-align: left;">设备信息UDID:</h5>
        <div style="text-align: left;word-break:break-all;background: #f3f3f3;border-radius: 4px;min-height: 40px;height: auto;padding: 8px 10px;border: 1px solid #ddd;" class="tag-box tag-box-v3 mb-25">
            <p class="color-333" style="font-size: 14px">{{data[0]}}</p>
        </div>
        <h5 class="color-878f92 font-16 mb-15" style="text-align: left;">设备型号:</h5>
        <div style="text-align: left;word-break:break-all;background: #f3f3f3;border-radius: 4px;min-height: 40px;height: auto;padding: 8px 10px;border: 1px solid #ddd;" class="tag-box tag-box-v3 mb-25">
            <p class="color-333" style="font-size: 14px">{{data[1]}}</p>
        </div>
        <h5 class="color-878f92 font-16 mb-15" style="text-align: left;">版本号:</h5>
        <div style="text-align: left;word-break:break-all;background: #f3f3f3;border-radius: 4px;min-height: 40px;height: auto;padding: 8px 10px;border: 1px solid #ddd;" class="tag-box tag-box-v3 mb-25">
            <p class="color-333" style="font-size: 14px">{{data[2]}}</p>
        </div>

</div>
</div>
</body>
</html>

然后app里注册蓝图即可

Python Flask获取iOS的UDID第3张

ok,到此为止,我们就自己搭建完成了flask获取udid网站:

 Python Flask获取iOS的UDID第4张

Python Flask获取iOS的UDID第5张

Python Flask获取iOS的UDID第6张

 有兴趣搭建遇到问题的,欢迎讨论。

免责声明:文章转载自《Python Flask获取iOS的UDID》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Python3.x基础教程3上分页(模仿百度)下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

python生成随机数、随机字符串

python生成随机数、随机字符串 python生成随机数、随机字符串 import randomimport string # 随机整数:print random.randint(1,50) # 随机选取0到100间的偶数:print random.randrange(0, 101, 2) # 随机浮点数:print random.random()p...

离线安装 Python三方包

方式一: 首先我们得从PyPI上先下载要装的第三方包 PyPI官方网址 :https://pypi.org/ PyPI(Python Package Index)是python官方的第三方bai库的仓库,所有人都可以下载第三方库或上传自己开发zhi的库到PyPI。PyPI推荐使用pip包管理器来下载第三方库。 下载下来我们需要安装的三方包 有一些包在安...

【XStream】xml和java实体的相互转化

1.pom.xml <!-- xstream xml和Java对象转化 --> <dependency> <groupId>xstream</groupId> <artifactId>xstream</artifactId...

c++设计模式:装饰者模式(Decorator Pattern)

定义: 装饰者模式动态的将责任附加到对象上。若要扩展功能,装饰者提供了比继承更有弹性的替代方案。 场景: 我们购买咖啡的时候,可以要求在其中加入各种调料,例如:蒸奶、豆浆、摩卡或覆盖奶泡,而咖啡店也会根据所加入的调料收取不同的费用,所以当我们设计订单系统的时候就需要考虑到这些调料部分啦。顾客的需求不一,如果我们针对每种配方都声明一个类得话,系统的维护将会十...

nRF5 SDK for Mesh(三) Installing the mesh toolchain 安装编译工具链

Installing the mesh toolchain To build the example applications, a toolchain based on either CMake or SEGGER Embedded Studio is required. Install instructions are provided for Wi...

SpringBoot入门 (四) 数据库访问之JdbcTemplate

  本文记录在SpringBoot中使用JdbcTemplate访问数据库。 一 JDBC回顾   最早是在上学时接触的使用JDBC访问数据库,主要有以下几个步骤: 1 加载驱动 Class.forName(Driver) 2 获取数据库连接 conn = DriverManager.getConnection(url, user,password) 3...