码上爬 第11题
本题时间戳为10位
主要就是计算m
<?php
$headers[] = 'Cookie: sessionid=acnti2em752v7l48qa9av21r69td509r;';
$sums = 0;
for ($page=1;$page<=20;$page++){
$time = time();
$sign = encrypt($page, $time);
$url = "https://mashangpa.com/api/problem-detail/11/data/?page={$page}&m={$sign}&_ts={$time}";
//echo $url;echo '<br><br>';echo PHP_EOL;
$code = get_curl_contents($url,$headers);
$json = json_decode($code,true);
//echo $page;echo $code;echo '<br><br>';exit;
$sum = 0;
foreach($json['current_array'] as $v){
$sum +=$v;
}
$sums += $sum;
}
echo $sums;
function get_curl_contents($bstrURL, $headers = null, $post = null) {
$ch = curl_init($bstrURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
if ($headers) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
if ($post) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
$data = curl_exec($ch);
// 关闭CURL会话
curl_close($ch);
return $data;
}
function get_total_millisecond() {
$time = explode(" ", microtime());
$time = ($time[1] + $time[0]) * 1000;
$time = round($time) . '';
return $time;
}
function encrypt(int $a, int $b): int{
// PHP 的 intdiv 对负数向 0 取整,等价于 WAT 的 i32.div_s
return $a + intdiv($b, 3) + 16358;
}
?>