迪巴拉 发表于 2025-1-15 08:10:54

分享一个帝国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;      $r=$empire->fetch1("select id,title,titlepic,smalltext,titleurl from phome_ecms_sinfo where id=$xid");      $title =$r;      $x1 ='<p>'.$r.'</p>';      $x2='';      $sql1=$empire->query("select id,classid from phome_dptag_sinfo where ztid=$r limit 4");            while($x=$empire->fetch($sql1))      //循环获取查询记录            {                  $xid=$x;                  $tablenames =$class_r[$x];                  $rs=$empire->fetch1("select title fromphome_ecms_$tablenameswhere id=$xid");                  $ml.='<li>'.$rs.'</li>';            }      $ml.='<p>.....</p>';      $ly ='文章来源:https://www.00cl.com'.$r.' 精选绝版书';      $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

婷姐 发表于 2025-1-15 08:11:02

谢谢分享 虽然我不会搞

IT618发布 发表于 2025-1-15 08:11:35

感谢分享

拾光 发表于 2025-1-15 08:12:17

感谢分享。

TyCoding 发表于 2025-1-15 08:13:04

感谢分享

独家记忆 发表于 2025-1-15 08:13:10

一脸懵逼的进来,一脸懵逼的出去
页: [1]
查看完整版本: 分享一个帝国cms实现每天自动5篇搜狐外链的方法