苹果ios通过描述文件获取udid
需要准备的东西
1,安装描述文件只支持https的回调地址,所以需要申请https域名
2,描述文件签名,不安装也可,只要能接受红色的字
步骤:
1,准备xml文件
2,生成xml文件逻辑
此版本是生成文件直接下载的版本
$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');
如果是读取则需要加
header('Content-type: application/x-apple-aspen-config; chatset=utf-8');
header('Content-Disposition: attachment; filename="company.mobileconfig"');
echo $mobileconfig;
3,回调地址的写法
回调地址只是中间跳转,苹果会从这里的301跳转到浏览器,所以安装完描述文件默认是会跳到浏览器里,在代码最后要进行301跳转。
$uid = $this->request->param('uid');
$data = file_get_contents('php://input');
$plistBegin = ' $plistEnd = '';
$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']."
";
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;
$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重定向,这样就会导致安装失败,设备安装会提示"无效的描述文件
4,最终处理udid
$uid = $this->request->param('uid');
$udid = $this->request->param('UDID');
//todo处理获取到的udid