Linux上PHP下载apk文件-appt解析

 $url)
{
    $url = trim($url);
    $tmpfname = tempnam("/data/logs/20190417", "APK_");
    chmod($tmpfname, 0755);
    exec("wget -c -t 10 -T 120 -O {$tmpfname}   $url 2>&1", $output, $return_val);
    $apkinfo =array();
    exec("sudo /usr/local/apk_tools/aapt d badging $tmpfname 2>&1", $apkinfo, $ret);
    @unlink($tmpfname);
    $data= array();
    if ( 0 === $ret )
    {
        $need_apkinfo = array(
            'apk_name'         => array('keyword' => 'package: name=\'', 'value' => ''),
            'targetSdkVersion' => array('keyword' => 'targetSdkVersion:\'', 'value' => ''),
            'minSdkVersion'    => array('keyword' => 'sdkVersion:\'', 'value' => ''),
        );
        $flag = 0;
        foreach ( $apkinfo as $info )
        {
            foreach ( $need_apkinfo as $tag => $needinfo )
            {
                if ( empty($needinfo['value']) )
                {
                    $pos_start = strpos($info, $needinfo['keyword']);
                    if ( false !== $pos_start )
                    {
                        $pos_end                     = strpos($info, '\'', $pos_start + strlen($needinfo['keyword']));
                        $need_apkinfo[$tag]['value'] = substr($info, $pos_start + strlen($needinfo['keyword']), $pos_end - $pos_start - strlen($needinfo['keyword']));
                    }
                    if ( !empty($need_apkinfo[$tag]['value']) )
                    {
                        $data[$tag] = $need_apkinfo[$tag]['value'];
                        $flag++;
                    }
                }

                if ( $flag == count($need_apkinfo) )
                {
                    break;
                }
            }
        }
    }
    file_put_contents('/data/logs/20190417/dev_msg.log',"{$data['apk_name']} \t {$data['minSdkVersion']}\t {$data['targetSdkVersion']}"."\n",FILE_APPEND);
}

 

你可能感兴趣的:(PHP)