itms-services协议:跳转网页部署及PHP动态生成 iOS渠道包IPA一键安装之plist

WBOY
Freigeben: 2016-06-23 13:29:24
Original
9232 Leute haben es durchsucht

相信很多人尝试过使用揣果测试库(http://ipa.chuaiguo.com/)的无线安装测试IPA安装包功能。有心人一定注意到其itms-services协议的一键安装地址的url=部分并不是我们常见的plist文件路径,而是一个install.php通过增加参数的形式自动生成输出了plist。之前因为笔者的项目中渠道包不多,所以懒得去写这样一个文件帮助部署,可是最近,笔者的项目的渠道包不断增多了,显然部署多个plist文件管理上似乎越来越麻烦了,于是笔者开始仿照揣果实现了并结合自己项目的需求,实现了PHP动态生成 iOS渠道包IPA一键安装之plist。这里跟大家分享一下,希望对您有所帮助。

 <!--*** index.html* iOS渠道包一键安装跳转页面。* Created by pcjbird on 2015-05-28* Copyright (c) 2015年 Zero Status. All rights reserved.*--><html><head><title>iOS 一键安装</title><meta http-equiv="Content-Type" content="text/HTML; charset=utf-8"><meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" name="viewport" /><script type="text/javascript">function doLocation(url){ var a = document.createElement("a"); if(!a.click)  { window.location = url; return; } a.setAttribute("href", url); a.style.display = "none"; document.body.appendChild(a); a.click();}function getQueryString(str){ var rs=new RegExp("(^|)"+str+"=([^&]*)(&|$)","gi").exec(locString),tmp; if(tmp=rs)return tmp[2]; return "";}</script></head><body>下载中...<script type="text/javascript">var locString=String(window.document.location.href);var cid = getQueryString('cid');var sslServer = 'https://www.lessney.com/';var mainChannelId = 2;var curVersionName = '1.0.3';if (!cid) { cid = mainChannelId;}doLocation('itms-services://?action=download-manifest&url=' + encodeURIComponent(sslServer + 'install.php?v=' + curVersionName + '&cid=' + cid));</script></body></html>
Nach dem Login kopieren
 <?php/*** install.php* PLIST文件生成器,用于iOS渠道包一键安装。* Created by pcjbird on 2015-05-28* Copyright (c) 2015年 Zero Status. All rights reserved.*///判断是否为字典数组(dict)function isDict($array){ return (is_array($array) && 0 !== count(array_diff_key($array, array_keys(array_keys($array)))));}//向xml节点中写入字典数组(dict)function xmlWriteDict(XMLWriter $x, &$dict) { $x->startElement('dict'); foreach($dict as $k => &$v)  { $x->writeElement('key', $k); xmlWriteValue($x, $v); } $x->endElement();}  //向xml节点中写入数组(array)function xmlWriteArray(XMLWriter $x, &$arr) { $x->startElement('array'); foreach($arr as &$v) xmlWriteValue($x, $v); $x->endElement();}//根据类型向xml节点中写入值function xmlWriteValue(XMLWriter $x, &$v) { if (is_int($v) || is_long($v)) $x->writeElement('integer', $v); elseif (is_float($v) || is_real($v) || is_double($v)) $x->writeElement('real', $v); elseif (is_string($v)) $x->writeElement('string', $v); elseif (is_bool($v)) $x->writeElement($v?'true':'false'); elseif (isDict($v)) xmlWriteDict($x, $v); elseif (is_array($v)) xmlWriteArray($x, $v); else  { trigger_error("Unsupported data type in plist ($v)", E_USER_WARNING); $x->writeElement('string', $v); }}//创建plistfunction createplist(){ $ssl_server = 'https://www.lessney.com/'; $target_name = 'Sample'; $bundle_identifier = 'com.lessney.' . $target_name; $subtitle = 'Zero Status Inc.'; $title = '示例程序'; $versionname = $_GET['v']; if (!$versionname)  { $versionname = '1.0.0'; } $versioncode = str_replace('.', '', $versionname); $channelid = $_GET['cid']; if (!$channelid)  { $channelid = '0'; } header('Content-Type: application/xml'); $plist = new XmlWriter(); $plist->openMemory(); $plist->setIndent(TRUE); $plist->startDocument('1.0', 'UTF-8'); $plist->writeDTD('plist', '-//Apple//DTD PLIST 1.0//EN', 'http://www.apple.com/DTDs/PropertyList-1.0.dtd'); $plist->startElement('plist'); $plist->writeAttribute('version', '1.0'); $pkg = array(); $pkg['kind'] = 'software-package'; $pkg['url'] = $ssl_server . $target_name .'_v' . $versioncode . '_' .$channelid . '.ipa'; $displayimage = array(); $displayimage['kind'] = 'display-image'; $displayimage['needs-shine'] = TRUE; $displayimage['url'] = $ssl_server . 'Icon.png'; $fullsizeimage = array(); $fullsizeimage['kind'] = 'full-size-image'; $fullsizeimage['needs-shine'] = TRUE; $fullsizeimage['url'] = $ssl_server . 'iTunesArtwork.png'; $assets = array(); $assets[] = $pkg; $assets[] = $displayimage; $assets[] = $fullsizeimage; $metadata = array(); $metadata['bundle-identifier'] = $bundle_identifier; $metadata['bundle-version'] = $versionname; $metadata['kind'] = 'software'; $metadata['subtitle'] = $subtitle; $metadata['title'] = $title; $items0 = array(); $items0['assets'] = $assets; $items0['metadata'] = $metadata; $items = array(); $items[] = $items0; $root = array(); $root['items'] = $items; xmlWriteValue($plist, $root); $plist->endElement(); $plist->endDocument(); return $plist->outputMemory();}//输出plistecho createplist();?>
Nach dem Login kopieren


Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage