自动登陆铜板街

<pre name="code" class="cpp">use LWP::UserAgent;
use HTTP::Cookies;
use HTTP::Headers;
use HTTP::Response;
use Encode;
use File::Temp qw/tempfile/;
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
my $now          = time();
$ua->agent("Mozilla/8.0");
my $cookie_jar = HTTP::Cookies->new(

    file           => 'lwp_cookies.txt',
    autosave       => 1,
    ignore_discard => 1
);
$ua->cookie_jar($cookie_jar);
my $str=(rand(1));
#system ("del/f/s/q c:\wj_qrcod*.jpg");
my $response = $ua->get("https://account.tongbanjie.com/generateImageCode?t=$now");



print "\$str is $str\n";
if ($response->is_success) {
  $r = $response->decoded_content;   
# print $response->decoded_content;  # or whatever
}
else {
 die $response->status_line;
};
my ( $fh, $filename ) =
  tempfile( "tbj_qrcode_XXXX", SUFFIX => ".jpg", DIR => 'c:\\' );
binmode $fh;
print $fh $r;
close $fh;
my $name="登录二维码已经下载到本地";

my $str=encode("gbk",decode("utf8","$name"));
print "$str  [ $filename ] \n";


my $validCode = <STDIN>;
print "\$validCode is $validCode\n";
chomp $validCode;
#https://account.tongbanjie.com/tongdun/generatetokenid?callback=jQuery172021522459380203696_1460130474156&_=1460130474380
my $url="https://account.tongbanjie.com/tongdun/generatetokenid?callback=jQuery172023142253021291004_$now&_=$now";

print "------------------------\n";
print "\$url is $url\n";
print "------------------------\n";

my $response = $ua->get("$url");
if ($response->is_success) {
  $r = $response->decoded_content;   
 print $response->decoded_content;  # or whatever

 #jQuery172023142253021291004_1460127766498({"tongduntokenid":"c2e5ec6a65f94e7eac01fdb7e6c90156"})
 
 if ($r =~ /jQuery.*{"tongduntokenid":"(.*?)"}/){$tongduntokenid=$1};
}
print "\n";
print "\$tongduntokenid is $tongduntokenid\n";

my $login_url = 'https://login.tongbanjie.com/web/submitlogin';
                

#$ua->default_header('Cookie'=>$cookie,'Referer'=>$login_url);





				
 my $res = $ua->post($login_url,{
	                       'MOBILE_DEVICE'=>'PC',
                          'password'=>xxxxxx,
						 
                          'phone'=>'18072722237',
                          'pictureCode'=> $validCode,
						  # 'redirectUrl' =>"https://www.tongbanjie.com/",
						   't'=>"$now",
						   'tongduntokenid'=>"$tongduntokenid"
                                                });
			 print "---------------\n";
			 
#my $content=$res->header('Location');
#my $content =~ s/\\u([0-9a-fA-F]{4})/pack("U",,hex($1))/eg; 
print $res->header('Location');								
print $res->status_line."\n";
print $res->as_string();#获取的是原始内容,包括响应头,响应正文
    print $res->content();            #获取的是响应正文
	
	
print "..............................\n";

	my $response = $ua->get("https://trade.tongbanjie.com/trade/web/member/assets/myassets.html");
if ($response->is_success) {
  $r = $response->content;   

$str=encode("gbk",decode("utf8","$r"));
print "\$str is $str\n";

}

	my $response = $ua->get("https://www.tongbanjie.com/");
if ($response->is_success) {
  $r = $response->content;   

$str=encode("gbk",decode("utf8","$r"));
print "\$str is $str\n";

}


 

你可能感兴趣的:(自动登陆铜板街)