Skip to content

Instantly share code, notes, and snippets.

@aloha1003
Last active April 27, 2020 05:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aloha1003/acd72c127874ad241da01cb68026d098 to your computer and use it in GitHub Desktop.
Save aloha1003/acd72c127874ad241da01cb68026d098 to your computer and use it in GitHub Desktop.
104打卡
<?php
//先做时间检查,如果不是8:40~10:00, 18:00~1900,就pass
//設置時區
date_default_timezone_set('Asia/Taipei');
$now = time();
$eightForth = strtotime(date("Y-m-d ")."8:40:00");
$ten = strtotime(date("Y-m-d ")."10:00:00");
$eighteen = strtotime(date("Y-m-d ")."18:00:00");
$nineteen = strtotime(date("Y-m-d ")."19:00:00");
$morningTest = (($now>=$eightForth) && ($now<=$ten));
$nightTest = ($now >= $eighteen) && ($now <=$nineteen);
if (!($morningTest||$nightTest)) {//只要不是打卡时间,就不要用
echo "现在非打卡时间";
exit;
}
//先做登入
$pid = $_GET['pid'];
$cid = $_GET['cid'];
$cookie = 'PID=' . $pid . '; CID=' . $cid . ';';
$headers = [
// 'Authority' => 'pro.104.com.tw',
'Method:GET',
'Path:/hrm2/api/auth/signinFromC',
'Scheme:https',
'Cookie:' . $cookie,
'Origin:https://pro.104.com.tw',
'Referer:https://pro.104.com.tw/psc2/signin?redirectURL=%2Fpsc2',
'x-request:JSON',
'User-agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36',
];
$curlOptions = [
CURLOPT_URL => 'https://pro.104.com.tw/hrm2/api/auth/signinFromC?cid=-&pid=-&widget=psc',
CURLOPT_HEADER => 1,
// CURLOPT_HTTPHEADER => $headers,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_VERBOSE => true,
// CURLOPT_COOKIE => $cookie,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_POST => 0,
];
$curl = curl_init();
curl_setopt_array($curl, $curlOptions);
$ret = curl_exec($curl);
curl_close($curl);
preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $ret, $matches);
foreach ($matches[1] as $item) {
parse_str($item, $cookie);
//我們只要 hrm_connect_sid 就好
if (isset($cookie['hrm_connect_sid'])) {
$sid = $cookie['hrm_connect_sid'];
}
}
$cookie = 'PID=' . $pid . '; CID=' . $cid . '; hrm.connect.sid=' . $sid . ';';
$headers = [
// 'Authority' => 'pro.104.com.tw',
'Method:POST',
'Path:/psc2/api/f0400/clockin',
'Content-type:application/json',
'Scheme:https',
'Cookie:' . $cookie,
'Origin:https://pro.104.com.tw',
'Referer:https://pro.104.com.tw/psc2',
'CLIENT-IP:公司的網路對外ip',
'X-FORWARDED-FOR:公司的網路對外ip',
'User-agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36',
];
$curlOptions = [
CURLOPT_URL => 'https://pro.104.com.tw/psc2/api/f0400/clockin',
CURLOPT_HEADER => 1,
// CURLOPT_HTTPHEADER => $headers,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_VERBOSE => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_POST => 1,
];
$curl = curl_init();
curl_setopt_array($curl, $curlOptions);
$ret = curl_exec($curl);
curl_close($curl);
echo "<PRE>";
print_r($ret);
exit;
<html>
<head>
<meta charset="UTF-8">
</head>
<script type="text/javascript" src="/vendor/laravel-admin/AdminLTE/plugins/jQuery/jQuery-2.1.4.min.js"></script>
<body>
<input type="button" value="打卡" id='clockin'>
<script type="text/javascript">
$(function() {
$('#clockin').click(function(){
var searchParams = new URLSearchParams(window.location.search)
var pid = searchParams.get('pid');
$.ajax({
url: "/dosign.php?pid="+pid
}).done(function() {
alert("打卡成功");
}).fail(function($xhr){
var string= $xhr.responseText ;
var data= JSON.parse(string);
alert("打卡失败:"+data.message);
})
})
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment