chajian_pushLink2Baidu.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <?php
  2. /********** 配置教程 ****************
  3. ********************************************/
  4. set_time_limit ( 0 );
  5. include ("../config/conn.php");
  6. include ("../config/function.php");
  7. AdminSes_audit ();
  8. $uip = getuip ();
  9. $configfile = "chajian_pushLink2Baidu_config.ini";
  10. $host = $_SERVER['HTTP_HOST'];
  11. //$testtoken="yCNM9gL9dYR6WZVt"; // 百度token
  12. $token = readBaiduToken($configfile);
  13. #empty()使用变量,不支持php5.3以下版本
  14. $baiduWebsite = readBaiduWebsite($configfile);
  15. $protocalHeader = readProtocolHeader($configfile);
  16. $baiduwebsite = empty($baiduWebsite)?$host:$baiduWebsite;
  17. if(empty($_POST['protocolheader'])){
  18. $protocolheader = empty($protocalHeader)?"http":$protocalHeader;
  19. }else {
  20. $protocolheader = $_POST['protocolheader'];
  21. }
  22. $rooturl = $protocolheader."://".$_SERVER['HTTP_HOST']."/";
  23. $productSize = empty($_POST[productsize])?20:$_POST[productsize];
  24. $newsSize = empty($_POST[newssize])?20:$_POST[newssize];
  25. if(isset($_POST['newurl'])){
  26. $productSize = $_POST[productsize];//empty($_POST[t1])?20:$_POST[t1]; // 商品推送数
  27. $newsSize = $_POST[newssize];//empty($_POST[t2])?20:$_POST[t2]; // 新闻推送数
  28. // 最新商品
  29. $px="order by lastsj desc";
  30. pagef($ses,$productSize,"yjcode_pro",$px);
  31. $producturls = array();
  32. $result = "";
  33. while($row=mysql_fetch_array($res)){
  34. $au=$rooturl."product/view".$row[id].".html";
  35. array_push($producturls,$au);
  36. }
  37. foreach ($producturls as $url){
  38. $result = $result.$url."\r\n";
  39. }
  40. // 最新文章
  41. $newsurls = array();
  42. pagef($ses,$newsSize,"yjcode_news","order by lastsj desc");
  43. while($row=mysql_fetch_array($res)){
  44. if (empty ( $row ["tit"] ) || ($row ["tit"] == ""))
  45. continue;
  46. if (empty ( $row ["txt"] ) || ($row ["txt"] == ""))
  47. continue;
  48. $aurl = $rooturl."news/txtlist_i".$row[id]."v.html";
  49. array_push($newsurls,$aurl);
  50. }
  51. foreach ($newsurls as $url){
  52. $result = $result.$url."\r\n";
  53. }
  54. //echo $result;
  55. $setSize = $productSize + $newsSize;
  56. $actualCount = count($producturls) + count($newsurls);
  57. $failSize = $setSize - $actualCount;
  58. $resultCount = "设置链接数: ".$setSize." 实际链接数: ".$actualCount." 失败链接数: ".$failSize;
  59. $token = $_POST[baidutoken];
  60. saveBaiduToken($configfile,$token,$baiduwebsite,$protocolheader);
  61. }
  62. //if ($_GET [control] == "push") {
  63. if(isset($_POST['push2baidu'])){
  64. if (! strstr ( $adminqx, ",0," )) {
  65. Audit_alert ( "权限不够", "default.php" );
  66. }
  67. zwzr ();
  68. $ifadminreg = 1;
  69. $r1 = intval ( $_POST [R1] );
  70. if ($r1 == 1) {
  71. // 自动生成
  72. $t1 = $_POST [t1];
  73. $token = $_POST[baidutoken];
  74. $urlarr = explode ( "\\r\\n", $t1 );
  75. foreach ( $urlarr as $url ) {
  76. //echo $url,'<br />';
  77. }
  78. $api = "http://data.zz.baidu.com/urls?site=".$baiduwebsite."&token=".$token;
  79. $ch = curl_init ();
  80. $options = array (
  81. CURLOPT_URL => $api,
  82. CURLOPT_POST => true,
  83. CURLOPT_RETURNTRANSFER => true,
  84. CURLOPT_POSTFIELDS => implode ( "\n", $urlarr ),
  85. CURLOPT_HTTPHEADER => array (
  86. 'Content-Type: text/plain'
  87. )
  88. );
  89. curl_setopt_array ( $ch, $options );
  90. $result = curl_exec ( $ch );
  91. saveBaiduToken($configfile,$token,$baiduwebsite,$protocolheader);
  92. //echo $result;
  93. } elseif ($r1 == 2) {
  94. }
  95. }
  96. //读ini文件
  97. function readini($name)
  98. {
  99. if (file_exists($name))
  100. {
  101. $data = parse_ini_file($name,true);
  102. if ($data)
  103. {
  104. return $data;
  105. }
  106. }
  107. else
  108. {
  109. return false;
  110. }
  111. }
  112. function writeini($assoc_arr, $path, $has_sections=FALSE)
  113. {
  114. $content = "";
  115. if ($has_sections)
  116. {
  117. foreach ($assoc_arr as $key=>$elem)
  118. {
  119. $content .= "[".$key."]\n";
  120. foreach ($elem as $key2=>$elem2)
  121. {
  122. if(is_array($elem2))
  123. {
  124. for($i=0;$i<count($elem2);$i++)
  125. {
  126. $content .= $key2."[] = \"".$elem2[$i]."\"\n";
  127. }
  128. }
  129. else if($elem2=="") $content .= $key2." = \n";
  130. else $content .= $key2." = \"".$elem2."\"\n";
  131. }
  132. }
  133. }
  134. else
  135. {
  136. foreach ($assoc_arr as $key=>$elem)
  137. {
  138. if(is_array($elem))
  139. {
  140. for($i=0;$i<count($elem);$i++)
  141. {
  142. $content .= $key2."[] = \"".$elem[$i]."\"\n";
  143. }
  144. }
  145. else if($elem=="") $content .= $key2." = \n";
  146. else $content .= $key2." = \"".$elem."\"\n";
  147. }
  148. }
  149. if (!$handle = fopen($path, 'w'))
  150. {
  151. return false;
  152. }
  153. if (!fwrite($handle, $content))
  154. {
  155. return false;
  156. }
  157. fclose($handle);
  158. return true;
  159. }
  160. function saveBaiduToken($configfile,$token,$baiduwebsite,$protocolheader){
  161. $config = array(
  162. 'pushLink2Baidu' => array(
  163. 'baidutoken' => $token,
  164. 'baiduwebsite' => $baiduwebsite,
  165. 'protocolheader' => $protocolheader,
  166. ));
  167. writeini($config, $configfile, true);
  168. }
  169. function readBaiduToken($configfile){
  170. $configarr = readini($configfile);
  171. return $configarr[pushLink2Baidu][baidutoken];
  172. }
  173. function readBaiduWebsite($configfile){
  174. $configarr = readini($configfile);
  175. return $configarr[pushLink2Baidu][baiduwebsite];
  176. }
  177. function readProtocolHeader($configfile){
  178. $configarr = readini($configfile);
  179. return $configarr[pushLink2Baidu][protocolheader];
  180. }
  181. ?>
  182. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  183. <html xmlns="http://www.w3.org/1999/xhtml">
  184. <head>
  185. <meta http-equiv="x-ua-compatible" content="ie=7" />
  186. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  187. <title><?=webname?>管理系统</title>
  188. <link href="css/basic.css" rel="stylesheet" type="text/css" />
  189. <script type="text/javascript" src="js/jquery.min.js"></script>
  190. <script language="javascript" src="js/basic.js"></script>
  191. <script language="javascript" src="js/layer.js"></script>
  192. <script language="javascript">
  193. function r1onc(x){
  194. document.getElementById("r1main1").style.display="none";
  195. document.getElementById("r1main2").style.display="none";
  196. document.getElementById("r1main"+x).style.display="";
  197. }
  198. </script>
  199. </head>
  200. <body>
  201. <? include("top.php");?>
  202. <script language="javascript">
  203. document.getElementById("menu7").className="a1";
  204. </script>
  205. <div class="yjcode">
  206. <? $leftid=1;include("menu_chajian.php");?>
  207. <div class="right">
  208. <!--B-->
  209. <? systs("恭喜您,操作成功!","chajian_pushLink2Baidu.php")?>
  210. <div class="bqu1">
  211. <a href="javascript:void(0);" class="a1">百度链接主动提交</a>
  212. </div>
  213. <div class="rkuang">
  214. <script language="javascript">
  215. function tj(){
  216. layer.msg('正在提交', {icon: 16 ,time: 0,shade :0.25});
  217. f1.action="chajian_pushLink2Baidu.php?control=push";
  218. }
  219. </script>
  220. <!-- <form name="f1" method="post" onsubmit="return tj()"
  221. enctype="multipart/form-data">
  222. -->
  223. <form name="f1" method="post" enctype="multipart/form-data">
  224. <ul class="uk">
  225. <li class="l1">链接总数:</li>
  226. <li class="l21"><?php echo ($resultCount);?></li>
  227. <li class="l1">添加方式:</li>
  228. <li class="l2">
  229. <label><input name="R1" type="radio" value="1"
  230. onclick="r1onc(1)" checked="checked" /> 自动生成</label>
  231. <!-- <label><input name="R1" type="radio" value="2" onclick="r1onc(2)" /> 批量上传</label> -->
  232. <li class="l1">商品数量:</li>
  233. <li class="l2"><input type="text" class="inp" value="<?php echo $productSize;?>" size="10" name="productsize"/><span class="fd">条</span></li>
  234. <li class="l1">文章数量:</li>
  235. <li class="l2"><input type="text" class="inp" value="<?php echo $newsSize;?>" size="10" name="newssize"/><span class="fd">条</span></li>
  236. <li class="l1">协议头:</li>
  237. <li class="l2"><input type="text" class="inp" value="<?php echo $protocolheader;?>" size="10" name="protocolheader" style="width: 300px"/><span class="fd">(默认http)</span></li>
  238. <li class="l1">站点名称:</li>
  239. <li class="l2"><input type="text" class="inp" value="<?php echo $baiduwebsite;?>" size="10" name="baiduwebsite" style="width: 300px"/><span class="fd">(从百度获取,需要验证的站点,注意一级域名和二级域名是独立的站点)</span></li>
  240. <li class="l1">百度Token:</li>
  241. <li class="l2"><input type="text" class="inp" value="<?php echo $token;?>" size="10" name="baidutoken" style="width: 300px"/><span class="fd">(从百度获取)</span></li>
  242. </li>
  243. </ul>
  244. <ul class="uk uk0" id="r1main1">
  245. <li class="l1">生成链接:</li>
  246. <li class="l2"><textarea cols="400" rows="150"
  247. style="width: 400px; height: 50px;" id="idTextarea1"
  248. class="inp" value="0" size="100" name="t1" v-model="vmTextarea1"><?php echo($result); ?></textarea></li>
  249. </ul>
  250. <ul class="uk uk0" id="r1main2" style="display: none;">
  251. <li class="l1">选择文件:</li>
  252. <li class="l2"><input type="file" name="inp1" class="inp1"
  253. id="inp1" size="25"></li>
  254. <li class="l1"></li>
  255. <li class="l21">上传格式为xls文件,即excel,程序会自动识别,但必须保证符合规则,<strong
  256. class="red">第一列为账号,第二列为密码</strong></li>
  257. </ul>
  258. <ul class="uk uk0">
  259. <!-- <li class="l3"><input type="submit" value="生成链接" class="btn1" /></li> -->
  260. <li class="l3">
  261. <input type="submit" name="newurl" id="newurl" value="生成链接" class="btn1" style="float: none"/>
  262. <input type="submit" name="push2baidu" id="push2baidu" value="开始推送" class="btn1" style="float: none"/>
  263. </li>
  264. <a href="https://ziyuan.baidu.com/linksubmit/index" target="_blank">推送查询</a>
  265. </li>
  266. </ul>
  267. </form>
  268. </div>
  269. <!--E-->
  270. </div>
  271. </div>
  272. <?php include("bottom.php");?>
  273. </body>
  274. </html>