🎀 🌸

JOE定时发布每天60秒读懂世界

有问题请联系小渡qq2092115940

JOE定时发布每天60秒读懂世界

就一个代码 文件通过定时任务来执行
<?php
$apiUrl = 'http://api.suxun.site/api/sixs?type=json';
$response = file_get_contents($apiUrl);
$data = json_decode($response, true);
if ($data['code'] === '200') {
  $dbHost = '127.0.0.1';
  $dbUser = '数据库名';
  $dbPass = '数据库密码';
  $dbName = '数据库名';
  $conn = new mysqli($dbHost, $dbUser, $dbPass, $dbName);
  if ($conn->connect_error) {
    die("连接失败: ". $conn->connect_error);
  }
  $categoryName = '数据填写1';
  $sqlGetCategoryId = "SELECT mid FROM `typecho_metas` WHERE `type`='数据填写2' AND `name`='$categoryName'";
  $result = $conn->query($sqlGetCategoryId);
  if ($result && $result->num_rows > 0) {
    $row = $result->fetch_assoc();
    $categoryId = $row['mid'];
  } else {
    die("无法找到指定分类的 ID。");
  }
  $sqlGetLastCid = "SELECT MAX(CAST(SUBSTRING(cid, 1) AS UNSIGNED)) AS last_cid FROM `typecho_contents`";
  $resultLastCid = $conn->query($sqlGetLastCid);
  $lastCid = 0;
  if ($resultLastCid && $resultLastCid->num_rows > 0) {
    $rowLastCid = $resultLastCid->fetch_assoc();
    $lastCid = $rowLastCid['last_cid']? $rowLastCid['last_cid'] + 1 : 1;
  }
  $date = date('Y 年 n 月 j 日,l');
  $title = $date. ',每日 60 秒读懂世界';
  $content = '<img src="'.$data['head_image'].'"><br>';
  foreach ($data['news'] as $newsItem) {
    $content.= $newsItem.'<br>';
  }
  $content.= '<br>'.$data['weiyu'];
  $tags = '每日 60 秒';
  $cid = $lastCid;
  $slug = date('Ymd');
  $sqlInsertPost = "INSERT INTO `typecho_contents` (`cid`, `title`, `slug`, `created`, `modified`, `text`, `order`, `authorId`, `template`, `type`, `status`, `password`, `commentsNum`, `allowComment`, `allowPing`, `allowFeed`, `parent`, `views`, `agree`)
      VALUES ('$cid', '$title', '$slug', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), '$content', '0', '1', NULL, 'post', 'publish', NULL, '0', '1', '1', '1', '0', '1', '0')";
  if ($conn->query($sqlInsertPost) === TRUE) {
    $lastInsertId = $conn->insert_id;
   
    $sqlInsertRelation = "INSERT INTO `typecho_relationships` (`cid`, `mid`) VALUES ($lastInsertId, $categoryId)";
    if ($conn->query($sqlInsertRelation) === TRUE) {
      echo "文章发布成功!";
    } else {
      echo "Error inserting relationship: ". $conn->error;
    }
  } else {
    echo "Error inserting post: ". $sqlInsertPost. "<br>". $conn->error;
  }

  $conn->close();
} else {
  echo '获取 API 数据失败。';
}
?>

1

温馨提示:本文最后更新于2024-11-02 10:44:00,某些文章具有时效性,若有错误或已失效,请在下方留言或联系站长
版权声明

   站内部分内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供网络资源分享服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请 联系我们 一经核实,立即删除。并对发布账号进行永久封禁处理。在为用户提供最好的产品同时,保证优秀的服务质量。


本站仅提供信息存储空间,不拥有所有权,不承担相关法律责任。
THE END
喜欢就支持一下吧
分享
评论 抢沙发

请登录后发表评论

    暂无评论内容