本帖最后由 523066680 于 2017-7-8 17:14 编辑
老刘不是发了个 图灵123 API 用来对接这里的问题不知道可否
好了,不赛跑了。代码:- use JSON;
- use Encode;
- use Try::Tiny;
- use Data::Dumper;
- use IO::Handle;
- STDOUT->autoflush(1);
-
- use LWP::Simple;
- use LWP::UserAgent;
-
- our $user = "vic2";
- our $website = 'http://bbaass.tk/math/';
- our $ua = LWP::UserAgent->new( agent => 'Mozilla/5.0', timeout => 3 );
- our $res;
-
- BEGIN:
- $res = $ua->post( $website, [ username => $user, send => 'reg' ] );
- $res = $ua->post( $website, [ username => $user, send => 'user' ] );
-
- my $min = 0;
- my $max = 100;
- my $test = int(($max + $min) / 2);
- my $data;
-
- $data = check($test);
- my $tokens = $data->{'tokens'};
-
- while ( $data->{re} ne "=" )
- {
- $min = $test + 1 if ($data->{re} eq "<");
- $max = $test - 1 if ($data->{re} eq ">");
-
- $test = int(($max + $min) / 2);
- $data = check( $test );
-
- printf "min: %d max: %d, test: %d %s, token: %s\n",
- $min, $max, $test, $data->{re}, $data->{tokens};
-
- if ( ($data->{tokens} ne $tokens) and $data->{re} ne "=" )
- {
- print "Tokens different, go back\n";
- goto BEGIN;
- }
- }
-
- print "Again\n";
- goto BEGIN;
-
- sub check
- {
- my $data;
- my $res;
-
- while (1)
- {
- $res = $ua->post(
- $website,
- [ username => $user, send => 'Answer', math => $_[0] ],
- );
-
- try { $data = decode_json( $res->content() ); last; }
- catch { sleep 3.0; print "Content error, try again.\n" }
- }
-
- return $data;
- }
复制代码
|