为啥要做

因为编程猫助手我做的越来越红,也要扩充新的功能,想到了在社区里自动签到源码精灵,众所周知,进行这些操作必须要系统认出你是该用户,所以我们就需要获取cookie,这次还是用curl去进行请求,设置header参数为1,就可以返回头部信息,然后这次使用正则来在头部的 Set-Cookie 抓取,废话不多说,晒代码!

代码

<?php
$u1=填账户;
$u2=填密码;
$date='{"identity":"'.$u1.'","password":"'.$u2.'","pid":"65edCTyg"}';
//echo $date;
$url= "https://api.codemao.cn/tiger/v3/web/accounts/login" ;
$ch = curl_init();
$header=['Accept: */*','Accept-Encoding: gzip, deflate, br','Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6','Connection: keep-alive','Content-Type: application/json;charset=UTF-8','Cookie: __ca_uid_key__=d4c7f485-e667-4423-bc6a-f30ebeabe0af; _ga=GA1.2.254684451.1612242217; acw_tc=2f624a4116126740172108022e65caa0525df63b6e7e14ee5bb955000e8df5'];
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,0);
curl_setopt($ch,CURLOPT_HEADER,1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$date);

echo curl_exec($ch);

if(preg_match('/Set-Cookie:([^<]+)Set-Cookie/isU', curl_exec($ch), $matches)){$imgurl = $matches[1];
$wow = curl_init();$wow = curl_init();
$header=['Cookie:'.$imgurl];
curl_setopt($wow,CURLOPT_URL,'https://trainer.codemao.cn/trainer/user/sign');
curl_setopt($wow,CURLOPT_RETURNTRANSFER,0);
curl_setopt($wow,CURLOPT_HEADER,0);
curl_setopt($wow, CURLOPT_HTTPHEADER, $header);
curl_setopt($wow, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($wow, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($wow,CURLOPT_POST,1);
curl_setopt($wow, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($wow,CURLOPT_POSTFIELDS,'{}');
echo 'code:200';echo curl_exec($wow);curl_close($wow);//断开连接
} else {
echo '失败,检查用户名称密码是否输入正确,万分感谢您!';
}?>

 

所以,新年快乐!!~


一个初一的垃圾