示例#1
0
 public function actionLrc()
 {
     $song_id = intval($this->post("song_id", 0));
     if (!$song_id) {
         return $this->renderJSON([], "歌曲不存在", -1);
     }
     $info = Music::findOne(['song_id' => $song_id, 'status' => 1]);
     if (!$info) {
         return $this->renderJSON([], "歌曲不存在", -1);
     }
     /*获取歌词*/
     $lrc_url = QQMusicService::getSongLrcUrl($song_id);
     $lrc_data = HttpClient::get($lrc_url);
     $lrc = '';
     if (substr($lrc_data, 0, 5) == "<?xml") {
         if (stripos(strtolower($lrc_data), 'encoding="GB2312"') !== false) {
             $lrc_data = mb_convert_encoding($lrc_data, "utf-8", "gb2312");
             $lrc_data = str_replace('encoding="GB2312"', 'encoding="utf-8"', $lrc_data);
         }
         //var_dump($lrc_data);exit();
         $parser = xml_parser_create();
         xml_parse_into_struct($parser, $lrc_data, $values, $index);
         //解析到数组
         xml_parser_free($parser);
         $lrc = isset($values[0]['value']) ? $values[0]['value'] : '';
     }
     $data = ['lrc' => $lrc, 'song_url' => QQMusicService::getSongUrl($song_id)];
     return $this->renderJSON($data);
 }
示例#2
0
 public static function parseImages($data)
 {
     if (!$data || !isset($data['url']) || !isset($data['type'])) {
         return self::_err('param not enough ~~');
     }
     if ($data['type'] != 2) {
         return self::_err('just handle type => 2( website need to parse to get images) ~~');
     }
     $url = $data['url'];
     $host = parse_url($url, PHP_URL_HOST);
     if (!$host) {
         return self::_err('no host');
     }
     $content = HttpClient::get($url);
     switch ($host) {
         case "www.18weixin.com":
             $content = mb_convert_encoding($content, 'gb2312', 'utf-8');
             $html_dom = new \HtmlParser\ParserDom($content);
             $tmp_images_wrap = $html_dom->find('div.picadd', 0);
             foreach ($tmp_images_wrap->find("img") as $tmp_image_target) {
                 $tmp_target_url = $tmp_image_target->getAttr("src");
                 if (!$tmp_target_url) {
                     continue;
                 }
                 if (substr($tmp_target_url, 0, 4) != "http") {
                     $tmp_target_url = "http://" . $host . $tmp_target_url;
                 }
                 self::addQueue(['url' => $tmp_target_url, 'type' => 1]);
             }
             break;
     }
     return true;
 }
示例#3
0
    public function actionIframe()
    {
        $url = $this->get("url", "");
        $width = $this->get("width", 300);
        $data = HttpClient::get($url);
        header("Content-type: text/html; charset=utf-8");
        echo <<<EOT
<pre class='iframe_bug' style='word-wrap: break-word; white-space: pre-wrap;width:{$width}px;'>{$data}</pre>
EOT;
        exit;
    }
示例#4
0
 /** 
  * backup mysql
  */
 public function actionMysqldata()
 {
     //$bakFile = '/opt/web/ddll/init.bat';// /opt/backup/mysql/2015-09/2015-09-13.movie.gz';
     $bakFile = '/opt/backup/mysql/2015-09/2015-09-13.movie.gz';
     $url = 'http://tk007.sinaapp.com/upfile.php';
     //$bakFile = '/home/kongxiangdong/dict_user.txt';
     $cfile = curl_file_create($bakFile);
     $url = 'http://tk007.sinaapp.com/upfile.php';
     //$content = file_get_contents($bakFile);
     $data = ['dest_name' => '2015-09-13.movie.gz', 'file' => $cfile];
     //$data = ['destfile'=>'2015-09-13.movie.gz', 'myfile'=>'@'.$bakFile];
     //$data = ['destfile'=>'2015-09-13.movie.gz'];
     $rs = HttpClient::curlRequset($url, null, 'post', $data);
     var_dump($rs);
     die;
 }
示例#5
0
 public function actionKeywords($param_date = 'Today')
 {
     $date = date('Y-m-d', strtotime($param_date));
     if ($this->checkHasFileByDate(2, $date)) {
         return $this->echoLog("has file,date:{$date} ");
     }
     $cookie = $this->getAuthCookie(2);
     $url = "https://web.umeng.com/main.php?c=traf&a=keyword&ajax=module=report&siteid=1259302647&st={$date}&et={$date}&tabIndex=1&keywordCondType=&keyword=&itemName=&itemNameType=&itemVal=&engin=all&orderBy=pv&orderType=-1&currentPage=1&pageType=90&downloadType=csv";
     HttpClient::setCookie($cookie);
     $ret = HttpClient::get($url);
     if (!$ret) {
         $this->echoLog(HttpClient::getLastErrorMsg());
         return;
     }
     $params = ['type' => 2, 'action' => 1, 'date' => $date];
     $this->save2File("keywordlist_umeng_{$date}_" . date("YmdHis") . ".csv", $ret, $params);
 }
示例#6
0
 /**
  * 每天运行一次就ok了
  * php yii emoticon/scrapy/weixin18
  */
 public function actionWeixin18($page = 1)
 {
     $host = 'http://www.18weixin.com';
     $url = $host . '/weixinbiaoqing_%s.shtml';
     $url = sprintf($url, $page);
     $content = HttpClient::get($url);
     $content = mb_convert_encoding($content, 'gb2312', 'utf-8');
     $html_dom = new \HtmlParser\ParserDom($content);
     $img_wrap_array = $html_dom->find('div.imgborder_bqimg_width');
     if (!$img_wrap_array) {
         return $this->echoLog("error:no img tag ~~");
     }
     foreach ($img_wrap_array as $_item) {
         $tmp_target_url = $_item->find("a", 0);
         $tmp_target_url = $host . $tmp_target_url->getAttr("href");
         EmoticonService::addQueue(['url' => $tmp_target_url, 'type' => 2]);
     }
     return $this->echoLog("it's over ~~");
 }
示例#7
0
 public function actionKeywords($param_date = 'Today')
 {
     $date = date('Y-m-d', strtotime($param_date));
     if ($this->checkHasFileByDate(1, $date)) {
         //return $this->echoLog("has file,date:{$date} ");
     }
     $cookie = $this->getAuthCookie(1);
     $url = "http://zhanzhang.baidu.com/keywords/keywordlist?site=http%3A%2F%2Fwww.vincentguo.cn%2F&range={$date}&download=true&searchItem=";
     HttpClient::setCookie($cookie);
     $ret = HttpClient::get($url);
     if (stripos($ret, 'Too many downloads') !== false) {
         //错误了
         $this->echoLog($ret);
         return;
     }
     if (!$ret) {
         $this->echoLog(HttpClient::getLastErrorMsg());
         return;
     }
     $params = ['type' => 1, 'action' => 1, 'date' => $date];
     $this->save2File("keywordlist_bd_{$date}_" . date("YmdHis") . ".csv", $ret, $params);
 }
示例#8
0
 public static function getMusicInfoById($song_ids = [])
 {
     $ret = [];
     $url = "http://music.baidu.com/data/music/links?songIds=%s";
     $url = sprintf($url, implode(",", $song_ids));
     $res = HttpClient::get($url);
     $res = @json_decode($res, true);
     if ($res && isset($res['data']) && $res['data']) {
         $songs = $res['data']['songList'];
         if ($songs) {
             foreach ($songs as $_song) {
                 $tmp_lrc_link = str_replace("http://qukufile2.qianqian.com/data2/pic/", "", $_song['lrcLink']);
                 $tmp_lrc_link = str_replace("http://c.hiphotos.baidu.com/ting/pic/item/ ", "", $tmp_lrc_link);
                 if (stripos($tmp_lrc_link, "http") === false) {
                     $_song['lrcLink'] = "http://qukufile2.qianqian.com" . $tmp_lrc_link;
                 }
                 if (self::saveMusic($_song)) {
                     $ret[] = $_song;
                 }
             }
         }
     }
     return $ret;
 }
示例#9
0
 /**
  * douban search 破解版
  *
  */
 public static function searchpj($keyword)
 {
     $url = "http://movie.douban.com/j/subject_suggest?q=" . $keyword;
     $data = HttpClient::curlRequset($url);
     return json_decode($data, true);
 }
示例#10
0
 /**
  * 更新电影基础数据
  */
 public function actionUpdatemovie()
 {
     $mvBasic = MvBasic::find()->where('id>=6214')->orderBy('id asc');
     $total = $mvBasic->count();
     $page = 1;
     $pageSize = 40;
     $totalPage = ceil($total / $pageSize);
     $mvBasic->limit($pageSize)->asArray();
     for ($page = 1; $page <= $totalPage; $page++) {
         $offset = ($page - 1) * $pageSize;
         $data = $mvBasic->offset($offset)->all();
         foreach ($data as $v) {
             $basic_id = $v['id'];
             var_dump('doubanId: ' . $v['douban_id'] . '  basicId: ' . $basic_id . "\n");
             if (empty($v['douban_id'])) {
                 continue;
             }
             $douban_url = 'http://movie.douban.com/subject/' . $v['douban_id'] . '/';
             //$douban_url = 'http://movie.douban.com/subject/10727641/';
             //$basic_id = 1793;
             $html = HttpClient::curlRequset($douban_url);
             if (empty($html)) {
                 continue;
             }
             echo "curl done \n";
             $reg1 = "/<div id=\"info\">[\\s\\S]+?<\\/div>/";
             preg_match($reg1, $html, $info_match);
             if (!isset($info_match['0']) && empty($info_match['0'])) {
                 continue;
             }
             $html_info = $info_match['0'];
             $movie = $this->pregDoubanData($html, $html_info, $v);
             if ($movie) {
                 // 更新
                 $py_title = PinyinUtil::getFullPy($movie['title']);
                 $py_title = PinyinUtil::subPinyin($py_title);
                 $mvBasic1 = MvBasic::findOne(['douban_id' => $v['douban_id']]);
                 //$mvBasic1 = MvBasic::findOne(['douban_id'=>'10727641']);
                 // sub casts
                 $casts = implode(',', $movie['casts']);
                 if (mb_strlen($casts, 'UTF-8') > 255) {
                     $new_casts = mb_substr($casts, 0, 255, 'UTF-8');
                     $new_casts_arr = array_filter(explode(',', $new_casts));
                     $last_cast = end($new_casts_arr);
                     if (!in_array($last_cast, $new_casts_arr)) {
                         array_pop($new_casts_arr);
                     }
                     $casts = implode(',', $new_casts_arr);
                 }
                 $mvBasic1->title = $movie['title'];
                 $mvBasic1->py_title = $py_title;
                 $mvBasic1->rating = $movie['rating'];
                 $mvBasic1->directors = implode(',', $movie['directors']);
                 $mvBasic1->writers = implode(',', $movie['writers']);
                 $mvBasic1->casts = $casts;
                 //$mvBas1ic1->cate = $movie['cate'];
                 $mvBasic1->countries = implode(',', $movie['countries']);
                 $mvBasic1->languages = implode(',', $movie['languages']);
                 $mvBasic1->pubdates = implode(',', $movie['pubdates']);
                 $mvBasic1->durations = implode(',', $movie['durations']);
                 $mvBasic1->aka = implode(',', $movie['aka']);
                 $rs = $mvBasic1->save();
                 if ($rs && $basic_id) {
                     // movie type
                     $movieType = $movie['cate'];
                     $this->updateMovieType($basic_id, $movieType);
                     // country
                     $movieCountry = $movie['countries'];
                     $this->updateMovieCountry($basic_id, $movieCountry);
                 }
                 var_dump($rs);
                 echo "{$v['title']} \n\n";
             }
             //die;
             file_put_contents('./last_id.txt', $v['douban_id'] . '=' . $v['id']);
             sleep(1);
         }
     }
     echo "\n all done \n";
 }
示例#11
0
 public static function getSongInfo($song_id)
 {
     $ret = [];
     $url = "http://s.plcloud.music.qq.com/fcgi-bin/fcg_list_songinfo.fcg?idlist=%s&callback=jsonCallback&url=1";
     $url = sprintf($url, $song_id);
     $data_jsonp = trim(HttpClient::get($url));
     $data_json = mb_substr($data_jsonp, 13, -1);
     $find = ['code:', 'data:', 'url:', 'url1:'];
     $replace = ['"code":', '"data":', '"url":', '"url1":'];
     $data_json = str_replace($find, $replace, $data_json);
     $data = @json_decode($data_json, true);
     if ($data && isset($data['code']) && $data['code'] == 0) {
         $song_attr_f = explode("|", $data['data'][$song_id]);
         if (isset($song_attr_f[4])) {
             $tmp_song_id = $song_attr_f[0];
             $tmp_img_id = $song_attr_f[4];
             $tmp_mid = $song_attr_f[20];
             $ret = ['song_id' => $tmp_song_id, 'type' => 2, 'cover_image' => self::getCoverImageUrl($tmp_img_id), "lrc" => "", "song_url" => self::getSongUrl($tmp_song_id, ".mp3"), "song_title" => $song_attr_f[1], "song_author" => $song_attr_f[3], "text" => $data, "format_data" => ['image_id' => $tmp_img_id, 'mid' => $tmp_mid], "status" => 1, "view_url" => UrlService::buildGameUrl("/music/info", ['song_id' => $tmp_song_id])];
         }
     }
     return $ret;
 }
示例#12
0
 public static function getGeoByIP($ip)
 {
     $ak = self::getAK();
     $url = "https://api.map.baidu.com/highacciploc/v1?qcip={$ip}&qterm=pc&ak={$ak}&coord=bd09ll";
     var_dump(HttpClient::get($url));
 }
示例#13
0
 /**
 * http://www.mca.gov.cn/article/sj/tjbz/a/2016/20161031/201610311102.html
 * http://www.stats.gov.cn/tjsj/tjbz/xzqhdm/201608/t20160809_1386477.html
 * 抓取省市区,抓取之后的数据结构如下
 * [
 * 		'province_id' => [
 * 			'id' => '',
 * 			'name' = >'',
 * 			'city_list' => [
 * 				'city_id' => [
 * 					'id' => '',
 * 					'name' => ''
 * 				]
 * 			],
 * 			'district_list' => [
 * 				'city_id' => [
 * 						'district_id' => [
 * 						'id' => '',
 * 						'name' => ''
 * 					]
 * 				]
 * 			]
 * 		]
 * ]
 * php yii report/grab/mac
 *
 */
 public function actionMca()
 {
     $url = "http://www.stats.gov.cn/tjsj/tjbz/xzqhdm/201608/t20160809_1386477.html";
     $content = HttpClient::get($url);
     $html_dom = new \HtmlParser\ParserDom($content);
     $target = $html_dom->find('p.MsoNormal');
     if (!$target) {
         return $this->echoLog("error:no table tag ~~");
     }
     $ret = [];
     foreach ($target as $_item_target) {
         $tmp_td_array = $_item_target->find("span");
         if (!$tmp_td_array || count($tmp_td_array) < 3) {
             continue;
         }
         $tmp_id = $tmp_td_array[0]->getPlainText();
         $tmp_title = trim($tmp_td_array[2]->getPlainText());
         $tmp_title = strip_tags($tmp_title);
         $tmp_title = trim($tmp_title, "    ");
         //$this->echoLog($tmp_id.":".$tmp_title);
         if (substr($tmp_id, 2, 4) == "0000") {
             //省
             $ret[$tmp_id] = ['id' => $tmp_id, 'name' => $tmp_title, 'city_list' => [], 'district_list' => []];
             continue;
         }
         if (substr($tmp_id, 4, 2) == "00") {
             //市
             $tmp_province_id = substr($tmp_id, 0, 2) . "0000";
             if (!isset($ret[$tmp_province_id])) {
                 $this->echoLog("error");
                 exit;
             }
             $ret[$tmp_province_id]['city_list'][$tmp_id] = ['id' => $tmp_id, 'name' => $tmp_title];
             continue;
         }
         //区
         $tmp_province_id = substr($tmp_id, 0, 2) . "0000";
         $tmp_city_id = substr($tmp_id, 0, 4) . "00";
         if (!isset($ret[$tmp_province_id])) {
             $this->echoLog("error");
             exit;
         }
         //这种情况就是直辖市,自己新生成一个市
         if (!isset($ret[$tmp_province_id]['city_list'][$tmp_city_id])) {
             $ret[$tmp_province_id]['city_list'][$tmp_city_id] = ['id' => $tmp_city_id, 'name' => $ret[$tmp_province_id]['name']];
         }
         $ret[$tmp_province_id]['district_list'][$tmp_city_id][$tmp_id] = ['id' => $tmp_id, 'name' => $tmp_title];
     }
     foreach ($ret as $_item) {
         $tmp_province_id = $_item['id'];
         $tmp_province_name = $_item['name'];
         $tmp_params = ['id' => $tmp_province_id, 'province_id' => $tmp_province_id, 'province_name' => $tmp_province_name];
         $this->setMapCityItem($tmp_params);
         if (!$_item['city_list']) {
             continue;
         }
         foreach ($_item['city_list'] as $_city_id => $_city_info) {
             $tmp_params = ['id' => $_city_id, 'province_id' => $tmp_province_id, 'province_name' => $tmp_province_name, 'city_id' => $_city_id, 'city_name' => $_city_info['name']];
             $this->setMapCityItem($tmp_params);
             if (!$_item['district_list'] || !isset($_item['district_list'][$_city_id])) {
                 continue;
             }
             $tmp_district_list = $_item['district_list'][$_city_id];
             foreach ($tmp_district_list as $_district_info) {
                 $tmp_params = ['id' => $_district_info['id'], 'province_id' => $tmp_province_id, 'province_name' => $tmp_province_name, 'city_id' => $_city_id, 'city_name' => $_city_info['name'], 'district_id' => $_district_info['id'], 'district_name' => $_district_info['name']];
                 $this->setMapCityItem($tmp_params);
             }
         }
     }
 }
示例#14
0
 public function actionToken()
 {
     $this->setWeixinConfig();
     $code = $this->get("code", "");
     $state = $this->get("state", "");
     if (!$code) {
         return $this->goHome();
     }
     $appid = $this->appid;
     $appsecret = $this->appsecret;
     $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" . $appid . "&secret=" . $appsecret . "&code=" . $code . "&grant_type=authorization_code";
     $ret = HttpClient::get($url, []);
     $data = @json_decode($ret, true);
     if (empty($data) || isset($data['errcode'])) {
         return $this->goHome();
     }
     $openid = $data['openid'];
     $sns_user_data = [];
     if ($data['scope'] == "snsapi_userinfo") {
         $url = "https://api.weixin.qq.com/sns/userinfo?access_token=" . $data['access_token'] . "&openid={$openid}&lang=zh_CN";
         $ret = HttpClient::get($url, []);
         $sns_user_data = @json_decode($ret, true);
     }
     /*特殊处理*/
     $state = str_replace("@@", "&", urldecode($state));
     $state = str_replace("@|@", "?", urldecode($state));
     /*微信url特殊参数处理*/
     $state = str_replace("from=groupmessage", "", $state);
     $state = str_replace("isappinstalled=0", "", $state);
     $state = str_replace("connect_redirect=", "", $state);
     $state = rtrim($state, "?");
     $state = rtrim($state, "&");
     /*看看有没有owid:公众号wx opendid*/
     $woid = '';
     $question_mark_idx = stripos($state, "?");
     if ($question_mark_idx !== false) {
         $parse_str = mb_substr($state, $question_mark_idx + 1);
         parse_str($parse_str, $get_params);
         if (isset($get_params['woid'])) {
             $woid = $get_params['woid'];
         }
     }
     $reg_bind = UserOpenidUnionid::findOne(["openid" => $openid]);
     if (!$reg_bind) {
         $date_now = date("Y-m-d H:i:s");
         $unique_name = md5($openid);
         $user_info = User::findOne(['unique_name' => $unique_name]);
         if (!$user_info) {
             $model_user = new User();
             if ($sns_user_data) {
                 $model_user->nickname = $sns_user_data['nickname'];
                 $model_user->avatar = $sns_user_data['headimgurl'];
             } else {
                 $model_user->nickname = "微信用户" . substr($openid, -10);
             }
             $model_user->unique_name = $unique_name;
             $model_user->updated_time = $date_now;
             $model_user->created_time = $date_now;
             $model_user->save(0);
             $user_info = $model_user;
         }
         $model_bind = new UserOpenidUnionid();
         $model_bind->uid = $user_info['uid'];
         $model_bind->openid = $openid;
         $model_bind->unionid = '';
         $model_bind->other_openid = $woid;
         $model_bind->updated_time = $date_now;
         $model_bind->created_time = $date_now;
         $model_bind->save(0);
         $reg_bind = $model_bind;
     } else {
         $user_info = User::findOne(['uid' => $reg_bind['uid']]);
     }
     if ($sns_user_data && (stripos("微信用户", $user_info['nickname'] !== false) || !$user_info['avatar'])) {
         $user_info->nickname = $sns_user_data['nickname'];
         $user_info->avatar = $sns_user_data['headimgurl'];
         $user_info->update(0);
     }
     if ($woid && !$reg_bind['other_openid']) {
         //为了修复以前的数据
         $reg_bind->other_openid = $woid;
         $reg_bind->update(0);
     }
     $this->createLoginStatus($user_info);
     $url = $state ? $state : UrlService::buildWapUrl("/default/index");
     return $this->redirect($url);
 }