1 win+r 输入taskschd.msc

2 点击创建任务

3 创建名称

4 创建触发器

5 创建操作 选择触发程序 .bat 文件 ,底部会配上.bat文件内容


6 设置条件

7 .bat 文件内容
(1) 访问php 文件,在PHP内写curl请求 访问接口

代码:
D:\phpstudy_pro\Extensions\php\php7.3.4nts\php.exe -q D:\phpstudy_pro\WWW\duty\public\bat\token.php

代码:
<?php
$url = 'http://******/index/index/index';
$timeout = 10;
$data = array();
$header = array();
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true); // 从证书中检查SSL加密算法是否存在
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
$response = curl_exec($ch);
if($error=curl_error($ch)){
die($error);
}
curl_close($ch);
echo $response;
?>
(2) 使用windows的curl直接请求 一般win10可以

代码:@echo off
:: 使用curl发送GET请求(需Windows 10+或安装curl)
curl -s “http://xxxxxxx:8765/api/car/clear” > nul
(3) :: 若curl不可用,使用PowerShell(兼容性更好)
powershell -Command “(Invoke-WebRequest -Uri ‘http://localhost/duty/public/api/index/index’).Content”

上面是三个.bat的内容 可以挨个试一下哪个好用,.bat文件创建方法,先创建个a.txt文件,将代码放进去,然后再把.txt改成.bat就可以了

117

被折叠的 条评论
为什么被折叠?



