123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797 |
- <?php
- /**
- * Created by PhpStorm.
- * User: hy
- * Date: 2019-05-16
- * Time: 14:59
- */
- include 'IpAgencyService.php';
- function str_random($i=1){
- $a = rand(1,4);
- if($a==1) return 'w0r0ewr';
- if($a==2) return 'sojwe';
- if($a==3) return 'ofwjfslds';
- if($a==4) return 'asdww';
- }
- class KuaishouScrapyIpProxyService {
- protected static $url;
- protected static $queryString;
- protected static $data;
- protected static $dataStr;
- protected static $didkey = 'kwaiIpDids:';
- protected static $ipArray = [];
- public static $currentIp = null;
- /**
- * 根据快手id或者用户名查找用户
- * @param $uname
- */
- public static function searchUser($uname) {
- $url = 'http://123.59.169.36/rest/n/search?';
- $parms = [
- 'keyword' => $uname,
- 'os' => 'android',
- 'client_key' => '3c2cd3f3',
- 'fromPage' => '1'
- ];
- $randomDid = self::getRandomDid();
- self::$queryString = 'app=0&kpf=ANDROID_PHONE&ver=6.3&c=HUAWEI&mod=HUAWEIA&appver=6.3.3.8915&ftt=&isp=CMCC&kpn=KUAISHOU&lon=0&language=zh-cn&sys=ANDROID_9&max_memory=384&ud=438923277&country_code=cn&oc=HUAWEI&hotfix_ver=&did_gt=' . time() . '100&iuid=&net=WIFI&lat=0' . $randomDid;
- $result = self::postRequest($url, $parms);
- if (isset($result['users'])) {
- $result = $result['users'];
- } else {
- if (!isset($result['result']) || $result['result'] != 1) {
- self::delIpProxy(self::$currentIp);
- self::$currentIp = self::getIpProxy(); //重新分配ip
- //Log::kwaiMyLogError('userSearch/invalid', ['result' => $result, 'ip' => self::$currentIp, 'did' => $randomDid]);
- return self::searchUser($uname);
- }
- $result = [];
- }
- return $result;
- }
- /**
- * 查询用户列表
- * @param $uname
- */
- public static function searchUserList($uname, $pcursor = '', $ussid = '') {
- $url = 'http://103.107.217.65/rest/n/search/user?';
- $parms = [
- 'keyword' => $uname,
- 'os' => 'android',
- 'client_key' => '3c2cd3f3',
- ];
- if (!empty($pcursor)) {
- $parms['pcursor'] = $pcursor;
- $parms['ussid'] = $ussid;
- }
- $randomDid = self::getRandomDid();
- self::$queryString = 'app=0&kpf=ANDROID_PHONE&ver=6.3&c=HUAWEI&mod=HUAWEIA&appver=6.3.3.8915&ftt=&isp=CMCC&kpn=KUAISHOU&lon=0&language=zh-cn&sys=ANDROID_9&max_memory=384&ud=438923277&country_code=cn&oc=HUAWEI&hotfix_ver=&did_gt=' . time() . '100&iuid=&net=WIFI&lat=0' . $randomDid;
- $result = self::postRequest($url, $parms);
- if (!isset($result['result']) || $result['result'] != 1) {
- self::delIpProxy(self::$currentIp);
- self::$currentIp = self::getIpProxy(); //重新分配ip
- //Log::kwaiMyLogError('userSearch/invalid', ['result' => $result, 'ip' => self::$currentIp, 'did' => $randomDid]);
- return self::searchUserList($uname, $pcursor, $ussid);
- }
- return $result;
- }
- /**
- * 根据uid获取用户详情
- * @param $uid
- * @param $from 0:普通请求, 1:脚本抓取
- */
- public static function getUserDetail($uid, $from = 0) {
- $url = 'http://140.143.173.241/rest/n/user/profile/v2?';
- $parms = [
- 'user' => $uid,
- 'os' => 'android',
- 'client_key' => '3c2cd3f3',
- ];
- $randomDid = self::getRandomDid();
- self::$queryString = 'app=0&kpf=ANDROID_PHONE&ver=6.3&c=HUAWEI&mod=HUAWELYA-AL00&appver=6.3.0.9003&ftt=&isp=CMCC&kpn=KUAISHOU&lon=0&language=zh-cn&sys=ANDROID_9&max_memory=384&ud=0&country_code=cn&oc=HUAWEI&hotfix_ver=&did_gt=' . time() . '100&iuid=&net=WIFI&lat=0&did=' . $randomDid;
- $result = self::postRequest($url, $parms);
- if ($from != 0) {
- if (!isset($result['result']) || $result['result'] != 1) {
- self::delIpProxy(self::$currentIp);
- self::$currentIp = self::getIpProxy(); //重新分配ip
- //Log::kwaiLogError('userInfo/invalid', ['result' => $result, 'ip' => self::$currentIp, 'did' => $randomDid]);
- }
- return $result;
- }
- if (isset($result['userProfile'])) {
- $result = $result['userProfile'];
- } else {
- if (!isset($result['result']) || $result['result'] != 1) {
- self::start($randomDid);
- }
- //Log::errorLog(null, ['data' => $result, 'uid' => $uid, 'params' => $parms, 'did' => $randomDid], __METHOD__ . ':' . __LINE__, 0);
- $result = null;
- }
- return $result;
- }
- /**
- * 获取视频列表
- * @param $uid
- */
- public static function getUserVideos($uid) {
- $url = 'http://123.59.169.36/rest/n/feed/profile2?';
- $parms = [
- 'user_id' => $uid,
- 'os' => 'android',
- 'client_key' => '3c2cd3f3',
- 'count' => '20',
- 'privacy' => 'public',
- 'browseType' => '1',
- ];
- $randomDid = self::getRandomDid();
- self::$queryString = 'app=0&kpf=ANDROID_PHONE&ver=6.3&c=HUAWEI&mod=HUAWEI9&appver=6.3.3.8915&ftt=&isp=CMCC&kpn=KUAISHOU&lon=0&language=zh-cn&sys=ANDROID_9&max_memory=384&ud=&country_code=cn&oc=HUAWEI&hotfix_ver=&did_gt=' . time() . '200&iuid=&net=WIFI&lat=0&did=' . $randomDid;
- $result = self::postRequest($url, $parms);
- if (!isset($result['result']) || $result['result'] != 1) {
- self::delIpProxy(self::$currentIp);
- self::$currentIp = self::getIpProxy(); //重新分配ip
- //Log::kwaiVideoLogError('video/retry userid:' . $uid . ' totalNum: ' . count($result['feeds']));
- unset($result);
- unset($parms);
- sleep(1);
- return self::getUserVideos($uid);
- }
- //判断ip是否被限制
- if (isset($result['feeds']) && is_array($result['feeds'])) {
- if (count($result['feeds']) == 25) { //错误返回值
- self::delIpProxy(self::$currentIp);
- self::$currentIp = self::getIpProxy(); //重新分配ip
- //Log::kwaiVideoLogError('video/retry userid:' . $uid . ' totalNum: ' . count($result['feeds']));
- unset($result);
- unset($parms);
- sleep(1);
- return self::getUserVideos($uid);
- }
- }
- unset($parms);
- return $result;
- }
- public static function getVideoCommentList($videoId, $userId, $times = 0) {
- $times++;
- $url = 'http://123.59.169.36/rest/n/comment/list/v2?';
- $parms = [
- 'photoId' => $videoId,
- 'user_id' => $userId,
- 'os' => 'android',
- 'client_key' => '3c2cd3f3',
- 'count' => '15',
- 'photoPageType' => '3',
- 'order' => 'desc',
- ];
- $randomDid = self::getRandomDid();
- self::$queryString = 'app=0&kpf=ANDROID_PHONE&ver=6.3&c=HUAWEI&mod=HUAWEI9&appver=6.3.3.8915&ftt=&isp=CMCC&kpn=KUAISHOU&lon=0&language=zh-cn&sys=ANDROID_9&max_memory=384&ud=&country_code=cn&oc=HUAWEI&hotfix_ver=&did_gt=' . time() . '200&iuid=&net=WIFI&lat=0&did=' . $randomDid;
- $result = self::postRequest($url, $parms);
- /* if ((!isset($result['result']) || $result['result'] != 1) && $times<2) {
- self::delIpProxy(self::$currentIp);
- self::$currentIp = self::getIpProxy(); //重新分配ip
- //Log::kwaiCommentLogError('video/retry userid:' . $userId . ' videoId:' . $videoId . ' totalNum: ' . count($result['feeds']));
- unset($result);
- unset($parms);
- sleep(1);
- return self::getVideoCommentList($videoId, $userId, $times);
- } */
- unset($parms);
- return $result;
- }
- /**
- * 根据直播场次获取商品信息
- * 签名sig系统生成,实际不需要__NStokensig
- */
- public static function getLiveCommodityList($liveStreamId, $emptyNum = 0) {
- $os_arr = array(
- 'android', 'ios'
- );
- $i = rand(0, 1);
- $os = $os_arr[$i];
- $url = 'https://livenew.ksapisrv.com/rest/n/live/shop/commodity/byGuest?';
- $parms = [
- 'liveStreamId' => $liveStreamId,
- 'client_key' => '3c2cd3f3',
- 'os' => $os,
- ];
- self::$queryString = '';
- $result = self::postRequest($url, $parms);
- if (!isset($result['result']) || $result['result'] != 1) {
- if ($emptyNum > 2) {
- return 'false';
- }
- $emptyNum++;
- self::delIpProxy(self::$currentIp);
- self::$currentIp = self::getIpProxy(); //重新分配ip
- //Log::kwaiOnliveCommodityLogError('live/commodity liveStreamId:' . $liveStreamId . ' emptyNum:' . $emptyNum);
- unset($result);
- unset($parms);
- sleep(1);
- return self::getLiveCommodityList($liveStreamId, $emptyNum);
- }
- unset($parms);
- if (count($result['commodityList']) == 0) {
- //Log::kwaiOnliveCommodityLogError('onlivecommodityerror/empty list: livestreamid:' . $liveStreamId . ' emptyNum:' . $emptyNum);
- //如果商品列表为空,则终止程序继续运行
- return 'false';
- }
- return $result;
- }
- /**
- * 根据商品id获取商品信息
- * @param $commodityId
- */
- public static function getCommodityInfoById($commodityId, $emptyNum = 0) {
- $url = 'https://h5api.m.taobao.com/h5/mtop.taobao.detail.getdetail/6.0/?data=';
- $params = '{"itemNumId":"' . $commodityId . '","detail_v":"8.0.0"}';
- $params = urlencode($params);
- $url = $url . $params;
- $result = self::curlWithIpPorxy('get', $url);
- if ($result['ret'][0] == 'FAIL_SYS_USER_VALIDATE') {
- //请求服务器过于频繁
- sleep(3);
- if ($emptyNum > 3) {
- return;
- }
- $emptyNum++;
- //Log::kwaiOnliveCommodityLogError('onlivecommodityerror/empty work: commotidyId:' . $commodityId . ' emptyNum:' . $emptyNum);
- self::getCommodityInfoById($commodityId, $emptyNum);
- }
- if (isset($result['commodityList']) && count($result['commodityList']) == 0) {
- //如果商品列表为空,则终止程序继续运行
- //Log::kwaiOnliveCommodityLogError('onlivecommodityerror/empty commodityInfo: commodityId:' . $commodityId);
- return 'false';
- }
- unset($params);
- return $result;
- }
- /**
- * 激活did
- * @param $did
- * @return mixed
- */
- public static function start($oldDid = '') {
- $url = 'http://123.59.169.36/rest/system/stat?';
- $did = 'ANDROID_' . strtolower(substr(md5(str_random()), 0, 16));
- $parms = [
- 'mark' => $did,
- 'manufacturer' => 'HUAWEI',
- 'startup' => '1',
- 'channel' => 'HUAWEI',
- 'original_channel' => 'UNKNOWN',
- 'data' => '',
- 'third_platform_tokens' => '[]',
- 'baidu_channel_id' => '',
- 'baidu_user_id' => '',
- 'enable_push' => '1',
- 'idfa' => '',
- 'muid' => strtolower(md5('sldfksidosf' . time())),
- 'imeis' => 'dyczKPr2Q6a1v06bv' . str_random(5) . '/YkmtvUfrcN5se/' . str_random(5),
- 'country_code' => 'cn',
- 'width' => '720',
- 'height' => '1280',
- 'shumeng_id' => '',
- 'umid' => '',
- 'lastUpgradePopupTimestamp' => '',
- 'client_key' => '3c2cd3f3',
- 'os' => 'android'
- ];
- self::$queryString = 'mod=vivo&kpf=ANDROID_PHONE&kpn=KUAISHOU&net=WIFI&app=0&oc=VIVO&ud=0&hotfix_ver=&c=VIVO&sys=ANDROID_8.0&appver=6.4.0.9003&language=zh&did_gt=' . time() . '000&ver=6.4&max_memory=128&did=' . $did;
- $result = self::postRequest($url, $parms);
- if (isset($result['result']) && $result['result'] == 1) {
- RedisModel::set(self::$didkey . self::$currentIp->ip, $did);
- RedisModel::expire(self::$didkey . self::$currentIp->ip, 3600);
- //Log::kwaiLogInfo('newdid', ['ip' => self::$currentIp, 'did' => $did]);
- } else {
- RedisModel::del(self::$didkey . self::$currentIp->ip, $did);
- //Log::kwaiLogError('removedid', ['data' => $result, 'params' => $parms, 'ip' => self::$currentIp, 'did' => $did]);
- return false; //如果是新生成,且接口报错
- }
- unset($parms);
- unset($result);
- return $did;
- }
- private static function getRandomDid($times = 0) {
- //先获取ip代理
- self::$currentIp = self::getIpProxy();
- //在获取ip代理下的did
- $randomDid = RedisModel::get(self::$didkey . self::$currentIp->ip);
- if ($randomDid == false) { //重新生成randomDid
- if ($times >= 3) {
- return 'ANDROID_e75d65b52b1f1e42';
- }
- if ($times == 2) {
- sleep(10);
- }
- $randomDid = self::start();
- if (!$randomDid) {
- $times++;
- sleep(5);
- $randomDid = self::getRandomDid($times);
- }
- }
- return $randomDid;
- }
- private static function postRequest($url, $params) {
- self::$url = $url;
- self::$data = $params;
- self::dataToStr();
- self::delSig();
- self::getToken();
- $result = self::curlWithIpPorxy('post', self::$url . self::$queryString, self::$data);
- return $result;
- }
- private static function dataToStr() {
- $dataStr = '';
- foreach (self::$data as $key => $datum) {
- // if(strpos($datum,'%') !== false){
- // $datum='';
- // }
- $dataStr .= $key . '=' . $datum . '&';
- }
- $dataStr = rtrim($dataStr, '&');
- self::$dataStr = $dataStr;
- }
- private static function delSig() {
- # 获取数据后用‘&’来分割数组
- $text = self::$queryString . '&' . self::$dataStr;
- $list_data = explode('&', $text);
- sort($list_data);
- $data = implode('', $list_data);
- self::getMd5($data);
- }
- private static function getMd5($data) {
- self::$data['sig'] = md5($data . '382700b563f4');
- }
- private static function getToken() {
- $token = hash('sha256', self::$data['sig'] . 'cbf8f8efe57db87cbec65db3959fa200');
- self::$data['__NStokensig'] = $token;
- }
- private static function curlWithIpPorxy($method, $url, $data = array(), $headers = false, $times = 0, $datatype = 'form-data') {
- $times++;
- if ($headers === false) {
- $headers = [
- "Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
- "Accept-Language:zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
- "Host:www.gifshow.com",
- "Upgrade-Insecure-Requests:1",
- 'Content-Type:application/x-www-form-urlencoded;charset=utf-8'
- ];
- }
- $ch = curl_init(); //初始化curl
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HEADER, 0); //
- curl_setopt($ch, CURLOPT_TIMEOUT, 5);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //要求结果为字符串且输出到屏幕上
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //绕过ssl验证
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- if ($method == 'post') {
- curl_setopt($ch, CURLOPT_POST, 1); //post提交方式
- if ($datatype == 'form-data') {
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
- } else if ($datatype == 'json') {
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
- }
- }
- //获取ip代理
- if (empty(self::$currentIp))
- self::$currentIp = self::getIpProxy();
- curl_setopt($ch, CURLOPT_PROXY, self::$currentIp->ip);
- curl_setopt($ch, CURLOPT_PROXYPORT, self::$currentIp->port);
- $result = curl_exec($ch); //运行curl
- if ($result === false && $times < 4) { //接口超时
- //Log::kwaiLogError('ipproxy/timeout', ['data' => self::$currentIp, 'msg' => 'timeout']);
- sleep(2);
- self::delIpProxy(self::$currentIp);
- //重新执行当前接口
- return self::curlWithIpPorxy($method, $url, $data, $headers, $times);
- }
- if ($result === false) {
- return $result;
- }
- return json_decode($result, true);
- }
- private static function getIpProxy() {
- if (empty(self::$ipArray))
- self::$ipArray = IpAgencyService::getIpAgency();
- //如果ip池数量小于1, 重新拉取
- if (count(self::$ipArray) <= 1) {
- sleep(1);
- $ipArr = IpAgencyService::getIpAgency();
- self::$ipArray = array_merge(self::$ipArray, $ipArr);
- }
- $randomKey = array_rand(self::$ipArray);
- return self::$ipArray[$randomKey];
- }
- private static function delIpProxy($ipProxy) {
- foreach (self::$ipArray as $key => $item) {
- if ($item->ip == $ipProxy->ip) {
- //Log::kwaiLogError('remove ip', ['ip' => $item->ip]);
- RedisModel::del(self::$didkey . $ipProxy->ip);
- unset(self::$ipArray[$key]);
- break;
- }
- }
- self::$currentIp = null;
- }
- // 获取用户 直播信息 开播信息
- public static function getStartPlayInfo($uid = '0', $times = 0) {
- $times++;
- $url = 'http://livenew.gifshow.com/rest/n/live/startPlay/v2?';
- $randomDid = self::getRandomDid();
- self::$queryString = ''
- . 'app=0&'
- . 'kpf=ANDROID_PHONE&'
- . 'ver=6.5&'
- . 'c=VIVO_KWAI&'
- . 'appver=6.5.1.9253&'
- . 'ftt=&'
- . 'isp=CMCC&'
- . 'kpn=KUAISHOU&'
- . 'lon=116.489108&'
- . 'language=zh-cn&'
- . 'sys=ANDROID_8.1.0&'
- . 'max_memory=256&'
- . 'ud=0&'
- . 'country_code=cn&'
- . 'oc=VIVO_KWAI&'
- . 'hotfix_ver=&'
- . 'did_gt=' . time() . '&'
- . 'iuid=&'
- . 'net=WIFI&'
- . 'did=' . $randomDid . '&'
- . 'lat=39.915562'
- ;
- $parms = [
- 'author' => $uid,
- 'source' => '0',
- 'client_key' => '3c2cd3f3',
- 'os' => 'android'
- ];
- $result = self::postRequest($url, $parms);
- if (!isset($result['result']) && $times < 2) {
- self::delIpProxy(self::$currentIp);
- self::$currentIp = self::getIpProxy(); //重新分配ip
-
- unset($result);
- unset($parms);
- sleep(1);
- return self::getStartPlayInfo($uid, $times);
- }
- //判断ip是否被限制
- if (isset($result['feeds']) && is_array($result['feeds'])) {
- if (count($result['feeds']) == 25) { //错误返回值
- self::delIpProxy(self::$currentIp);
- self::$currentIp = self::getIpProxy(); //重新分配ip
- //Log::kwaiShowLogError('video/retry userid:' . $uid . ' totalNum: ' . count($result['feeds']));
- unset($result);
- unset($parms);
- sleep(1);
- return self::getStartPlayInfo($uid);
- }
- }
- unset($parms);
- return $result;
- }
- // 礼物排行榜 topUsers
- public static function topUsers($showId, $times = 0) {
- $times++;
- $randomDid = self::getRandomDid();
- $url = 'http://live.ksapisrv.com/rest/n/live/topUsers?';
- self::$queryString = ''
- . 'app=0&'
- . 'kpf=ANDROID_PHONE&'
- . 'ver=6.5&'
- . 'c=VIVO_KWAI&'
- . 'appver=6.5.1.9253&'
- . 'ftt=&'
- . 'isp=CMCC&'
- . 'kpn=KUAISHOU&'
- . 'lon=116.489108&'
- . 'language=zh-cn&'
- . 'max_memory=256&'
- . 'ud=0&'
- . 'country_code=cn&'
- . 'oc=VIVO_KWAI&'
- . 'hotfix_ver=&'
- . 'did_gt=' . time() . '&'
- . 'iuid=&'
- . 'net=WIFI&'
- . 'did=' . $randomDid
- ;
- $parms = [
- 'liveStreamId' => $showId,
- 'client_key' => '3c2cd3f3',
- 'os' => 'android'
- ];
- $result = self::postRequest($url, $parms);
- if (!isset($result['result']) && $times < 2) {
- self::$currentIp = self::getIpProxy(); //重新分配ip
- //Log::kwaiShowLogError('video/retry userid:' . $showId);
- unset($result);
- unset($parms);
- sleep(1);
- return self::topUsers($showId, $times);
- }
- //判断ip是否被限制
- if (isset($result['feeds']) && is_array($result['feeds'])) {
- if (count($result['feeds']) == 25) { //错误返回值
- self::delIpProxy(self::$currentIp);
- self::$currentIp = self::getIpProxy(); //重新分配ip
- //Log::kwaiShowLogError('video/retry userid:' . $showId . ' totalNum: ' . count($result['feeds']));
- unset($result);
- unset($parms);
- sleep(1);
- return self::topUsers($showId);
- }
- }
- unset($parms);
- return $result;
- }
- public static function getStopInfo($showId) {
- $randomDid = self::getRandomDid();
- $url = 'http://livenew.gifshow.com/rest/n/live/getEndSummary?';
- self::$queryString = ''
- . '$app=0&'
- . 'kpf=ANDROID_PHONE&'
- . 'ver=6.5&'
- . 'appver=6.5.1.9253&'
- . 'ftt=&isp=CMCC&'
- . 'kpn=KUAISHOU&'
- . 'lon=116.489108&'
- . 'language=zh-cn&'
- . 'sys=ANDROID_8.1.0&'
- . 'max_memory=256&'
- . 'ud=0&'
- . 'country_code=cn&'
- . 'oc=VIVO_KWAI&'
- . 'hotfix_ver=&'
- . 'did_gt=' . time() . '&'
- . 'iuid=&'
- . 'net=WIFI&'
- . 'did=' . $randomDid
- ;
- $parms = [
- 'liveStreamId' => $showId,
- 'client_key' => '3c2cd3f3',
- 'os' => 'android'
- ];
- $result = self::postRequest($url, $parms);
- //判断ip是否被限制
- if (isset($result['feeds']) && is_array($result['feeds'])) {
- if (count($result['feeds']) == 25) { //错误返回值
- self::delIpProxy(self::$currentIp);
- self::$currentIp = self::getIpProxy(); //重新分配ip
- //Log::kwaiShowLogError('video/retry userid:' . $showId . ' totalNum: ' . count($result['feeds']));
- unset($result);
- unset($parms);
- sleep(1);
- return self::topUsers($showId);
- }
- }
- unset($parms);
- return $result;
- }
- /**
- * 标签名称--热搜列表
- * @param type $tagName
- * @return type
- */
- public static function getTopic($tagName) {
- $randomDid = self::getRandomDid();
- $url = 'http://103.107.217.130/rest/n/tag/text/feed/hot?';
- self::$queryString = ''
- . 'app=0&'
- . 'c=VIVO_KWAI&'
- . 'ftt=&isp=CMCC&'
- . 'kpn=KUAISHOU&'
- . 'language=zh-cn&'
- . 'max_memory=256&'
- . 'country_code=cn&'
- . 'hotfix_ver=&'
- . 'did_gt=' . time()
- . '&iuid=&'
- . 'net=WIFI&'
- . 'did=' . $randomDid
- ;
- $parms = [
- 'tagName' => $tagName,
- 'tagSource' => 1,
- 'client_key' => '3c2cd3f3',
- 'os' => 'android'
- ];
- $result = self::postRequest($url, $parms);
- //判断ip是否被限制
- if (isset($result['feeds']) && is_array($result['feeds'])) {
- if (count($result['feeds']) == 25) { //错误返回值
- self::delIpProxy(self::$currentIp);
- self::$currentIp = self::getIpProxy(); //重新分配ip
- //Log::kwaiShowLogError('video/retry userid:' . $showId . ' totalNum: ' . count($result['feeds']));
- unset($result);
- unset($parms);
- sleep(1);
- return self::getTopic($showId);
- }
- }
- unset($parms);
- return $result;
- }
- /**
- * 标签名称--获取话题列表
- * @param type $tagName
- * @return type
- */
- public static function getTopicList($no) {
- $randomDid = self::getRandomDid();
- $url = 'http://api.ksapisrv.com/rest/n/search/tagRecommend?';
- self::$queryString = ''
- . 'app=0&'
- . 'kpf=ANDROID_PHONE&'
- . 'ver=6.5&'
- . 'c=VIVO_KWAI&'
- . 'ftt=&'
- . 'isp=CMCC&'
- . 'kpn=KUAISHOU&'
- . 'language=zh-cn&'
- . 'max_memory=256&'
- . 'country_code=cn&'
- . 'oc=VIVO_KWAI&'
- . 'hotfix_ver=&'
- . 'did_gt=' . time() . '&'
- . 'iuid=&net=WIFI&'
- . 'did=' . $randomDid . '&'
- ;
- $parms = [
- 'pcursor' => $no,
- 'client_key' => '3c2cd3f3',
- 'os' => 'android'
- ];
- $result = self::postRequest($url, $parms);
- // 判断ip是否被限制
- if (isset($result['feeds']) && is_array($result['feeds'])) {
- if (count($result['feeds']) == 25) { //错误返回值
- self::delIpProxy(self::$currentIp);
- self::$currentIp = self::getIpProxy(); //重新分配ip
- unset($result);
- unset($parms);
- sleep(1);
- return self::getTopicList($showId);
- }
- }
- unset($parms);
- return $result;
- }
- /**
- * 标签名称--获取话题的描述
- * @param type $tagName
- * @return type
- */
- public static function getTopicInfo($tagName) {
- $randomDid = self::getRandomDid();
- $url = 'http://api.ksapisrv.com/rest/n/tag/text/info?';
- self::$queryString = ''
- . 'app=0&'
- . 'kpf=ANDROID_PHONE&'
- . 'c=VIVO_KWAI&'
- . 'ftt=&'
- . 'isp=CMCC&'
- . 'kpn=KUAISHOU&'
- . 'language=zh-cn&'
- . 'max_memory=256&'
- . 'country_code=cn&'
- . 'oc=VIVO_KWAI&'
- . 'hotfix_ver=&'
- . 'did_gt=' . time() . '&'
- . 'iuid=&'
- . 'net=WIFI&'
- . 'did=' . $randomDid
- ;
- $parms = [
- 'tagName' => $tagName,
- 'client_key' => '3c2cd3f3',
- 'os' => 'android'
- ];
- $result = self::postRequest($url, $parms);
- //判断ip是否被限制
- if (isset($result['feeds']) && is_array($result['feeds'])) {
- if (count($result['feeds']) == 25) { //错误返回值
- self::delIpProxy(self::$currentIp);
- self::$currentIp = self::getIpProxy(); //重新分配ip
- unset($result);
- unset($parms);
- sleep(1);
- return self::getTopicInfo($showId);
- }
- }
- unset($parms);
- return $result;
- }
- /**
- *
- * @param type $uid
- * @param type $page
- * @return type
- */
- public static function getUserShop($uid, $page = 1) {
- $url = 'https://www.kwaishop.com/rest/app/grocery/product/self/midPage/list';
- $times = 0;
- $datatype = 'json';
- $data['listProductParam'] = array(
- 'id' => (string) $uid,
- 'page' => $page,
- );
- $headers = [
- "Content-Type:application/json",
- 'Referer:https://www.kwaishop.com/merchant/shop/list?id=' . $uid . '&webviewClose=false&biz=merchant&carrierType=3&from=profile&hyId=kwaishop',
- ];
- return self::curlWithIpPorxy('post', $url, $data, $headers, 0, $datatype);
- }
- /**
- *
- * @param type $uid
- * @param type $page
- * @return type
- */
- public static function getUserShopInfo($uid) {
- $url = 'https://www.kwaishop.com/rest/app/grocery/ks/shop/score?sellerId=' . $uid;
- return self::curlWithIpPorxy('get', $url, array(), array());
- }
- }
|