分享一个帝国cms实现每天自动5篇搜狐外链的方法
- //获取副表名 新增shwl字段用于记录是否发布$table =ReturnInfoDataTbname('sinfo',$checked=1,$stb=1);$sql=$empire->query("select id from $table where shwl=0 limit $num"); //查询新闻表最新10条记录while($xx=$empire->fetch($sql)) //循环获取查询记录{ $xid=$xx[id]; $r=$empire->fetch1("select id,title,titlepic,smalltext,titleurl from phome_ecms_sinfo where id=$xid"); $title =$r[title]; $x1 ='<p>'.$r[smalltext].'</p>'; $x2=''; $sql1=$empire->query("select id,classid from phome_dptag_sinfo where ztid=$r[id] limit 4"); while($x=$empire->fetch($sql1)) //循环获取查询记录 { $xid=$x[id]; $tablenames =$class_r[$x[classid]][tbname]; $rs=$empire->fetch1("select title from phome_ecms_$tablenames where id=$xid"); $ml.='<li>'.$rs[title].'</li>'; } $ml.='<p>.....</p>'; $ly ='文章来源:https://www.00cl.com'.$r[titleurl].' 精选绝版书'; $content=$x1.$x2.$ml.$ly;}// Cookie 信息$cookie="你的cook";$title =$title.'最新章节';$xxx =publishArticle($title, $content, $cookie, $channelId = 30, $accountId = 121023862);$ok2=$xxx["success"];if($ok2){ $up =$empire->query("update $table set shwl=1 where id=$xid limit 1"); var_dump($up); }function publishArticle($title, $content, $cookie, $channelId = 30, $accountId = 121023862) { $url = 'https://mp.sohu.com/mpbp/bp/news/v4/news/publish?accountId=' . $accountId;// 表单数据$data = [ 'title' => $title, 'brief' => '', 'content' => $content, 'channelId' => $channelId, 'categoryId' => -1, 'id' => 0, 'userColumnId' => 0, 'columnNewsIds' => '', 'businessCode' => 0, 'isOriginal' => false, 'cover' => '', 'attrIds' => 14218034, 'topicIds' => '', 'isAd' => 0, 'userLabels' => [], 'reprint' => false, 'customTags' => '', 'infoResource' => 0, 'sourceUrl' => '', 'visibleToLoginedUsers' => 0, 'accountId' => $accountId,]; $postFields = http_build_query($data); $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Accept: application/json', 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8', 'Cookie: ' . $cookie, 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36', ]); $response = curl_exec($ch); if (curl_errno($ch)) { echo '请求错误: ' . curl_error($ch); } else { $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($httpCode !== 200) { echo "HTTP 错误代码: " . $httpCode; } else { $result = json_decode($response, true); if (json_last_error() !== JSON_ERROR_NONE) { echo "JSON 解码错误: " . json_last_error_msg(); } else { return $result; // 返回结果 } } } curl_close($ch);}// 执行请求// $response = curl_exec($ch);// var_dump($response);// $result = json_decode($response, true);// var_dump($result);// var_dump(1111111);// var_dump($result["success"]);db_close();$empire=null;
然后用linux的
crontab