前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Thinkphp6实现APP手机应用信息采集

Thinkphp6实现APP手机应用信息采集

作者头像
程序猿的栖息地
发布2022-04-29 15:42:19
2490
发布2022-04-29 15:42:19
举报
文章被收录于专栏:程序猿的栖息地

手机应用信息采集数据源来自腾讯管家。

ps:链接有可能不能使用了

已经封装成一个类库,拿过去稍微改一下自己要采集的参数就能用

代码语言:javascript
复制
<?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;
        }
    }
}
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-09-04,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 程序猿的栖息地 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档