安卓和蘋(píng)果多渠道分包PHP版本

IOS分包,適用企業(yè)簽

<?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; // 拒絕訪(fǎng)問(wèn)

return $return;

}

if(empty($p) || empty($a)){

$return = -3;? //請(qǐng)求數(shù)據(jù)為空

return $return;

}

$opt = md5(md5($p.$a).'resub');

if($o != $opt){

? ? $return = -4;? //驗(yàn)證錯(cuò)誤

? ? 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;//無(wú)法創(chuàng)建文件,打包失敗

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(); // 應(yīng)用名稱(chēng)

? ? $data['pakagename'] = $appObj->getPackage(); // 應(yīng)用包名

? ? $data['vername'] = $appObj->getVersionName(); // 版本名稱(chēng)

? ? $data['verid'] = $appObj->getVersionCode(); // 版本代碼

? ? $data['size'] = $fz->getFileSize($file,false);

? ? return $data;

}

function del_file($files)

{

? ? //如果是文件,判斷是2分鐘以前的文件進(jìn)行刪除

? ? $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; // 拒絕訪(fǎng)問(wèn)

// return $return;

}

if(empty($p) || empty($a)){

$return = -3;? //請(qǐng)求數(shù)據(jù)為空

return $return;

}

$opt = md5(md5($p.$a).'resub');

if($o != $opt){

? ? $return = -4;? //驗(yàn)證錯(cuò)誤

? ? 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;//無(wú)法創(chuàng)建文件,打包失敗

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(); // 應(yīng)用名稱(chēng)

? ? $data['pakagename'] = $appObj->getPackage(); // 應(yīng)用包名

? ? $data['vername'] = $appObj->getVersionName(); // 版本名稱(chēng)

? ? $data['verid'] = $appObj->getVersionCode(); // 版本代碼

? ? $data['size'] = $fz->getFileSize($file,false);

? ? return $data;

}

function del_file($files)

{

? ? //如果是文件,? 判斷是2分鐘以前的文件進(jìn)行刪除

$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);

? ? ? ? }

? ? // }

}

?>



分包函數(shù)調(diào)用

<?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);

?>

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容