积分墙(通过Safari浏览器获取iOS设备UDID)

标签:      

本文基于在线安装Profile来实现获取UDID

演示:用Safari浏览器打开

演示链接: 获取iOS设备UDID

通过苹果Safari浏览器获取iOS设备UDID步骤

1、在你的Web服务器上创建一个.mobileconfig的XML格式的描述文件;
2、用户在所有操作之前必须通过某个点击操作完成.mobileconfig描述文件的安装;
3、服务器需要的数据,比如:UDID,需要在.mobileconfig描述文件中配置好,以及服务器接收数据的URL地址(此地址必须为https);
4、当用户设备完成数据的手机后,返回提示给客户端用户;

.mobileconfig

<?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://ex.eyunzhu.com/jfq/getUDID/receive.php</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>eyunzhu.com</string>
        <key>PayloadDisplayName</key>
        <string>查询设备UDID</string>
        <key>PayloadVersion</key>
        <integer>1</integer>
        <key>PayloadUUID</key>
        <string>3C4DC7D2-E475-3375-489C-0BB8D737A653</string>
        <key>PayloadIdentifier</key>
        <string>dev.skyfox.profile-service</string>
        <key>PayloadDescription</key>
        <string>本文件仅用来获取设备ID</string>
        <key>PayloadType</key>
        <string>Profile Service</string>
    </dict>
</plist>

你需要填写回调数据的URL和PayloadUUID。该PayloadUUID仅仅是随机生成的唯一字符串,类似bundleid,一般是域名倒置,用来标识唯一。

iOS12 mobileconfig中的URL要用https地址(例如 https://dev.skyfox.org/udid/receive.php)。否者会报ATS错误。

注意:mobileconfig下载时设置文件内容类型Content Type为:application/x-apple-aspen-config 否则可能不能下载

当访问mobileconfig文件不能直接下载时 就需要设置mime content type了,application/x-apple-aspen-config

设置content type大体上两种方法 :

  1. .htaccess增加如下配置
<IfModule mod_mime.c>
        AddType application/x-apple-aspen-config .mobileconfig
</IfModule>

2.php等动态语言直接设置

header('Content-type: application/x-apple-aspen-config; chatset=utf-8');
header('Content-Disposition: attachment; filename="company.mobileconfig"');
echo $mobileconfig;

iOS设备安装.mobileconfig描述文件

新建一个用于下载mobileconfig的网页,这里我命名为index.php

<?php
$UDID = $_GET['UDID'] ? $_GET['UDID'] : $_POST['UDID'];
?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <meta content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0,user-scalable=no" name="viewport" id="viewport" />
 <script src="clipboard.min.js"></script>

<title>获取您的UDID</title>
<style type="text/css">
body {
    margin: 0;
    padding: 0;
    color: #333;
    font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
    font-size: 14px;
    line-height: 1.42857;
}
#content {
    width: 96%;
    padding: 0px 0;
    margin: 0 auto;
    text-align: center;
}

#header{
    background-color: #1aa79a;
    height: 120px;
    margin: 0;
    padding: 0;
    color: white;
    font-size: 50px;
    padding-top: 40px;
    text-align: center;
}
#showText{
    font-size: 18px;
    width: 100%;
    padding:0;
    height:40px;
    /* text-align: center; */
}
.udid-intro {
    color: #8c9293;
    line-height: 24px;
}
#footer{
    border-top: 1px solid #979797;
    font-family: "Roboto Slab","Helvetica Neue",Helvetica,"Hiragino Sans GB",Arial,sans-serif;
    margin-top: 50px;
    padding-bottom: 70px;
    padding-top: 30px;
    text-align: center;

}
.buttons{
    background: #1AA79A none repeat scroll 0 0;
    border: 1px solid #777;
    border-radius: 8px;
    box-shadow: 0 -1px 3px rgba(255, 255, 255, 0.5) inset, 0 2px 2px rgba(0, 0, 0, 0.2);
    color: #fff;
    cursor: pointer;
    font-family: "Microsoft Yahei",Arial,Tahoma,sans-serif;
    font-size: 14px;
    font-style: normal;
    font-weight: bold;
    padding: 8px 12px;
    margin-left:10px;
    text-decoration: none;
    text-shadow: -1px -1px rgba(0, 0, 0, 0.1), 0 0 15px rgba(255, 255, 255, 0.75);
    text-transform: none;
    white-space: nowrap;

}
</style>

</head>
<body>
<div id="header">
     UDID
</div>

<div id="content">
<br><br>

<input  name="" id="showText" placeholder="点击获取UDID即可获取(请使用Safari打开)"  value="<?php echo $UDID; ?>" /> 

<br><br>

<a class="buttons" href="udid.mobileconfig" target="_blank">获取UDID</a>
<a class="buttons" id="copyButton" data-clipboard-target="#showText">拷贝UDID</a>

<br><br>

<p class="udid-intro">UDID 是一种 iOS 设备的特殊识别码。除序号之外,每台 iOS 装置都另有一组独一无二的号码,我们就称之为识别码( Unique Device Identifier, UDID )。就像我们的身份证一样。开发者需要知道你的 UDID,才可以让你的手机安装访问测试中的应用,就像需要你的身份证才可以让你登机一样 :)</p>

<!-- <a class="buttons" href="xxapp://?function=valid&uuid=<?php echo $UDID; ?>&secret=dhasdjh5521673hghdsah">2.验证ipa</a> -->

<br>

</div>
<div id="footer">
@UDID
</div>
</body>

<script type="text/javascript">
        //init
     var clipboard = new ClipboardJS('#copyButton');
    //优雅降级:safari 版本号>=10,提示复制成功;否则提示需在文字选中后,手动选择“拷贝”进行复制
    clipboard.on('success', function(e) {
        alert('复制成功!')
        e.clearSelection();
    });
    clipboard.on('error', function(e) {
        alert('请选择“拷贝”进行复制!')
    });
 </script>
</html>

服务器接收返回数据并显示

使用xml等解析库解析数据后,直接把需要的UDID等设备信息传到显示页面即可

<?php
$data = file_get_contents('php://input');
$plistBegin = '<?xml version="1.0"';
$plistEnd = '</plist>';
$pos1 = strpos($data, $plistBegin);
$pos2 = strpos($data, $plistEnd);
$data2 = substr($data, $pos1, $pos2 - $pos1);
$xml = xml_parser_create();
xml_parse_into_struct($xml, $data2, $vs);
xml_parser_free($xml);
$UDID = "";
$CHALLENGE = "";
$DEVICE_NAME = "";
$DEVICE_PRODUCT = "";
$DEVICE_VERSION = "";
$iterator = 0;
$arrayCleaned = array();
foreach ($vs as $v) {
    if ($v['level'] == 3 && $v['type'] == 'complete') {
        $arrayCleaned[] = $v;
    }
    $iterator++;
}
$data = "";
$iterator = 0;
foreach ($arrayCleaned as $elem) {
    $data.= "\n==" . $elem['tag'] . " -> " . $elem['value'] . "<br/>";
    switch ($elem['value']) {
        case "CHALLENGE":
            $CHALLENGE = $arrayCleaned[$iterator + 1]['value'];
        break;
        case "DEVICE_NAME":
            $DEVICE_NAME = $arrayCleaned[$iterator + 1]['value'];
        break;
        case "PRODUCT":
            $DEVICE_PRODUCT = $arrayCleaned[$iterator + 1]['value'];
        break;
        case "UDID":
            $UDID = $arrayCleaned[$iterator + 1]['value'];
        break;
        case "VERSION":
            $DEVICE_VERSION = $arrayCleaned[$iterator + 1]['value'];
        break;
    }
    $iterator++;
}
$params = "UDID=" . $UDID . "&CHALLENGE=" . $CHALLENGE . "&DEVICE_NAME=" . $DEVICE_NAME . "&DEVICE_PR ODUCT=" . $DEVICE_PRODUCT . "&DEVICE_VERSION=" . $DEVICE_VERSION;
//header("Location: http://dev.skyfox.org/udid?data=".rawurlencode($params));
header('HTTP/1.1 301 Moved Permanently');
header("Location: https://ex.eyunzhu.com/jfq/getUDID/?" . $params);
?>

此时访问index.php页面即可

对mobileconfig文件进行签名

安装描述文件时,会提醒描述文件未签名,mobileconfig 签名有几种方法,这里使用SSL证书对IOS描述文件mobileconfig的签名认证

重命名证书密钥文件名(Apache SSL证书文件)如下:

  • server.crt (证书)
  • ca.crt(root_bundle证书)
  • server.key (密钥)

命令行进行签名

openssl smime -sign -in uuid.mobileconfig -out signed.mobileconfig -signer server.crt -inkey server.key  -certfile ca.crt -outform der -nodetach

源代码下载:GitHub


发表评论 登录

目前评论:1

  • avatar YZ7Z 回复 2022-12-31 13:11:30

    UDID