前公司吃饭是需要在钉钉报餐的,对于不挑剔的我每天都在公司吃饭,有时忘记报餐导致吃不了饭还是很麻烦的。看了下报餐系统需要的是json数据包含我的工号即可。于是编写如下代码,放在360网址监控,1小时执行1次
<?php
/*自动报餐类*/
class AutoBaocan{
private $url;
private $data;
//构造方法初始化
function __construct($url,$data){
$this->url=$url;
$this->data=$data;
}
//(1).创建会话,返回会话
public function newcurl(){
$ch=curl_init();//初始会话
curl_setopt($ch,CURLOPT_POST,1);/*Post模式*/
curl_setopt($ch,CURLOPT_URL,$this->url);/*URl设置*/
curl_setopt($ch,CURLOPT_POSTFIELDS,$this->data);/*Json数据*/
curl_setopt($ch,CURLOPT_HTTPHEADER,array(
'Content-Type: application/json; charset=gb2312',
'Content-Length: ' . strlen($this->data)
));
return $ch;
}
//(2).利用会话句柄,发送Json,返回状态和文本
public function postjson($ch){
//开启缓存区
ob_start();
//执行CURL会话
curl_exec($ch);
//获取缓冲区的内容
$return_content=ob_get_contents();
//关闭缓冲区
ob_end_clean();
//获取资源句柄的信息
$return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
return array($return_code, $return_content);
}
}
/*类结束*/
//设置参数
$url = "http://weixin.xajlnkyjy.com/lswyjishu/renshi.php/Bcdingding/baocan"; /*目标URL*/
$info = array
(
shangwu=>'吃',
xiawu=>'吃',
jobnumber=>'0209060334387389791',
ename=>'高久峰',
deptname=>'安康项目组'
);
$data = json_encode($info);/*Json数据*/
//实例化
$Baocan=new AutoBaocan($url,$data);
//执行发送json
$result=$Baocan->postjson($Baocan->newcurl());
//生成日志
file_put_contents('log.txt',$result[0]."--".$result[1]."\r\n",FILE_APPEND);
?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>demo</title> </head> <bod...
<?php /* *算法学习自百度.只是学习和记录 */ header("Content-type:text/html;charset=utf-8"); //1.设置奖项,id是奖项id,name是中奖名称,v是中奖概率 $arr =&n...
php调用Webservice基本语法如下:$url ='xxxxxxx.cn' //链接服务器端 $client = new SoapClient($url);通过以上语法已经连接到webservice,也可将wsdl在本地使用,...
array_merge是最常用的数组合并方法,+号同样也可以,但是却有很大不同。array_merge遇到相同字符串key,后面数组的key会覆盖前面数组的key,+号正好相反。$a = [ 'one' => 'A on...
重构框架的时候想要考虑支持下cli模式,于是参考了thinkphp的底层。/** * 获取应用根目录 * @return string */ public static function getRootP...
有时候我们需要爬一个接口,但是这个接口需要很多参数,包括header和cookie要去编写,使用php curl模拟实在太慢。我们可以通过浏览器的network来复制请求为curl命令。例如我需要模拟请求接口地址:https://www.xkmz.cc/Ajax/Debug/delly,我们只需要在...