优惠券订单及其他脚本

KuaishouScrapyIpProxyService.php 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: hy
  5. * Date: 2019-05-16
  6. * Time: 14:59
  7. */
  8. include 'IpAgencyService.php';
  9. function str_random($i=1){
  10. $a = rand(1,4);
  11. if($a==1) return 'w0r0ewr';
  12. if($a==2) return 'sojwe';
  13. if($a==3) return 'ofwjfslds';
  14. if($a==4) return 'asdww';
  15. }
  16. class KuaishouScrapyIpProxyService {
  17. protected static $url;
  18. protected static $queryString;
  19. protected static $data;
  20. protected static $dataStr;
  21. protected static $didkey = 'kwaiIpDids:';
  22. protected static $ipArray = [];
  23. public static $currentIp = null;
  24. /**
  25. * 根据快手id或者用户名查找用户
  26. * @param $uname
  27. */
  28. public static function searchUser($uname) {
  29. $url = 'http://123.59.169.36/rest/n/search?';
  30. $parms = [
  31. 'keyword' => $uname,
  32. 'os' => 'android',
  33. 'client_key' => '3c2cd3f3',
  34. 'fromPage' => '1'
  35. ];
  36. $randomDid = self::getRandomDid();
  37. 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;
  38. $result = self::postRequest($url, $parms);
  39. if (isset($result['users'])) {
  40. $result = $result['users'];
  41. } else {
  42. if (!isset($result['result']) || $result['result'] != 1) {
  43. self::delIpProxy(self::$currentIp);
  44. self::$currentIp = self::getIpProxy(); //重新分配ip
  45. //Log::kwaiMyLogError('userSearch/invalid', ['result' => $result, 'ip' => self::$currentIp, 'did' => $randomDid]);
  46. return self::searchUser($uname);
  47. }
  48. $result = [];
  49. }
  50. return $result;
  51. }
  52. /**
  53. * 查询用户列表
  54. * @param $uname
  55. */
  56. public static function searchUserList($uname, $pcursor = '', $ussid = '') {
  57. $url = 'http://103.107.217.65/rest/n/search/user?';
  58. $parms = [
  59. 'keyword' => $uname,
  60. 'os' => 'android',
  61. 'client_key' => '3c2cd3f3',
  62. ];
  63. if (!empty($pcursor)) {
  64. $parms['pcursor'] = $pcursor;
  65. $parms['ussid'] = $ussid;
  66. }
  67. $randomDid = self::getRandomDid();
  68. 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;
  69. $result = self::postRequest($url, $parms);
  70. if (!isset($result['result']) || $result['result'] != 1) {
  71. self::delIpProxy(self::$currentIp);
  72. self::$currentIp = self::getIpProxy(); //重新分配ip
  73. //Log::kwaiMyLogError('userSearch/invalid', ['result' => $result, 'ip' => self::$currentIp, 'did' => $randomDid]);
  74. return self::searchUserList($uname, $pcursor, $ussid);
  75. }
  76. return $result;
  77. }
  78. /**
  79. * 根据uid获取用户详情
  80. * @param $uid
  81. * @param $from 0:普通请求, 1:脚本抓取
  82. */
  83. public static function getUserDetail($uid, $from = 0) {
  84. $url = 'http://140.143.173.241/rest/n/user/profile/v2?';
  85. $parms = [
  86. 'user' => $uid,
  87. 'os' => 'android',
  88. 'client_key' => '3c2cd3f3',
  89. ];
  90. $randomDid = self::getRandomDid();
  91. 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;
  92. $result = self::postRequest($url, $parms);
  93. if ($from != 0) {
  94. if (!isset($result['result']) || $result['result'] != 1) {
  95. self::delIpProxy(self::$currentIp);
  96. self::$currentIp = self::getIpProxy(); //重新分配ip
  97. //Log::kwaiLogError('userInfo/invalid', ['result' => $result, 'ip' => self::$currentIp, 'did' => $randomDid]);
  98. }
  99. return $result;
  100. }
  101. if (isset($result['userProfile'])) {
  102. $result = $result['userProfile'];
  103. } else {
  104. if (!isset($result['result']) || $result['result'] != 1) {
  105. self::start($randomDid);
  106. }
  107. //Log::errorLog(null, ['data' => $result, 'uid' => $uid, 'params' => $parms, 'did' => $randomDid], __METHOD__ . ':' . __LINE__, 0);
  108. $result = null;
  109. }
  110. return $result;
  111. }
  112. /**
  113. * 获取视频列表
  114. * @param $uid
  115. */
  116. public static function getUserVideos($uid) {
  117. $url = 'http://123.59.169.36/rest/n/feed/profile2?';
  118. $parms = [
  119. 'user_id' => $uid,
  120. 'os' => 'android',
  121. 'client_key' => '3c2cd3f3',
  122. 'count' => '20',
  123. 'privacy' => 'public',
  124. 'browseType' => '1',
  125. ];
  126. $randomDid = self::getRandomDid();
  127. 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;
  128. $result = self::postRequest($url, $parms);
  129. if (!isset($result['result']) || $result['result'] != 1) {
  130. self::delIpProxy(self::$currentIp);
  131. self::$currentIp = self::getIpProxy(); //重新分配ip
  132. //Log::kwaiVideoLogError('video/retry userid:' . $uid . ' totalNum: ' . count($result['feeds']));
  133. unset($result);
  134. unset($parms);
  135. sleep(1);
  136. return self::getUserVideos($uid);
  137. }
  138. //判断ip是否被限制
  139. if (isset($result['feeds']) && is_array($result['feeds'])) {
  140. if (count($result['feeds']) == 25) { //错误返回值
  141. self::delIpProxy(self::$currentIp);
  142. self::$currentIp = self::getIpProxy(); //重新分配ip
  143. //Log::kwaiVideoLogError('video/retry userid:' . $uid . ' totalNum: ' . count($result['feeds']));
  144. unset($result);
  145. unset($parms);
  146. sleep(1);
  147. return self::getUserVideos($uid);
  148. }
  149. }
  150. unset($parms);
  151. return $result;
  152. }
  153. public static function getVideoCommentList($videoId, $userId, $times = 0) {
  154. $times++;
  155. $url = 'http://123.59.169.36/rest/n/comment/list/v2?';
  156. $parms = [
  157. 'photoId' => $videoId,
  158. 'user_id' => $userId,
  159. 'os' => 'android',
  160. 'client_key' => '3c2cd3f3',
  161. 'count' => '15',
  162. 'photoPageType' => '3',
  163. 'order' => 'desc',
  164. ];
  165. $randomDid = self::getRandomDid();
  166. 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;
  167. $result = self::postRequest($url, $parms);
  168. /* if ((!isset($result['result']) || $result['result'] != 1) && $times<2) {
  169. self::delIpProxy(self::$currentIp);
  170. self::$currentIp = self::getIpProxy(); //重新分配ip
  171. //Log::kwaiCommentLogError('video/retry userid:' . $userId . ' videoId:' . $videoId . ' totalNum: ' . count($result['feeds']));
  172. unset($result);
  173. unset($parms);
  174. sleep(1);
  175. return self::getVideoCommentList($videoId, $userId, $times);
  176. } */
  177. unset($parms);
  178. return $result;
  179. }
  180. /**
  181. * 根据直播场次获取商品信息
  182. * 签名sig系统生成,实际不需要__NStokensig
  183. */
  184. public static function getLiveCommodityList($liveStreamId, $emptyNum = 0) {
  185. $os_arr = array(
  186. 'android', 'ios'
  187. );
  188. $i = rand(0, 1);
  189. $os = $os_arr[$i];
  190. $url = 'https://livenew.ksapisrv.com/rest/n/live/shop/commodity/byGuest?';
  191. $parms = [
  192. 'liveStreamId' => $liveStreamId,
  193. 'client_key' => '3c2cd3f3',
  194. 'os' => $os,
  195. ];
  196. self::$queryString = '';
  197. $result = self::postRequest($url, $parms);
  198. if (!isset($result['result']) || $result['result'] != 1) {
  199. if ($emptyNum > 2) {
  200. return 'false';
  201. }
  202. $emptyNum++;
  203. self::delIpProxy(self::$currentIp);
  204. self::$currentIp = self::getIpProxy(); //重新分配ip
  205. //Log::kwaiOnliveCommodityLogError('live/commodity liveStreamId:' . $liveStreamId . ' emptyNum:' . $emptyNum);
  206. unset($result);
  207. unset($parms);
  208. sleep(1);
  209. return self::getLiveCommodityList($liveStreamId, $emptyNum);
  210. }
  211. unset($parms);
  212. if (count($result['commodityList']) == 0) {
  213. //Log::kwaiOnliveCommodityLogError('onlivecommodityerror/empty list: livestreamid:' . $liveStreamId . ' emptyNum:' . $emptyNum);
  214. //如果商品列表为空,则终止程序继续运行
  215. return 'false';
  216. }
  217. return $result;
  218. }
  219. /**
  220. * 根据商品id获取商品信息
  221. * @param $commodityId
  222. */
  223. public static function getCommodityInfoById($commodityId, $emptyNum = 0) {
  224. $url = 'https://h5api.m.taobao.com/h5/mtop.taobao.detail.getdetail/6.0/?data=';
  225. $params = '{"itemNumId":"' . $commodityId . '","detail_v":"8.0.0"}';
  226. $params = urlencode($params);
  227. $url = $url . $params;
  228. $result = self::curlWithIpPorxy('get', $url);
  229. if ($result['ret'][0] == 'FAIL_SYS_USER_VALIDATE') {
  230. //请求服务器过于频繁
  231. sleep(3);
  232. if ($emptyNum > 3) {
  233. return;
  234. }
  235. $emptyNum++;
  236. //Log::kwaiOnliveCommodityLogError('onlivecommodityerror/empty work: commotidyId:' . $commodityId . ' emptyNum:' . $emptyNum);
  237. self::getCommodityInfoById($commodityId, $emptyNum);
  238. }
  239. if (isset($result['commodityList']) && count($result['commodityList']) == 0) {
  240. //如果商品列表为空,则终止程序继续运行
  241. //Log::kwaiOnliveCommodityLogError('onlivecommodityerror/empty commodityInfo: commodityId:' . $commodityId);
  242. return 'false';
  243. }
  244. unset($params);
  245. return $result;
  246. }
  247. /**
  248. * 激活did
  249. * @param $did
  250. * @return mixed
  251. */
  252. public static function start($oldDid = '') {
  253. $url = 'http://123.59.169.36/rest/system/stat?';
  254. $did = 'ANDROID_' . strtolower(substr(md5(str_random()), 0, 16));
  255. $parms = [
  256. 'mark' => $did,
  257. 'manufacturer' => 'HUAWEI',
  258. 'startup' => '1',
  259. 'channel' => 'HUAWEI',
  260. 'original_channel' => 'UNKNOWN',
  261. 'data' => '',
  262. 'third_platform_tokens' => '[]',
  263. 'baidu_channel_id' => '',
  264. 'baidu_user_id' => '',
  265. 'enable_push' => '1',
  266. 'idfa' => '',
  267. 'muid' => strtolower(md5('sldfksidosf' . time())),
  268. 'imeis' => 'dyczKPr2Q6a1v06bv' . str_random(5) . '/YkmtvUfrcN5se/' . str_random(5),
  269. 'country_code' => 'cn',
  270. 'width' => '720',
  271. 'height' => '1280',
  272. 'shumeng_id' => '',
  273. 'umid' => '',
  274. 'lastUpgradePopupTimestamp' => '',
  275. 'client_key' => '3c2cd3f3',
  276. 'os' => 'android'
  277. ];
  278. 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;
  279. $result = self::postRequest($url, $parms);
  280. if (isset($result['result']) && $result['result'] == 1) {
  281. RedisModel::set(self::$didkey . self::$currentIp->ip, $did);
  282. RedisModel::expire(self::$didkey . self::$currentIp->ip, 3600);
  283. //Log::kwaiLogInfo('newdid', ['ip' => self::$currentIp, 'did' => $did]);
  284. } else {
  285. RedisModel::del(self::$didkey . self::$currentIp->ip, $did);
  286. //Log::kwaiLogError('removedid', ['data' => $result, 'params' => $parms, 'ip' => self::$currentIp, 'did' => $did]);
  287. return false; //如果是新生成,且接口报错
  288. }
  289. unset($parms);
  290. unset($result);
  291. return $did;
  292. }
  293. private static function getRandomDid($times = 0) {
  294. //先获取ip代理
  295. self::$currentIp = self::getIpProxy();
  296. //在获取ip代理下的did
  297. $randomDid = RedisModel::get(self::$didkey . self::$currentIp->ip);
  298. if ($randomDid == false) { //重新生成randomDid
  299. if ($times >= 3) {
  300. return 'ANDROID_e75d65b52b1f1e42';
  301. }
  302. if ($times == 2) {
  303. sleep(10);
  304. }
  305. $randomDid = self::start();
  306. if (!$randomDid) {
  307. $times++;
  308. sleep(5);
  309. $randomDid = self::getRandomDid($times);
  310. }
  311. }
  312. return $randomDid;
  313. }
  314. private static function postRequest($url, $params) {
  315. self::$url = $url;
  316. self::$data = $params;
  317. self::dataToStr();
  318. self::delSig();
  319. self::getToken();
  320. $result = self::curlWithIpPorxy('post', self::$url . self::$queryString, self::$data);
  321. return $result;
  322. }
  323. private static function dataToStr() {
  324. $dataStr = '';
  325. foreach (self::$data as $key => $datum) {
  326. // if(strpos($datum,'%') !== false){
  327. // $datum='';
  328. // }
  329. $dataStr .= $key . '=' . $datum . '&';
  330. }
  331. $dataStr = rtrim($dataStr, '&');
  332. self::$dataStr = $dataStr;
  333. }
  334. private static function delSig() {
  335. # 获取数据后用‘&’来分割数组
  336. $text = self::$queryString . '&' . self::$dataStr;
  337. $list_data = explode('&', $text);
  338. sort($list_data);
  339. $data = implode('', $list_data);
  340. self::getMd5($data);
  341. }
  342. private static function getMd5($data) {
  343. self::$data['sig'] = md5($data . '382700b563f4');
  344. }
  345. private static function getToken() {
  346. $token = hash('sha256', self::$data['sig'] . 'cbf8f8efe57db87cbec65db3959fa200');
  347. self::$data['__NStokensig'] = $token;
  348. }
  349. private static function curlWithIpPorxy($method, $url, $data = array(), $headers = false, $times = 0, $datatype = 'form-data') {
  350. $times++;
  351. if ($headers === false) {
  352. $headers = [
  353. "Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
  354. "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",
  355. "Host:www.gifshow.com",
  356. "Upgrade-Insecure-Requests:1",
  357. 'Content-Type:application/x-www-form-urlencoded;charset=utf-8'
  358. ];
  359. }
  360. $ch = curl_init(); //初始化curl
  361. curl_setopt($ch, CURLOPT_URL, $url);
  362. curl_setopt($ch, CURLOPT_HEADER, 0); //
  363. curl_setopt($ch, CURLOPT_TIMEOUT, 5);
  364. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  365. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //要求结果为字符串且输出到屏幕上
  366. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //绕过ssl验证
  367. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  368. if ($method == 'post') {
  369. curl_setopt($ch, CURLOPT_POST, 1); //post提交方式
  370. if ($datatype == 'form-data') {
  371. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
  372. } else if ($datatype == 'json') {
  373. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
  374. }
  375. }
  376. //获取ip代理
  377. if (empty(self::$currentIp))
  378. self::$currentIp = self::getIpProxy();
  379. curl_setopt($ch, CURLOPT_PROXY, self::$currentIp->ip);
  380. curl_setopt($ch, CURLOPT_PROXYPORT, self::$currentIp->port);
  381. $result = curl_exec($ch); //运行curl
  382. if ($result === false && $times < 4) { //接口超时
  383. //Log::kwaiLogError('ipproxy/timeout', ['data' => self::$currentIp, 'msg' => 'timeout']);
  384. sleep(2);
  385. self::delIpProxy(self::$currentIp);
  386. //重新执行当前接口
  387. return self::curlWithIpPorxy($method, $url, $data, $headers, $times);
  388. }
  389. if ($result === false) {
  390. return $result;
  391. }
  392. return json_decode($result, true);
  393. }
  394. private static function getIpProxy() {
  395. if (empty(self::$ipArray))
  396. self::$ipArray = IpAgencyService::getIpAgency();
  397. //如果ip池数量小于1, 重新拉取
  398. if (count(self::$ipArray) <= 1) {
  399. sleep(1);
  400. $ipArr = IpAgencyService::getIpAgency();
  401. self::$ipArray = array_merge(self::$ipArray, $ipArr);
  402. }
  403. $randomKey = array_rand(self::$ipArray);
  404. return self::$ipArray[$randomKey];
  405. }
  406. private static function delIpProxy($ipProxy) {
  407. foreach (self::$ipArray as $key => $item) {
  408. if ($item->ip == $ipProxy->ip) {
  409. //Log::kwaiLogError('remove ip', ['ip' => $item->ip]);
  410. RedisModel::del(self::$didkey . $ipProxy->ip);
  411. unset(self::$ipArray[$key]);
  412. break;
  413. }
  414. }
  415. self::$currentIp = null;
  416. }
  417. // 获取用户 直播信息 开播信息
  418. public static function getStartPlayInfo($uid = '0', $times = 0) {
  419. $times++;
  420. $url = 'http://livenew.gifshow.com/rest/n/live/startPlay/v2?';
  421. $randomDid = self::getRandomDid();
  422. self::$queryString = ''
  423. . 'app=0&'
  424. . 'kpf=ANDROID_PHONE&'
  425. . 'ver=6.5&'
  426. . 'c=VIVO_KWAI&'
  427. . 'appver=6.5.1.9253&'
  428. . 'ftt=&'
  429. . 'isp=CMCC&'
  430. . 'kpn=KUAISHOU&'
  431. . 'lon=116.489108&'
  432. . 'language=zh-cn&'
  433. . 'sys=ANDROID_8.1.0&'
  434. . 'max_memory=256&'
  435. . 'ud=0&'
  436. . 'country_code=cn&'
  437. . 'oc=VIVO_KWAI&'
  438. . 'hotfix_ver=&'
  439. . 'did_gt=' . time() . '&'
  440. . 'iuid=&'
  441. . 'net=WIFI&'
  442. . 'did=' . $randomDid . '&'
  443. . 'lat=39.915562'
  444. ;
  445. $parms = [
  446. 'author' => $uid,
  447. 'source' => '0',
  448. 'client_key' => '3c2cd3f3',
  449. 'os' => 'android'
  450. ];
  451. $result = self::postRequest($url, $parms);
  452. if (!isset($result['result']) && $times < 2) {
  453. self::delIpProxy(self::$currentIp);
  454. self::$currentIp = self::getIpProxy(); //重新分配ip
  455. unset($result);
  456. unset($parms);
  457. sleep(1);
  458. return self::getStartPlayInfo($uid, $times);
  459. }
  460. //判断ip是否被限制
  461. if (isset($result['feeds']) && is_array($result['feeds'])) {
  462. if (count($result['feeds']) == 25) { //错误返回值
  463. self::delIpProxy(self::$currentIp);
  464. self::$currentIp = self::getIpProxy(); //重新分配ip
  465. //Log::kwaiShowLogError('video/retry userid:' . $uid . ' totalNum: ' . count($result['feeds']));
  466. unset($result);
  467. unset($parms);
  468. sleep(1);
  469. return self::getStartPlayInfo($uid);
  470. }
  471. }
  472. unset($parms);
  473. return $result;
  474. }
  475. // 礼物排行榜 topUsers
  476. public static function topUsers($showId, $times = 0) {
  477. $times++;
  478. $randomDid = self::getRandomDid();
  479. $url = 'http://live.ksapisrv.com/rest/n/live/topUsers?';
  480. self::$queryString = ''
  481. . 'app=0&'
  482. . 'kpf=ANDROID_PHONE&'
  483. . 'ver=6.5&'
  484. . 'c=VIVO_KWAI&'
  485. . 'appver=6.5.1.9253&'
  486. . 'ftt=&'
  487. . 'isp=CMCC&'
  488. . 'kpn=KUAISHOU&'
  489. . 'lon=116.489108&'
  490. . 'language=zh-cn&'
  491. . 'max_memory=256&'
  492. . 'ud=0&'
  493. . 'country_code=cn&'
  494. . 'oc=VIVO_KWAI&'
  495. . 'hotfix_ver=&'
  496. . 'did_gt=' . time() . '&'
  497. . 'iuid=&'
  498. . 'net=WIFI&'
  499. . 'did=' . $randomDid
  500. ;
  501. $parms = [
  502. 'liveStreamId' => $showId,
  503. 'client_key' => '3c2cd3f3',
  504. 'os' => 'android'
  505. ];
  506. $result = self::postRequest($url, $parms);
  507. if (!isset($result['result']) && $times < 2) {
  508. self::$currentIp = self::getIpProxy(); //重新分配ip
  509. //Log::kwaiShowLogError('video/retry userid:' . $showId);
  510. unset($result);
  511. unset($parms);
  512. sleep(1);
  513. return self::topUsers($showId, $times);
  514. }
  515. //判断ip是否被限制
  516. if (isset($result['feeds']) && is_array($result['feeds'])) {
  517. if (count($result['feeds']) == 25) { //错误返回值
  518. self::delIpProxy(self::$currentIp);
  519. self::$currentIp = self::getIpProxy(); //重新分配ip
  520. //Log::kwaiShowLogError('video/retry userid:' . $showId . ' totalNum: ' . count($result['feeds']));
  521. unset($result);
  522. unset($parms);
  523. sleep(1);
  524. return self::topUsers($showId);
  525. }
  526. }
  527. unset($parms);
  528. return $result;
  529. }
  530. public static function getStopInfo($showId) {
  531. $randomDid = self::getRandomDid();
  532. $url = 'http://livenew.gifshow.com/rest/n/live/getEndSummary?';
  533. self::$queryString = ''
  534. . '$app=0&'
  535. . 'kpf=ANDROID_PHONE&'
  536. . 'ver=6.5&'
  537. . 'appver=6.5.1.9253&'
  538. . 'ftt=&isp=CMCC&'
  539. . 'kpn=KUAISHOU&'
  540. . 'lon=116.489108&'
  541. . 'language=zh-cn&'
  542. . 'sys=ANDROID_8.1.0&'
  543. . 'max_memory=256&'
  544. . 'ud=0&'
  545. . 'country_code=cn&'
  546. . 'oc=VIVO_KWAI&'
  547. . 'hotfix_ver=&'
  548. . 'did_gt=' . time() . '&'
  549. . 'iuid=&'
  550. . 'net=WIFI&'
  551. . 'did=' . $randomDid
  552. ;
  553. $parms = [
  554. 'liveStreamId' => $showId,
  555. 'client_key' => '3c2cd3f3',
  556. 'os' => 'android'
  557. ];
  558. $result = self::postRequest($url, $parms);
  559. //判断ip是否被限制
  560. if (isset($result['feeds']) && is_array($result['feeds'])) {
  561. if (count($result['feeds']) == 25) { //错误返回值
  562. self::delIpProxy(self::$currentIp);
  563. self::$currentIp = self::getIpProxy(); //重新分配ip
  564. //Log::kwaiShowLogError('video/retry userid:' . $showId . ' totalNum: ' . count($result['feeds']));
  565. unset($result);
  566. unset($parms);
  567. sleep(1);
  568. return self::topUsers($showId);
  569. }
  570. }
  571. unset($parms);
  572. return $result;
  573. }
  574. /**
  575. * 标签名称--热搜列表
  576. * @param type $tagName
  577. * @return type
  578. */
  579. public static function getTopic($tagName) {
  580. $randomDid = self::getRandomDid();
  581. $url = 'http://103.107.217.130/rest/n/tag/text/feed/hot?';
  582. self::$queryString = ''
  583. . 'app=0&'
  584. . 'c=VIVO_KWAI&'
  585. . 'ftt=&isp=CMCC&'
  586. . 'kpn=KUAISHOU&'
  587. . 'language=zh-cn&'
  588. . 'max_memory=256&'
  589. . 'country_code=cn&'
  590. . 'hotfix_ver=&'
  591. . 'did_gt=' . time()
  592. . '&iuid=&'
  593. . 'net=WIFI&'
  594. . 'did=' . $randomDid
  595. ;
  596. $parms = [
  597. 'tagName' => $tagName,
  598. 'tagSource' => 1,
  599. 'client_key' => '3c2cd3f3',
  600. 'os' => 'android'
  601. ];
  602. $result = self::postRequest($url, $parms);
  603. //判断ip是否被限制
  604. if (isset($result['feeds']) && is_array($result['feeds'])) {
  605. if (count($result['feeds']) == 25) { //错误返回值
  606. self::delIpProxy(self::$currentIp);
  607. self::$currentIp = self::getIpProxy(); //重新分配ip
  608. //Log::kwaiShowLogError('video/retry userid:' . $showId . ' totalNum: ' . count($result['feeds']));
  609. unset($result);
  610. unset($parms);
  611. sleep(1);
  612. return self::getTopic($showId);
  613. }
  614. }
  615. unset($parms);
  616. return $result;
  617. }
  618. /**
  619. * 标签名称--获取话题列表
  620. * @param type $tagName
  621. * @return type
  622. */
  623. public static function getTopicList($no) {
  624. $randomDid = self::getRandomDid();
  625. $url = 'http://api.ksapisrv.com/rest/n/search/tagRecommend?';
  626. self::$queryString = ''
  627. . 'app=0&'
  628. . 'kpf=ANDROID_PHONE&'
  629. . 'ver=6.5&'
  630. . 'c=VIVO_KWAI&'
  631. . 'ftt=&'
  632. . 'isp=CMCC&'
  633. . 'kpn=KUAISHOU&'
  634. . 'language=zh-cn&'
  635. . 'max_memory=256&'
  636. . 'country_code=cn&'
  637. . 'oc=VIVO_KWAI&'
  638. . 'hotfix_ver=&'
  639. . 'did_gt=' . time() . '&'
  640. . 'iuid=&net=WIFI&'
  641. . 'did=' . $randomDid . '&'
  642. ;
  643. $parms = [
  644. 'pcursor' => $no,
  645. 'client_key' => '3c2cd3f3',
  646. 'os' => 'android'
  647. ];
  648. $result = self::postRequest($url, $parms);
  649. // 判断ip是否被限制
  650. if (isset($result['feeds']) && is_array($result['feeds'])) {
  651. if (count($result['feeds']) == 25) { //错误返回值
  652. self::delIpProxy(self::$currentIp);
  653. self::$currentIp = self::getIpProxy(); //重新分配ip
  654. unset($result);
  655. unset($parms);
  656. sleep(1);
  657. return self::getTopicList($showId);
  658. }
  659. }
  660. unset($parms);
  661. return $result;
  662. }
  663. /**
  664. * 标签名称--获取话题的描述
  665. * @param type $tagName
  666. * @return type
  667. */
  668. public static function getTopicInfo($tagName) {
  669. $randomDid = self::getRandomDid();
  670. $url = 'http://api.ksapisrv.com/rest/n/tag/text/info?';
  671. self::$queryString = ''
  672. . 'app=0&'
  673. . 'kpf=ANDROID_PHONE&'
  674. . 'c=VIVO_KWAI&'
  675. . 'ftt=&'
  676. . 'isp=CMCC&'
  677. . 'kpn=KUAISHOU&'
  678. . 'language=zh-cn&'
  679. . 'max_memory=256&'
  680. . 'country_code=cn&'
  681. . 'oc=VIVO_KWAI&'
  682. . 'hotfix_ver=&'
  683. . 'did_gt=' . time() . '&'
  684. . 'iuid=&'
  685. . 'net=WIFI&'
  686. . 'did=' . $randomDid
  687. ;
  688. $parms = [
  689. 'tagName' => $tagName,
  690. 'client_key' => '3c2cd3f3',
  691. 'os' => 'android'
  692. ];
  693. $result = self::postRequest($url, $parms);
  694. //判断ip是否被限制
  695. if (isset($result['feeds']) && is_array($result['feeds'])) {
  696. if (count($result['feeds']) == 25) { //错误返回值
  697. self::delIpProxy(self::$currentIp);
  698. self::$currentIp = self::getIpProxy(); //重新分配ip
  699. unset($result);
  700. unset($parms);
  701. sleep(1);
  702. return self::getTopicInfo($showId);
  703. }
  704. }
  705. unset($parms);
  706. return $result;
  707. }
  708. /**
  709. *
  710. * @param type $uid
  711. * @param type $page
  712. * @return type
  713. */
  714. public static function getUserShop($uid, $page = 1) {
  715. $url = 'https://www.kwaishop.com/rest/app/grocery/product/self/midPage/list';
  716. $times = 0;
  717. $datatype = 'json';
  718. $data['listProductParam'] = array(
  719. 'id' => (string) $uid,
  720. 'page' => $page,
  721. );
  722. $headers = [
  723. "Content-Type:application/json",
  724. 'Referer:https://www.kwaishop.com/merchant/shop/list?id=' . $uid . '&webviewClose=false&biz=merchant&carrierType=3&from=profile&hyId=kwaishop',
  725. ];
  726. return self::curlWithIpPorxy('post', $url, $data, $headers, 0, $datatype);
  727. }
  728. /**
  729. *
  730. * @param type $uid
  731. * @param type $page
  732. * @return type
  733. */
  734. public static function getUserShopInfo($uid) {
  735. $url = 'https://www.kwaishop.com/rest/app/grocery/ks/shop/score?sellerId=' . $uid;
  736. return self::curlWithIpPorxy('get', $url, array(), array());
  737. }
  738. }