Inhaltsverzeichnis
php获取apk包信息的方法,php获取apk包
php怎获取一个http包
php页面可以否指定向访问它的某个android的apk程序发送消息?
Heim php教程 php手册 php获取apk包信息的方法,php获取apk包

php获取apk包信息的方法,php获取apk包

Jun 13, 2016 am 09:27 AM
android apk php 信息 获取

php获取apk包信息的方法,php获取apk包

有时候在使用php上传安卓apk包的时候,我们需要获取安卓apk包内的信息,本文以实例形式讲述了php获取apk包信息的方法。具体实现方法如下:

<&#63;php
/*解析安卓apk包中的压缩XML文件,还原和读取XML内容
依赖功能:需要PHP的ZIP包函数支持。*/
include('./Apkparser.php');
$appObj  = new Apkparser(); 
$targetFile = a.apk;//apk所在的路径地址
$res   = $appObj->open($targetFile);
$appObj->getAppName();     // 应用名称
$appObj->getPackage();    // 应用包名
$appObj->getVersionName();  // 版本名称
$appObj->getVersionCode();  // 版本代码
&#63;>

Nach dem Login kopieren

以下是Apkparser类包,把以下代码复制出来保存为Apkparser.php就可以执行以上代码

<&#63;php
//-------------------------------
//Apkparser类包开始
//-------------------------------
class ApkParser{
//----------------------
// 公共函数,供外部调用
//----------------------
  public function open($apk_file, $xml_file='AndroidManifest.xml'){
    $zip = new \ZipArchive;
    if ($zip->open($apk_file) === TRUE) {
      $xml = $zip->getFromName($xml_file);
      $zip->close();
      if ($xml){
        try {
          return $this->parseString($xml);
        }catch (Exception $e){
        }
      }
    }
    return false;
  }
  public function parseString($xml){
    $this->xml = $xml;
    $this->length = strlen($xml);
    $this->root = $this->parseBlock(self::AXML_FILE);
    return true;
  }
  public function getXML($node=NULL, $lv=-1){
    if ($lv == -1) $node = $this->root;
    if (!$node) return '';
    if ($node['type'] == self::END_TAG) $lv--;
    $xml = @($node['line'] == 0 || $node['line'] == $this->line) &#63; '' : "\n".str_repeat(' ', $lv);
    $xml .= $node['tag'];
    $this->line = @$node['line'];
    foreach ($node['child'] as $c){
      $xml .= $this->getXML($c, $lv+1);
    }
    return $xml;
  }
  public function getPackage(){
    return $this->getAttribute('manifest', 'package');
  }
  public function getVersionName(){
    return $this->getAttribute('manifest', 'android:versionName');
  }
  public function getVersionCode(){
    return $this->getAttribute('manifest', 'android:versionCode');
  }
  public function getAppName(){
    return $this->getAttribute('manifest/application', 'android:name');
  }
  public function getMainActivity(){
    for ($id=0; true; $id++){
      $act = $this->getAttribute("manifest/application/activity[{$id}]/intent-filter/action", 'android:name');
      if (!$act) break;
      if ($act == 'android.intent.action.MAIN') return $this->getActivity($id);
    }
    return NULL;
  }
  public function getActivity($idx=0){
    $idx = intval($idx);
    return $this->getAttribute("manifest/application/activity[{$idx}]", 'android:name');
  }
  public function getAttribute($path, $name){
    $r = $this->getElement($path);
    if (is_null($r)) return NULL;
    if (isset($r['attrs'])){
      foreach ($r['attrs'] as $a){
        if ($a['ns_name'] == $name) return $this->getAttributeValue($a);
      }
    }
    return NULL;
  }
//----------------------
// 类型常量定义
//----------------------
  const AXML_FILE       = 0x00080003;
  const STRING_BLOCK     = 0x001C0001;
  const RESOURCEIDS      = 0x00080180;
  const START_NAMESPACE    = 0x00100100;
  const END_NAMESPACE     = 0x00100101;
  const START_TAG       = 0x00100102;
  const END_TAG        = 0x00100103;
  const TEXT         = 0x00100104;
  const TYPE_NULL       =0;
  const TYPE_REFERENCE    =1;
  const TYPE_ATTRIBUTE    =2;
  const TYPE_STRING      =3;
  const TYPE_FLOAT      =4;
  const TYPE_DIMENSION    =5;
  const TYPE_FRACTION     =6;
  const TYPE_INT_DEC     =16;
  const TYPE_INT_HEX     =17;
  const TYPE_INT_BOOLEAN   =18;
  const TYPE_INT_COLOR_ARGB8 =28;
  const TYPE_INT_COLOR_RGB8  =29;
  const TYPE_INT_COLOR_ARGB4 =30;
  const TYPE_INT_COLOR_RGB4  =31;
  const UNIT_MASK       = 15;
  private static $RADIX_MULTS = array(0.00390625, 3.051758E-005, 1.192093E-007, 4.656613E-010);
  private static $DIMENSION_UNITS = array("px","dip","sp","pt","in","mm","","");
  private static $FRACTION_UNITS = array("%","%p","","","","","","");
  private $xml='';
  private $length = 0;
  private $stringCount = 0;
  private $styleCount = 0;
  private $stringTab = array();
  private $styleTab = array();
  private $resourceIDs = array();
  private $ns = array();
  private $cur_ns = NULL;
  private $root = NULL;
  private $line = 0;
//----------------------
// 内部私有函数
//----------------------
  private function getElement($path){
    if (!$this->root) return NULL;
    $ps = explode('/', $path);
    $r = $this->root;
    foreach ($ps as $v){
      if (preg_match('/([^\[]+)\[([0-9]+)\]$/', $v, $ms)){
        $v = $ms[1];
        $off = $ms[2];
      }else {
        $off = 0;
      }
      foreach ($r['child'] as $c){
        if ($c['type'] == self::START_TAG && $c['ns_name'] == $v){
          if ($off == 0){
            $r = $c; continue 2;
          }else {
            $off--;
          }
        }
      }
      // 没有找到节点
      return NULL;
    }
    return $r;
  }
  private function parseBlock($need = 0){
    $o = 0;
    $type = $this->get32($o);
    if ($need && $type != $need) throw new Exception('Block Type Error', 1);
    $size = $this->get32($o);
    if ($size < 8 || $size > $this->length) throw new Exception('Block Size Error', 2);
    $left = $this->length - $size;
    $props = false;
    switch ($type){
      case self::AXML_FILE:
        $props = array(
          'line' => 0,
          'tag' => '<&#63;xml version="1.0" encoding="utf-8"&#63;>'
        );
      break;
      case self::STRING_BLOCK:
        $this->stringCount = $this->get32($o);
        $this->styleCount = $this->get32($o);
        $o += 4;
        $strOffset = $this->get32($o);
        $styOffset = $this->get32($o);
        $strListOffset = $this->get32array($o, $this->stringCount);
        $styListOffset = $this->get32array($o, $this->styleCount);
        $this->stringTab = $this->stringCount > 0 &#63; $this->getStringTab($strOffset, $strListOffset) : array();
        $this->styleTab = $this->styleCount > 0 &#63; $this->getStringTab($styOffset, $styListOffset) : array();
        $o = $size;
      break;
      case self::RESOURCEIDS:
        $count = $size / 4 - 2;
        $this->resourceIDs = $this->get32array($o, $count);
      break;
      case self::START_NAMESPACE:
        $o += 8;
        $prefix = $this->get32($o);
        $uri = $this->get32($o);
        if (empty($this->cur_ns)){
          $this->cur_ns = array();
          $this->ns[] = &$this->cur_ns;
        }
        $this->cur_ns[$uri] = $prefix;
      break;
      case self::END_NAMESPACE:
        $o += 8;
        $prefix = $this->get32($o);
        $uri = $this->get32($o);
        if (empty($this->cur_ns)) break;
        unset($this->cur_ns[$uri]);
      break;
      case self::START_TAG:
        $line = $this->get32($o);
        $o += 4;
        $attrs = array();
        $props = array(
          'line' => $line,
          'ns' => $this->getNameSpace($this->get32($o)),
          'name' => $this->getString($this->get32($o)),
          'flag' => $this->get32($o),
          'count' => $this->get16($o),
          'id' => $this->get16($o)-1,
          'class' => $this->get16($o)-1,
          'style' => $this->get16($o)-1,
          'attrs' => &$attrs
        );
        $props['ns_name'] = $props['ns'].$props['name'];
        for ($i=0; $i < $props['count']; $i++){
          $a = array(
            'ns' => $this->getNameSpace($this->get32($o)),
            'name' => $this->getString($this->get32($o)),
            'val_str' => $this->get32($o),
            'val_type' => $this->get32($o),
            'val_data' => $this->get32($o)
          );
          $a['ns_name'] = $a['ns'].$a['name'];
          $a['val_type'] >>= 24;
          $attrs[] = $a;
        }
        // 处理TAG字符串
        $tag = "<{$props['ns_name']}";
        foreach ($this->cur_ns as $uri => $prefix){
          $uri = $this->getString($uri);
          $prefix = $this->getString($prefix);
          $tag .= " xmlns:{$prefix}=\"{$uri}\"";
        }
        foreach ($props['attrs'] as $a){
          $tag .= " {$a['ns_name']}=\"".
              $this->getAttributeValue($a).
              '"';
        }
        $tag .= '>';
        $props['tag'] = $tag;
        unset($this->cur_ns);
        $this->cur_ns = array();
        $this->ns[] = &$this->cur_ns;
        $left = -1;
      break;
      case self::END_TAG:
        $line = $this->get32($o);
        $o += 4;
        $props = array(
          'line' => $line,
          'ns' => $this->getNameSpace($this->get32($o)),
          'name' => $this->getString($this->get32($o))
        );
        $props['ns_name'] = $props['ns'].$props['name'];
        $props['tag'] = "</{$props['ns_name']}>";
        if (count($this->ns) > 1){
          array_pop($this->ns);
          unset($this->cur_ns);
          $this->cur_ns = array_pop($this->ns);
          $this->ns[] = &$this->cur_ns;
        }
      break;
      case self::TEXT:
        $o += 8;
        $props = array(
          'tag' => $this->getString($this->get32($o))
        );
        $o += 8;
      break;
      default:
        throw new Exception('Block Type Error', 3);
      break;
    }
    $this->skip($o);
    $child = array();
    while ($this->length > $left){
      $c = $this->parseBlock();
      if ($props && $c) $child[] = $c;
      if ($left == -1 && $c['type'] == self::END_TAG){
        $left = $this->length;
        break;
      }
    }
    if ($this->length != $left) throw new Exception('Block Overflow Error', 4);
    if ($props){
      $props['type'] = $type;
      $props['size'] = $size;
      $props['child'] = $child;
      return $props;
    }else {
      return false;
    }
  }
  private function getAttributeValue($a){
    $type = &$a['val_type'];
    $data = &$a['val_data'];
    switch ($type){
      case self::TYPE_STRING:
        return $this->getString($a['val_str']);
      case self::TYPE_ATTRIBUTE:
        return sprintf('&#63;%s%08X', self::_getPackage($data), $data);
      case self::TYPE_REFERENCE:
        return sprintf('@%s%08X', self::_getPackage($data), $data);
      case self::TYPE_INT_HEX:
        return sprintf('0x%08X', $data);
      case self::TYPE_INT_BOOLEAN:
        return ($data != 0 &#63; 'true' : 'false');
      case self::TYPE_INT_COLOR_ARGB8:
      case self::TYPE_INT_COLOR_RGB8:
      case self::TYPE_INT_COLOR_ARGB4:
      case self::TYPE_INT_COLOR_RGB4:
        return sprintf('#%08X', $data);
      case self::TYPE_DIMENSION:
        return $this->_complexToFloat($data).self::$DIMENSION_UNITS[$data & self::UNIT_MASK];
      case self::TYPE_FRACTION:
        return $this->_complexToFloat($data).self::$FRACTION_UNITS[$data & self::UNIT_MASK];
      case self::TYPE_FLOAT:
        return $this->_int2float($data);
    }
    if ($type >=self::TYPE_INT_DEC && $type < self::TYPE_INT_COLOR_ARGB8){
      return (string)$data;
    }
    return sprintf('<0x%X, type 0x%02X>', $data, $type);
  }
  private function _complexToFloat($data){
    return (float)($data & 0xFFFFFF00) * self::$RADIX_MULTS[($data>>4) & 3];
  }
  private function _int2float($v) {
    $x = ($v & ((1 << 23) - 1)) + (1 << 23) * ($v >> 31 | 1);
    $exp = ($v >> 23 & 0xFF) - 127;
    return $x * pow(2, $exp - 23);
  }
  private static function _getPackage($data){
    return ($data >> 24 == 1) &#63; 'android:' : '';
  }
  private function getStringTab($base, $list){
    $tab = array();
    foreach ($list as $off){
      $off += $base;
      $len = $this->get16($off);
      $mask = ($len >> 0x8) & 0xFF;
      $len = $len & 0xFF;
      if ($len == $mask){
        if ($off + $len > $this->length) throw new Exception('String Table Overflow', 11);
        $tab[] = substr($this->xml, $off, $len);
      }else {
        if ($off + $len * 2 > $this->length) throw new Exception('String Table Overflow', 11);
        $str = substr($this->xml, $off, $len * 2);
        $tab[] = mb_convert_encoding($str, 'UTF-8', 'UCS-2LE');
      }
    }
    return $tab;
  }
  private function getString($id){
    if ($id > -1 && $id < $this->stringCount){
      return $this->stringTab[$id];
    }else {
      return '';
    }
  }
  private function getNameSpace($uri){
    for ($i=count($this->ns); $i > 0; ){
      $ns = $this->ns[--$i];
      if (isset($ns[$uri])){
        $ns = $this->getString($ns[$uri]);
        if (!empty($ns)) $ns .= ':';
        return $ns;
      }
    }
    return '';
  }
  private function get32(&$off){
    $int = unpack('V', substr($this->xml, $off, 4));
    $off += 4;
    return array_shift($int);
  }
  private function get32array(&$off, $size){
    if ($size <= 0) return NULL;
    $arr = unpack('V*', substr($this->xml, $off, 4 * $size));
    if (count($arr) != $size) throw new Exception('Array Size Error', 10);
    $off += 4 * $size;
    return $arr;
  }
  private function get16(&$off){
    $int = unpack('v', substr($this->xml, $off, 2));
    $off += 2;
    return array_shift($int);
  }
  private function skip($size){
    $this->xml = substr($this->xml, $size);
    $this->length -= $size;
  }
}
//---------------------
//Apkparser类包结束 
//---------------------
&#63;>

Nach dem Login kopieren

感兴趣的朋友可以调试运行一下本文实例,相信会对大家的php程序开发带来一定的启发。

php怎获取一个http包

$_POST是一个数组,echo $_POST当然是Array.你可以var_dump($_POST)看一下数组里的参数和值。如果你传过去的参数是a,值是hello,你可以用 $_POST['a']来获取,仿GET方式welcome.php?a=hello
echo $_GET['a'];
 

php页面可以否指定向访问它的某个android的apk程序发送消息?

你现在的做法是唯一可行的做法了,只能让APK定时刷新,除非APK和服务器保持连接不断开,否则服务器的PHP是服务去找到APK的,因为你的APK不是服务器,不能反过来执行。

如果要减轻服务器压力,那就必须把你的APK做成一个服务器,侦听一个网络端口,允许网络上的其它设备来连接。不过这个工程会很大,APK和PHP的逻辑都会变得非常复杂,因为PHP要在需要的时候来找APK,如果手机关机还得延时再来,而APK为了随时等待PHP来连接,要以服务方式工作,随时待命。
 

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

Heiße KI -Werkzeuge

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Clothoff.io

Clothoff.io

KI-Kleiderentferner

AI Hentai Generator

AI Hentai Generator

Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

R.E.P.O. Energiekristalle erklärten und was sie tun (gelber Kristall)
2 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
Repo: Wie man Teamkollegen wiederbelebt
4 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Abenteuer: Wie man riesige Samen bekommt
4 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌

Heiße Werkzeuge

Notepad++7.3.1

Notepad++7.3.1

Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version

SublimeText3 chinesische Version

Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1

Senden Sie Studio 13.0.1

Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6

Dreamweaver CS6

Visuelle Webentwicklungstools

SublimeText3 Mac-Version

SublimeText3 Mac-Version

Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

PHP 8.4 Installations- und Upgrade-Anleitung für Ubuntu und Debian PHP 8.4 Installations- und Upgrade-Anleitung für Ubuntu und Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 bringt mehrere neue Funktionen, Sicherheitsverbesserungen und Leistungsverbesserungen mit einer beträchtlichen Menge an veralteten und entfernten Funktionen. In dieser Anleitung wird erklärt, wie Sie PHP 8.4 installieren oder auf PHP 8.4 auf Ubuntu, Debian oder deren Derivaten aktualisieren. Obwohl es möglich ist, PHP aus dem Quellcode zu kompilieren, ist die Installation aus einem APT-Repository wie unten erläutert oft schneller und sicherer, da diese Repositorys in Zukunft die neuesten Fehlerbehebungen und Sicherheitsupdates bereitstellen.

So richten Sie Visual Studio-Code (VS-Code) für die PHP-Entwicklung ein So richten Sie Visual Studio-Code (VS-Code) für die PHP-Entwicklung ein Dec 20, 2024 am 11:31 AM

Visual Studio Code, auch bekannt als VS Code, ist ein kostenloser Quellcode-Editor – oder eine integrierte Entwicklungsumgebung (IDE) –, die für alle gängigen Betriebssysteme verfügbar ist. Mit einer großen Sammlung von Erweiterungen für viele Programmiersprachen kann VS Code c

Xiaomi Redmi Note 14 Pro Plus erscheint als erstes Qualcomm Snapdragon 7s Gen 3 Smartphone mit Light Hunter 800 Kamera Xiaomi Redmi Note 14 Pro Plus erscheint als erstes Qualcomm Snapdragon 7s Gen 3 Smartphone mit Light Hunter 800 Kamera Sep 27, 2024 am 06:23 AM

Das Redmi Note 14 Pro Plus ist nun offiziell als direkter Nachfolger des letztjährigen Redmi Note 13 Pro Plus (aktuell 375 $ bei Amazon) erhältlich. Wie erwartet steht das Redmi Note 14 Pro Plus neben dem Redmi Note 14 und dem Redmi Note 14 Pro an der Spitze der Redmi Note 14-Serie. Li

Wie analysiert und verarbeitet man HTML/XML in PHP? Wie analysiert und verarbeitet man HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

Dieses Tutorial zeigt, wie XML -Dokumente mit PHP effizient verarbeitet werden. XML (Extensible Markup-Sprache) ist eine vielseitige textbasierte Markup-Sprache, die sowohl für die Lesbarkeit des Menschen als auch für die Analyse von Maschinen entwickelt wurde. Es wird üblicherweise für die Datenspeicherung ein verwendet und wird häufig verwendet

Das Design des Oppo Find X8 sieht auf ersten Bildern wie eine Kreuzung zwischen Apple iPhone 16 Pro und OnePlus Open aus Das Design des Oppo Find X8 sieht auf ersten Bildern wie eine Kreuzung zwischen Apple iPhone 16 Pro und OnePlus Open aus Sep 28, 2024 am 06:04 AM

In der Vergangenheit hat Oppo seine Flaggschiff-Serie „Find X“ im späten Winter oder frühen Frühling aktualisiert, mit Ausnahme des ursprünglichen Find an dieser Stelle. H

PHP -Programm zum Zählen von Vokalen in einer Zeichenfolge PHP -Programm zum Zählen von Vokalen in einer Zeichenfolge Feb 07, 2025 pm 12:12 PM

Eine Zeichenfolge ist eine Folge von Zeichen, einschließlich Buchstaben, Zahlen und Symbolen. In diesem Tutorial wird lernen, wie Sie die Anzahl der Vokale in einer bestimmten Zeichenfolge in PHP unter Verwendung verschiedener Methoden berechnen. Die Vokale auf Englisch sind a, e, i, o, u und sie können Großbuchstaben oder Kleinbuchstaben sein. Was ist ein Vokal? Vokale sind alphabetische Zeichen, die eine spezifische Aussprache darstellen. Es gibt fünf Vokale in Englisch, einschließlich Großbuchstaben und Kleinbuchstaben: a, e, ich, o, u Beispiel 1 Eingabe: String = "TutorialPoint" Ausgabe: 6 erklären Die Vokale in der String "TutorialPoint" sind u, o, i, a, o, ich. Insgesamt gibt es 6 Yuan

Die Samsung Galaxy Z Fold Special Edition soll Ende Oktober erscheinen, da ein widersprüchlicher Name auftaucht Die Samsung Galaxy Z Fold Special Edition soll Ende Oktober erscheinen, da ein widersprüchlicher Name auftaucht Oct 01, 2024 am 06:21 AM

Die Einführung des lang erwarteten faltbaren „Special Edition“-Modells von Samsung hat eine weitere Wendung genommen. In den letzten Wochen verliefen die Gerüchte um die sogenannte Galaxy Z Fold Special Edition eher ruhig. Stattdessen hat sich der Fokus auf die Galaxy S25-Serie verlagert, darunter

iQOO Z9 Turbo+ debütiert als Dimensity 9300+-Smartphone mit „außergewöhnlicher' Akkulaufzeit iQOO Z9 Turbo+ debütiert als Dimensity 9300+-Smartphone mit „außergewöhnlicher' Akkulaufzeit Sep 26, 2024 am 06:20 AM

Das Z9 Turbo+ ist jetzt im chinesischen Online-Shop von Vivo für 2.199 Yuan (~313 US-Dollar) für ein Basismodell mit 12 GB RAM/256 GB internem Speicher erhältlich, während das RedmiK70 Extreme Edition mit der gleichen Konfiguration bei 2.599 Yuan (~370 US-Dollar) startete: Tatsächlich ist es so newiQ

See all articles