码上爬 第14题
本题就是怎样生成m
<?php
$headers[] = 'Cookie: sessionid=acnti2em752v7l48qa9av21r69td509r; ';
$sums = 0;
for ($page=1;$page<=20;$page++){
$time = get_total_millisecond();
$sign = sign($time);
$post['page'] = $page;
$url = "https://mashangpa.com/api/problem-detail/14/data/?m={$sign}";
//echo $time;echo '<br><br>';echo $url;echo '<br><br>';echo PHP_EOL;
$code = get_curl_contents($url,$headers,json_encode($post));
//$code = get_curl_contents($url,$headers,$post);
$json = json_decode($code,true);
//echo $code;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);
}
//var_dump($headers);
//var_dump($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;
}
function B(int $b, int $f, int $p): int
{
return $b ^ ($f << ($p % 8));
}
function J(int $b, int $f, int $p): int
{
return $b ^ ($f >> ($p % 8));
}
function Y(int $b, int $f): int
{
return $b ^ $f;
}
function sign(string $T): string
{
$N ='dasdasdarqwdasdasqwdasda'.$T;
$M = 0;
$W = 0;
$len = strlen($N);
for ($L = 0; $L < $len; $L++) {
$O = ord($N[$L]);
for ($y = 0; $y < 20; $y++) {
switch ($y % 3) {
case 0:
$W = B($W, $O, $y);
break;
case 1:
$W = J($W, $O, $y);
break;
case 2:
$W = Y($W, $O);
break;
}
}
}
// 将整数转为 16 进制字符串并去掉前导 0x
$hex = dechex($W);
// 若长度为奇数,补一个前导 0,确保按字节对齐
if (strlen($hex) & 1) {
$hex = '0' . $hex;
}
// 按字节拆成二进制并做 base64 编码
return str_replace('=','A',base64_encode($hex.$T));
}
?>