需要准备的东西
1,安装描述文件只支持https的回调地址,所以需要申请https域名
2,描述文件签名,不安装也可,只要能接受红色的字
步骤:
<?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>i 红包</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>
此版本是生成文件直接下载的版本
$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;
回调地址只是中间跳转,苹果会从这里的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;
$dataaa['text']=$params; db::table('mk_test')->insert($dataaa); //echo db::table('mk_test')->getlastsql(); // enrollment is a directoryheader('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
转载于:https://www.cnblogs.com/mengzhilva/p/11572505.html
相关资源:iOS 通过 描述文件获取 UDID