APP手机应用信息采集

php

浏览数:363

2019-1-7


手机应用信息采集数据源来自腾讯管家。ps:链接可能不能使用

<?php
/***
 * $demo = new Myapp;
 * 查询软件包名
 * $demo->search('看了吗');
 * 调取评论
 * $demo->comment('com.klm123.klmvideo','21');
 */
class Myapp{

    private function Curl($url,$data,$reffer){
        $curl  = curl_init();
        $headers=[];
        $headers[]='Accept:application/json, text/javascript, */*; q=0.01';
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($curl,CURLOPT_REFERER,$reffer);
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($curl, CURLOPT_HEADER, 0);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
        curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36');
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        $tmpInfo = curl_exec($curl);
        if (curl_errno($curl)) {
            return ['error'=>curl_error($curl),'status'=>0];
        }
        curl_close($curl);
        return ['status'=>1,'data'=>$tmpInfo];
    }

    private function bulidmsg($appDetail){
        return [
            'app'=>$appDetail['appName'],
            'description'=>$appDetail['description'],
            'category'=>$appDetail['categoryName'],
            'apk_url'=>$appDetail['apkUrl'],
            'app_down_count'=>$appDetail['appDownCount'],
            'author'=>$appDetail['authorName'],
            'new_feature'=>$appDetail['newFeature'],
            'pkg'=>$appDetail['pkgName'],
            'version_code'=>$appDetail['versionCode'],
            'version'=>$appDetail['versionName'],
            'rating'=>$appDetail['averageRating'],
            'images'=>$appDetail['images'],
            'icon'=>$appDetail['iconUrl'],
            'apk_publish_time'=>$appDetail['apkPublishTime'],
            'detail_url'=>('http://android.myapp.com/myapp/detail.htm?apkName='.$appDetail['pkgName']),
            'rating_count'=>$appDetail['appRatingInfo']['ratingCount']
        ];
    } 

    /**
     * 应用宝搜索
     */
    public function search($keyword,$islist = false,$pns='',$sid='')
    {
        $url = 'http://sj.qq.com/myapp/searchAjax.htm?kw='.$keyword.'&pns='.$pns.'&sid='.$sid;
        $reffer = 'http://sj.qq.com/myapp/search.htm?kw='.$keyword;
        $data = self::Curl($url,'',$reffer);
        if($data['status']==1){
            $objdata = json_decode($data['data'],true);
            if($islist){
                $return =[];
                foreach ($objdata['obj']['appDetails'] as $value) {
                    $return[]=self::bulidmsg($value);
                }
                return $return;
            }else{
        foreach ($objdata['obj']['appDetails'] as $value){
            if(strpos($value['appName'],$keyword)!==false){
                return self::bulidmsg($value);
            }
        }
                $appDetail = $objdata['obj']['appDetails'][0];
                return self::bulidmsg($appDetail);
            }
        }else{
            return false;
        }
    }

    /**
     * 获取评论
     */
    public function comment($apk,$version_code,$page=1,$contextData='')
    {
        $url = 'http://android.myapp.com/myapp/app/comment.htm?apkName='.$apk.'&apkCode='.$version_code.'&p='.$page.'&fresh=0.'.(microtime(true)*1000).'&contextData='.$contextData;
        $reffer = 'http://android.myapp.com/myapp/detail.htm?apkName='.$apk;
        $data = self::Curl($url,'',$reffer);
        if($data['status']==1){
            $objdata = json_decode($data['data'],true);
            $objdata=$objdata['obj'];
            $objdata['commentDetails'] = empty($objdata['commentDetails'])?[]:$objdata['commentDetails'];
            foreach($objdata['commentDetails'] as $k=>$value){
                unset($value['pkgName'],$value['uin'],$value['phoneMode'],$value['phoneBrand']);
                $objdata['commentDetails'][$k]=$value;
            }
            return $objdata;
        }else{
            return false;
        }
    }
}