須要準備的東西php
1,安裝描述文件只支持https的回調地址,因此須要申請https域名ios
2,描述文件簽名,不安裝也可,只要能接受紅色的字ajax
步驟:sql
<?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://caipudq.cn/home/ajax/getuid</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>www.xman.com</string>
<key>PayloadDisplayName</key>
<string>caipu</string>
<key>PayloadVersion</key>
<integer>1</integer>
<key>PayloadUUID</key>
<string>abc66063-61b1-4348-ac01-d815a073ff5e</string>
<key>PayloadIdentifier</key>
<string>com.yun-bangshou.profile-service</string>
<key>PayloadDescription</key>
<string>該配置文件將幫助用戶獲取當前iOS設備的UDID號碼。</string>
<key>PayloadType</key>
<string>Profile Service</string>
</dict>
</plist>瀏覽器
此版本是生成文件直接下載的版本app
$path = WEB_ROOT .'static/mobileconfig.xml';
$pathto = WEB_ROOT .'static/udid.mobileconfig';
$url = config('API_HOSTS').'/user/getudid/?uid='.$uid;//config('API_HOST').'/user/getudid/uid/'.$uid;
changexml_fun($path,$url,$pathto);
//Atom
header('Content-type: application/x-apple-aspen-config');
//header("Accept-Ranges:bytes");
//header("Accept-Length:" . filesize($pathto));
//header("Content-Disposition:attachment;filename=udid.mobileconfig");
//@readfile($pathto);
$mobileconfig = file_get_contents($pathto);
//echo $mobileconfig;
header('location:'.config('API_HOST').'static/udid.mobileconfig');ui
若是是讀取則須要加this
header('Content-type: application/x-apple-aspen-config; chatset=utf-8');
header('Content-Disposition: attachment; filename="company.mobileconfig"');
echo $mobileconfig;url
回調地址只是中間跳轉,蘋果會從這裏的301跳轉到瀏覽器,因此安裝完描述文件默認是會跳到瀏覽器裏,在代碼最後要進行301跳轉。
$uid = $this->request->param('uid');
$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 = "uid=".$uid."&UDID=".$UDID."&CHALLENGE=".$CHALLENGE."&DEVICE_NAME=".$DEVICE_NAME."&DEVICE_PRODUCT=".$DEVICE_PRODUCT."&DEVICE_VERSION=".$DEVICE_VERSION;spa
$dataaa['text']=$params;
db::table('mk_test')->insert($dataaa);
//echo db::table('mk_test')->getlastsql();
// enrollment is a directory
header('HTTP/1.1 301 Moved Permanently');
header('Location:'.config('API_HOSTS').'user/saveudid/?'.($params),TRUE,301);
exit;
這裏必定要注意:
重定向必定要使用301重定向,有些重定向默認是302重定向,這樣就會致使安裝失敗,設備安裝會提示"無效的描述文件
$uid = $this->request->param('uid');
$udid = $this->request->param('UDID');
//todo處理獲取到的udid