zoukankan      html  css  js  c++  java
  • Python Flask获取iOS的UDID

    测试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开发的同学给你一个证书名称就行:

     这个双引号之间的名称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服务

     第四步:

    搭建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里注册蓝图即可

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

     

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

  • 相关阅读:
    课程作业08:课后作业之字串加密、动手动脑之String.equals()方法、整理String类的Length()、charAt()、 getChars()、replace()、 toUpperCase()、 toLowerCase()、trim()、toCharArray()使用说明、阅读笔记发表到博客园。
    课程作业07:请编写一个程序,使用上述算法加密或解密用户输入的英文字符串。
    课程作业06:验证课件上的代码,并将所有的动手动脑或要求发表博客作业部分整理成一篇博客发表。
    课程作业05:使用类的静态字段和构造函数,我们可以跟踪某个类所创建对象的个数。请写一个类,在任何时候都可以向它查询“你已经创建了多少个对象?”
    Django 学习之用户认证组件auth与User对象
    Django 学习之中间件Middleware
    Django学习 之后端视图与ajax
    Django 学习之cookie与session
    Django 学习 之ORM聚合查询分组查询与F查询与Q查询
    Django 学习 之ORM多表操作
  • 原文地址:https://www.cnblogs.com/drewgg/p/14974013.html
Copyright © 2011-2022 走看看