IOS分包,适用企业签
<?php
define('IPOne', "127.0.0.1");
function postReturn($return){
$return = base64_encode($return);
exit();
}
function GetIP($type=0){
if(!empty($_SERVER["HTTP_CLIENT_IP"])) {
$cip = $_SERVER["HTTP_CLIENT_IP"];
} else if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])) {
$cip = $_SERVER["HTTP_X_FORWARDED_FOR"];
} else if(!empty($_SERVER["REMOTE_ADDR"])) {
$cip = $_SERVER["REMOTE_ADDR"];
} else {
$cip = "";
}
preg_match("/[\d\.]{7,15}/", $cip, $cips);
$cip = $cips[0] ? $cips[0] : 'unknown';
unset($cips);
if ($type == 1)
$cip = myip2long($cip);
return $cip;
}
function subpackage($urldata){
$p = base64_decode($urldata['p']);
$a = base64_decode($urldata['a']);
$o = base64_decode($urldata['o']);
if(isset($urldata['c'])){
$c = base64_decode($urldata['c']);
}else{
$c='';
}
// $mch=base64_decode($urldata['mch']);
$ip = GetIP();
if ($ip != IPOne && $ip != IPTwo && $ip != IPThree){
$return = -6; // 拒绝访问
return $return;
}
if(empty($p) || empty($a)){
$return = -3; //请求数据为空
return $return;
}
$opt = md5(md5($p.$a).'resub');
if($o != $opt){
$return = -4; //验证错误
return $return;
}
$pinyin = isset($p) ? $p :'';
$agentgame = isset($a) ? $a :'';
// $mch = isset($mch)? $mch :'';
$url = dirname(__FILE__);
$url = $url.DIRECTORY_SEPARATOR."iosgame".DIRECTORY_SEPARATOR;
$pinyinarr = explode('/', $pinyin);
$sourfile = $url . $pinyin . "/" . $pinyinarr[0] . ".ipa";
if(!file_exists($sourfile)){
if (!file_exists($url . $pinyin)) {
mkdir($url . $pinyin, 0777, true);
}
if ($pinyinarr[0] == $agentgame) {
return 111;
}
$return = -5; //游戏原包不存在
return $return;
}
// chmod($url, 0777);
// chmod($sourfile, 0777);
$filename= $agentgame.".ipa";
$newfile = $url.$pinyin."/".$filename;
if(file_exists($newfile)){
if ($pinyinarr[0] == $agentgame) {
$data = getApkinfo($sourfile);
return json_encode($data);
}
if($c){
$return = 2; //已分包
return $return;
}
del_file($newfile);
subpackage($urldata);
}
$return = 0;
if (!copy($sourfile, $newfile)) {
$return = -1;//无法创建文件,打包失败
return $return;
}
$var = explode("_", $agentgame);
$huomark = "p91" . "g" . $var['1'] . "a" . $var['2'];
//fopen($channelfile, "w");
$zip = zip_open($newfile);
$i=1;
if ($zip) {
while ($zip_entry = zip_read($zip)) {
$channelname=zip_entry_name($zip_entry);
if (zip_entry_open($zip, $zip_entry, "r")) {
$i++;
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
zip_entry_close($zip_entry);
}
if($i==3){
break;
}
}
zip_close($zip);
}
$channelname = $channelname."_CodeSignature/gameChannel";
$zip = new ZipArchive();
if ($zip->open($newfile) === TRUE) {
$zip->addFromString($channelname, $agentgame);
$zip->close();
$return = 111;
} else {
$return = -2;
}
return $return;
}
function getApkinfo($file) {
include dirname(__FILE__).'/apkParser.php';
include ('./FilesizeHelper.php');
$data = array();
$appObj = new \ApkParser();
$fz = new FilesizeHelper();
$res = $appObj->open($file);
$data['appname'] = $appObj->getAppName(); // 应用名称
$data['pakagename'] = $appObj->getPackage(); // 应用包名
$data['vername'] = $appObj->getVersionName(); // 版本名称
$data['verid'] = $appObj->getVersionCode(); // 版本代码
$data['size'] = $fz->getFileSize($file,false);
return $data;
}
function del_file($files)
{
//如果是文件,判断是2分钟以前的文件进行删除
$file=$files;
$files = fopen($files, "r");
$f = fstat($files);
fclose($files);
// if ($f['mtime'] < (time() - 60 * 2)) {
if (@unlink($file)) {
@unlink($file);
} else {
@unlink($file);
}
// }
}
?>
安卓分包
<?php
define('IPOne', "127.0.0.1");
function postReturn($return){
$return = base64_encode($return);
exit();
}
function GetIP($type=0){
if(!empty($_SERVER["HTTP_CLIENT_IP"])) {
$cip = $_SERVER["HTTP_CLIENT_IP"];
} else if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])) {
$cip = $_SERVER["HTTP_X_FORWARDED_FOR"];
} else if(!empty($_SERVER["REMOTE_ADDR"])) {
$cip = $_SERVER["REMOTE_ADDR"];
} else {
$cip = "";
}
preg_match("/[\d\.]{7,15}/", $cip, $cips);
$cip = $cips[0] ? $cips[0] : 'unknown';
unset($cips);
if ($type == 1)
$cip = myip2long($cip);
return $cip;
}
function subpackage($urldata){
$p = base64_decode($urldata['p']);
$a = base64_decode($urldata['a']);
$o = base64_decode($urldata['o']);
if(isset($urldata['c'])){
$c = base64_decode($urldata['c']);
}else{
$c='';
}
$ip = GetIP();
if ($ip != IPOne && $ip != IPTwo && $ip != IPThree){
$return = -6; // 拒绝访问
// return $return;
}
if(empty($p) || empty($a)){
$return = -3; //请求数据为空
return $return;
}
$opt = md5(md5($p.$a).'resub');
if($o != $opt){
$return = -4; //验证错误
return $return;
}
$pinyin = isset($p) ? $p :'';
$agentgame = isset($a) ? $a :'';
$url = dirname(__FILE__);
$url = $url.DIRECTORY_SEPARATOR."sdkgame".DIRECTORY_SEPARATOR;
$pinyinarr = explode('/', $pinyin);
$sourfile = $url . $pinyin . "/" . $pinyinarr[0] . ".apk";
if(!file_exists($sourfile)){
if (!file_exists($url . $pinyin)) {
mkdir($url . $pinyin, 0777, true);
}
if ($pinyinarr[0] == $agentgame) {
return 1;
}
$return = -5; //游戏原包不存在
return $return;
}
//chmod($url, 0777);
//chmod($sourfile, 0777);
$filename= $agentgame.".apk";
$newfile = $url.$pinyin."/".$filename;
if(file_exists($newfile)){
if ($pinyinarr[0] == $agentgame) {
$data = getApkinfo($sourfile);
return json_encode($data);
}
if($c){
$return = 2; //已分包
return $return;
}
del_file($newfile);
subpackage($urldata);
}
$return = 0;
if (!copy($sourfile, $newfile)) {
$return = -1;//无法创建文件,打包失败
return $return;
}
$var = explode("_", $agentgame);
$huomark = "p99" . "g" . $var['1'] . "a" . $var['2'];
// fopen($channelfile, "w");
$channelname = "META-INF/gamechannel";
$huosdk = "META-INF/huosdk_" . $huomark;
$zip = new ZipArchive();
if ($zip->open($newfile) === TRUE) {
$zip->addFromString($channelname, json_encode(array(
'agentgame' => $agentgame
)));
$zip->addFromString($huosdk, json_encode(array(
'agentgame' => $huomark
)));
$zip->close();
$return = 1;
} else {
$return = -2;
}
return $return;
}
function getApkinfo($file) {
include dirname(__FILE__).'/apkParser.php';
include ('./FilesizeHelper.php');
$data = array();
$appObj = new \ApkParser();
$fz = new FilesizeHelper();
$res = $appObj->open($file);
$data['appname'] = $appObj->getAppName(); // 应用名称
$data['pakagename'] = $appObj->getPackage(); // 应用包名
$data['vername'] = $appObj->getVersionName(); // 版本名称
$data['verid'] = $appObj->getVersionCode(); // 版本代码
$data['size'] = $fz->getFileSize($file,false);
return $data;
}
function del_file($files)
{
//如果是文件, 判断是2分钟以前的文件进行删除
$file=$files;
$files = fopen($files, "r");
$f = fstat($files);
fclose($files);
// if ($f['mtime'] < (time() - 60 * 2)) {
if (@unlink($file)) {
@unlink($file);
} else {
@unlink($file);
}
// }
}
?>
分包函数调用
<?php
include "downFunc.php";
// $urldata = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : '';
$urldata = file_get_contents("php://input");
//$urldata = '{"p":"bGN6el82MDAyNA==","a":"bGN6el82MDAyNF8xMzY=","o":"ZjI4N2MwMzJmMTJlZWU0NjM2YWZjODAyYWEzMTkwZGI="}';
$urldata = get_object_vars(json_decode($urldata));
$cnt = 0;
while (1) {
$return = subpackage($urldata);
if (-2 != $return || 3 == $cnt || strlen($return)>10 ) {
break;
}
$cnt++;
}
echo base64_encode($return);
?>
网友评论