迅睿CMS-APPPC排名采集

基于aleax插件修改

功能代码

public function apppc()
{
	$mid = dr_safe_filename(\Phpcmf\Service::L('input')->get('mid'));
	$num = dr_safe_filename(\Phpcmf\Service::L('input')->get('all'));
	
	if (!$mid) {
		$this->_html_msg(0, dr_lang('mid参数不能为空'));
	}
	
	$this->_module_init($mid);
	$page = (int)\Phpcmf\Service::L('input')->get('page');
	$psize = 1; // 每页处理的数量
	$total = (int)\Phpcmf\Service::L('input')->get('total');
	if (!$page) {
		// 计算数量
		if ($num == '999') { //999指令:所有空值备案查询
			$total = \Phpcmf\Service::M()->db->table($this->content_model->mytable)->where('(apppc IS NULL OR apppc = "" OR apppc = "100000000" OR apppc = "0") AND wangzhi <> ""')->countAllResults();
		} elseif ($num == '1') { //今日备案
			$total = \Phpcmf\Service::M()->db->table($this->content_model->mytable . '_index')->where('DATEDIFF(now() , FROM_UNIXTIME(`inputtime`)) <= ' . $num)->where('status', 9)->countAllResults();
		} else { //所有备案
			$total = \Phpcmf\Service::M()->db->table($this->content_model->mytable . '_index')->where('status', 9)->countAllResults();
		}
		
		if (!$total) {
			$this->_html_msg(0, dr_lang('无可用内容更新'));
		}
	
		$url = dr_url(APP_DIR . '/home/apppc', ['mid' => $mid]);
		$this->_html_msg(1, dr_lang('正在执行中...'), $url . '&total=' . $total . '&page=' . ($page + 1));
	}
	
	$tpage = ceil($total / $psize); // 总页数
	
	// 更新完成
	if ($page > $tpage) {
		$this->_html_msg(1, dr_lang('更新完成'));
	}
	
	$data = \Phpcmf\Service::M()->db->table($this->content_model->mytable)->where('(apppc IS NULL OR apppc = "" OR apppc = "100000000" OR apppc = "0") AND wangzhi <> ""')
->limit($psize)->orderBy('id DESC')->get()->getResultArray();

	if (empty($data)) {
		$data = \Phpcmf\Service::M()->db->table($this->content_model->mytable)->where('(apppc IS NULL OR apppc = "" OR apppc = "100000000" OR apppc = "0") AND wangzhi <> ""')
		->limit($psize)->orderBy('id DE SC')->get()->getResultArray();
		exit();
	}
	
	foreach ($data as $t) {
		// 更新alexa
		//\Phpcmf\Service::M('Updata', APP_DIR)->_get_alexa($mid,$t['id']);
		// 更新备案
		if ($t['wangzhi']) {
			$wangzhi = $t['wangzhi'];
			$wangzhi = str_ireplace('http://', '', $wangzhi);
			$wangzhi = str_ireplace('https://', '', $wangzhi);
			$wangzhi = explode('/', $wangzhi);d
			$domain = explode('.', $wangzhi[0]); //判断是否有二级域名
		
			if ($domain[2]) { //如果是二级域名
				preg_match("#(.*?)\.#i", $wangzhi[0], $match); //获取二级域名前缀
				$domain = str_ireplace($match[1] . '.', '', $wangzhi[0]);
			} else {
				$domain = $wangzhi[0];
			}
		
			$rank = '100000000';
			echo 'ID:' . $t['id'] . ' --- 域名:' . $domain . ' --- ';
		
			function http_request($url, $data) {
				$ch = curl_init();
				$timeout = 5;
				curl_setopt($ch, CURLOPT_URL, $url);
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
				curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
				curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
				curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
				curl_setopt($ch, CURLOPT_POST, 1);
				curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
				$returnData = curl_exec($ch);
				curl_close($ch);
				return $returnData;
			}
			
			if ($domain) {
				$appId = "appid";
				$appSecret = "appSecret";
				$url = "url";
				$sign = md5($appId . $appSecret);
				$data = array("sign" => $sign, "time" => time(), "domain" => $domain);
				$content = http_request($url, $data);
				$content = json_decode($content, true);
				$data = $content['data'];
				$rank = round($data['current']['day_rank']); //获取排名
				if ($rank == 0) $rank = '99999999';
			}
			
			if ($rank) { //判断该api有效
				//有数据不一定有备案,但能运行
				echo '排名:' . $rank . '<br />';
				echo("<script>setTimeout('windows.location.reload()',500)</script>");
				$upedit = array(
					'apppc' => $rank,
				);
				\Phpcmf\Service::M()->db->table(SITE_ID . '_' . $mid)->where('id', $t['id'])->update($upedit);
				echo '更新成功...准备更新下一条';
				usleep(3000); //毫秒
				echo '<br /><br />';
			} else {
				echo '<br />';
				echo '程序异常,停止运行。';
				echo '<br />';
				exit();
			}
		}
	}
	$this->_html_msg(1, dr_lang('正在执行中【%s】...', "$tpage/$page"), dr_url(APP_DIR . '/home/apppc', ['mid' => $mid, 'total' => $total, 'page' => $page + 1]));
}

模板修改

<label>
	<a href="javascript:dr_iframe_show('更新APPPC', '{dr_url(APP_DIR.'/home/apppc', ['mid'=>$t.dirname,'all'=>999])}');" class="btn btn-xs dark">
		<i class="fa fa-trash"></i>
		{dr_lang('更新APPPC')}
	</a>
</label>
posted @ 2025-05-04 09:51  Dy大叔  阅读(20)  评论(0)    收藏  举报