码上爬 第8题

<?php
declare(strict_types=1);

//echo encrypt('oooooo1754143287158', 'oooooo');exit;



$sums = 0;
for ($page=1;$page<=20;$page++){
    $time = get_total_millisecond();
    $time_base64 = base64_encode($time);
    $sign = encrypt("oooooo{$time}{$page}", 'oooooo');
    
    
    $headers = [];
    $headers[] = 'Cookie: sessionid=acnti2em752v7l48qa9av21r69td509r; Hm_lvt_0d2227abf9548feda3b9cb6fddee26c0=1753953679,1753958584,1754045814,1754140132; HMACCOUNT=8CFCE68853DBDF9C; Hm_lpvt_0d2227abf9548feda3b9cb6fddee26c0=1754142035; s=51b351b351b351b370b0f0d070d01050d030519050';
    $headers[] = "m: {$sign}";
    $headers[] = "t: {$time_base64}";
    

    $url = "https://mashangpa.com/api/problem-detail/8/data/";
    
    $post['page'] = $page;
    

    $code = get_curl_contents($url,$headers,json_encode($post));
    $json = json_decode($code,true);
    //var_dump($json);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 padPkcs7($data, $blocksize = 16){
    $pad = $blocksize - (strlen($data) % $blocksize);
    return $data . str_repeat(chr($pad), $pad);
}

function encrypt(string $input, string $key): string{
    $inputChars = preg_split('//u', $input, -1, PREG_SPLIT_NO_EMPTY);
    $keyChars   = preg_split('//u', $key,   -1, PREG_SPLIT_NO_EMPTY);
    $result     = '';

    for ($i = 0; $i < count($inputChars); $i += 4) {
        $chunk = array_slice($inputChars, $i, 4);

        foreach ($chunk as $idx => $char) {
            $inputCode = ord($char);
            $keyCode   = ord($keyChars[$idx % count($keyChars)]);
            $combined  = ($inputCode + $keyCode) % 256;
            $result   .= chr($combined);
        }
    }

    // 兼容旧版 PHP 的写法
    return implode('', array_map(function ($c) {
        return str_pad(dechex(ord($c)), 2, '0', STR_PAD_LEFT);
    }, str_split($result, 1)));
}
none
最后修改于:2025年08月02日 22:11

添加新评论