1.整體思路:
a.在你的Web服務(wù)器上創(chuàng)建一個(gè).mobileconfig的XML格式的描述文件
b.用戶點(diǎn)擊按鈕完成.mobileconfig描述文件的安裝 操作
c.服務(wù)器需要的數(shù)據(jù),比如:UDID,需要在.mobileconfig描述文件中配置好,以及服務(wù)器接收數(shù)據(jù)的URL地址(此地址必須為https)
d.當(dāng)用戶設(shè)備完成數(shù)據(jù)的手機(jī)后,返回提示給客戶端用戶
2..mobileconfig文件的內(nèi)容
<?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://xxxx.xxx.com/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>查詢?cè)O(shè)備UDID</string>
<key>PayloadVersion</key>
<integer>1</integer>
<key>PayloadUUID</key>
<string>3C4DC7D2-E475-7533-489C-0BB8D373A653</string>
<key>PayloadIdentifier</key>
<string>dev.skyfox.profile-service</string>
<key>PayloadDescription</key>
<string>本文件僅用來獲取設(shè)備ID</string>
<key>PayloadType</key>
<string>Profile Service</string>
</dict>
</plist>
注意事項(xiàng):
你需要填寫回調(diào)數(shù)據(jù)的URL和PayloadUUID。該P(yáng)ayloadUUID僅僅是隨機(jī)生成的唯一字符串,類似bundleid,一般是域名倒置,用來標(biāo)識(shí)唯一。
iOS12 mobileconfig中的URL要用https地址(例如 https://dev.skyfox.org/udid/receive.php)。否者會(huì)報(bào)ATS錯(cuò)誤。
注意:mobileconfig下載時(shí)設(shè)置文件內(nèi)容類型Content Type為:application/x-apple-aspen-config 否則可能不能下載
當(dāng)訪問mobileconfig文件不能直接下載時(shí) 就需要設(shè)置mime content type了,application/x-apple-aspen-config
設(shè)置content type大體上兩種方法 :
1.htaccess增加如下配置
<IfModule mod_mime.c>
AddType application/x-apple-aspen-config .mobileconfig
</IfModule>
2.php等動(dòng)態(tài)語(yǔ)言直接設(shè)置
header('Content-type: application/x-apple-aspen-config; chatset=utf-8');
header('Content-Disposition: attachment; filename="company.mobileconfig"');
echo $mobileconfig;
3.本人參考的首頁(yè)內(nèi)容如下(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="點(diǎn)擊獲取UDID即可獲取(請(qǐng)使用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 設(shè)備的特殊識(shí)別碼。除序號(hào)之外,每臺(tái) iOS 裝置都另有一組獨(dú)一無(wú)二的號(hào)碼,我們就稱之為識(shí)別碼( Unique Device Identifier, UDID )。就像我們的身份證一樣。開發(fā)者需要知道你的 UDID,才可以讓你的手機(jī)安裝訪問測(cè)試中的應(yīng)用,就像需要你的身份證才可以讓你登機(jī)一樣 :)</p>
<!-- <a class="buttons" href="xxapp://?function=valid&uuid=<?php echo $UDID; ?>&secret=dhasdjh5521673hghdsah">2.驗(yàn)證ipa</a> -->
<br>
</div>
<div id="footer">
@UDID
</div>
</body>
<script type="text/javascript">
//init
var clipboard = new ClipboardJS('#copyButton');
//優(yōu)雅降級(jí):safari 版本號(hào)>=10,提示復(fù)制成功;否則提示需在文字選中后,手動(dòng)選擇“拷貝”進(jìn)行復(fù)制
clipboard.on('success', function(e) {
alert('復(fù)制成功!')
e.clearSelection();
});
clipboard.on('error', function(e) {
alert('請(qǐng)選擇“拷貝”進(jìn)行復(fù)制!')
});
</script>
</html>
4.服務(wù)端的receive.php文件內(nèi)容如下
<?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); // 很重要不能刪 (重定向頁(yè)面是否只能是請(qǐng)求頁(yè)面?)**
?>
以下內(nèi)容未實(shí)踐,暫且記錄下來
對(duì)mobileconfig文件進(jìn)行簽名
安裝描述文件時(shí),會(huì)提醒描述文件未簽名,mobileconfig 簽名有幾種方法,這里使用SSL證書對(duì)IOS描述文件mobileconfig的簽名認(rèn)證
重命名證書密鑰文件名(Apache SSL證書文件)如下:
server.crt (證書)
ca.crt(root_bundle證書)
server.key (密鑰)
命令行進(jìn)行簽名
openssl smime -sign -in uuid.mobileconfig -out signed.mobileconfig -signer server.crt -inkey server.key -certfile ca.crt -outform der -nodetach
PS:問題描述:
a.一直報(bào) “無(wú)效的描述文件”
原因:
1..mobileconfig文件里面配置的URL鏈接必須是https的
2.服務(wù)器的301 重定向必須要寫, 而且只能重定向回請(qǐng)求頁(yè)面(就算服務(wù)器的301不寫,也是可以正常收到數(shù)據(jù)的)
b..mobileconfig無(wú)法下載,路徑配置的是正確的(本人將.mobileconfig文件放在本地沒有遇到該問題,但是放到服務(wù)器就遇到該問題,打算采用這兩種方式來修改,后續(xù)更新結(jié)果)
當(dāng)訪問mobileconfig文件不能直接下載時(shí) 就需要設(shè)置mime content type了,application/x-apple-aspen-config
設(shè)置content type大體上兩種方法 :
1.htaccess增加如下配置
<IfModule mod_mime.c>
AddType application/x-apple-aspen-config .mobileconfig
</IfModule>
2.php等動(dòng)態(tài)語(yǔ)言直接設(shè)置
header('Content-type: application/x-apple-aspen-config; chatset=utf-8');
header('Content-Disposition: attachment; filename="company.mobileconfig"');
echo $mobileconfig;
基本參考,感謝:獲取UDID