- 论坛徽章:
- 0
|
网上的代码来自:
http://blog.csdn.net/zhaoyangjian724/article/details/51790133
我注册了一个临时用户名测试用,登录时会返回一个图片验证码,在DOS中输入。由于没有申请交易密码,最后的交易登录不能进行,这里不关心。
我这里关心的是1楼cookie问题:
Set-Cookie会出现在DOS的222222222222222上一行,
lwp_cookies222.txt名是任意指定的,其内容与DOS中的返回内容不一致。
- use Net::SMTP;
- use LWP::UserAgent;
- use HTTP::Cookies;
- use HTTP::Headers;
- use HTTP::Response;
- use Encode;
- use Switch;
- use File::Temp qw/tempfile/;
- use HTTP::Date qw(time2iso str2time time2iso time2isoz);
- open out,">respcontent.html";
- my $CurrTime = time2iso(time());
- my $ua = LWP::UserAgent->new;
- $ua->timeout(10);
- $ua->env_proxy;
- my $now = time();
- $ua->agent('Mozilla/5.0');
- my $cookie_jar = HTTP::Cookies->new(
- file => 'lwp_cookies222.txt',
- autosave => 1,
- ignore_discard => 1
- );
- $ua->cookie_jar($cookie_jar);
- if ($cookie_jar)
- {
- $cookie_jar->load( $cookie_jar );
- my $now = time();
- my $url="https://wenjinbao.winfae.com/web/auth?method=%2Fwze%2Ftransfer%2Fcash%2Fin&amount=0.1&tradePassword=79e8fe923f031f46221a9283d0c9263a&_=$now";
- my $response = $ua->get("$url");
- if ($response->is_success)
- {
- #print $response->content;
- $r = $response->content;
- $str=encode("gbk",decode("utf8","$r"));
- print "\$str is $str\n";
-
-
- if ($str =~/用户未登录/)
- {
- my $response = $ua->get("https://wenjinbao.winfae.com/validcode/generate-validcode.do?$str");
- if ($response->is_success) {
- $r = $response->decoded_content;
- #print $response->decoded_content; # or whatever
- }else
- {
- die $response->status_line;
- };
-
- my ( $fh, $filename ) =
- tempfile( "wj_qrcode_XXXX", SUFFIX => ".jpg", DIR => 'd:\\' );
-
- binmode $fh;
- print $fh $r;
- close $fh;
- print "登录二维码已经下载到本地 [ $filename ] \n";
-
- ##打开图片
- system("start $filename ");
-
- my $validCode = <STDIN>;#图片验证码
- chomp $validCode ;
- print "\$validCode is $validCode\n";
-
- #my $url="https://wenjinbao.winfae.com/business/dispatch_post.do";
-
- my $login_url = 'https://wenjinbao.winfae.com/business/dispatch_post.do';
-
- my $res = $ua->post($login_url,{
- 'action'=>'doLogin',
- 'userName'=>'hztj2005',#'userName'=>'18072722237'
- 'followId'=>'',
- 'userPass'=>'55073332xyz',
- 'validCode'=> "$validCode"
- }
- );
- print "---------------\n";
-
- my $head =$res->header('Location');
-
- print $res->header('Location');
- print "\n";
-
-
- print $res->status_line."\n";
- print "11111111111111111111\n";
- print $res->as_string();#获取的是原始内容,包括响应头,响应正文
- print "22222222222222222222\n";
- my $content=$res->content(); #获取的是响应正文
- my $spool = encode("gbk",decode("utf8","$content"));
- print "\$spool is $spool\n";
- print "\n";
- print "3333333333333333333\n";
-
- my $response = $ua->get("$head");
- if ($response->is_success)
- {
- #print $response->content;
- $r = $response->content;
- print out $response->content;#内容是登录表格
-
- #$str=encode("gbk",decode("utf8","$r"));
- #print "\$str is $str\n";
-
- print "4444444444444444444\n";
- my $now = time();
- my $url="https://wenjinbao.winfae.com/web/auth?method=%2Fwze%2Ftransfer%2Fcash%2Fin&amount=0.1&tradePassword=79e8fe923f031f46221a9283d0c9263a&_=$now";
- #my $url="https://wenjinbao.winfae.com/web/auth?method=/wze/transfer/cash/in
- #&amount=0.1 #可能是一个很小的测试值
- #&tradePassword=79e8fe923f031f46221a9283d0c9263a #交易密码
- #&_=$now";
-
- my $response = $ua->get("$url");
- if ($response->is_success)
- {
- #print $response->content;
- $r = $response->content;
- $str=encode("gbk",decode("utf8","$r"));
- print "\$str is $str\n";
- print "555555555555555555\n";
- }else
- {
- $r = $response->content;
- print $response->content;
- print "6666666666666666666\n";
- }
-
- }
-
- };
- };
-
- }else
- {
-
- print "no cookie\n";
- };
- _END_
-
复制代码
|
|